« first day (3861 days earlier)      last day (1080 days later) » 
00:00 - 20:0020:00 - 00:00

8:00 PM
I simply need to iterate all possible algebraic expressions, identify which ones equal my desired value, and choose the shortest one
using lexicographic order as a tie breaker for expressions of equal length
 
I mean you'd think that integers have a canonical representation, but then someone comes along and says it's sets all the way down.
 
Someone claims that point nine repeating is just as canonical as one, but he is quickly pulled off stage with a comically long hook
 
8:16 PM
1 can also be represented by 0.22222222... base 3
 
I read that as "I can also be..." which struck me by surprise because pi is famously non-constructible
 
hah
 
trying to remember if I know any famously outdated answers
 
8:32 PM
Hello, can I ask what is the best practice in inserting new data into my dataset on a regular basis to avoid messing up my dataset when problems occur? I am only working on solo projects so what I typically do is append data to a flat file (csv in my case) and just use something like read csv to import to a dataframe. I'm usually getting my data from a websites by making requests but i'm concerned the website might change something or encounter a bug and mess up the whole dataset
Looking into things like SQL but i'd want to check if it fits my needs before spending time to learn it
 
by "messing up my dataset", do you mean corrupting the data – e.g. due to an incomplete write – or or adding junk data – e.g. due to incomplete or malformed records?
 
More on the incomplete write/junk data part
Or when they change field/column names for instance
I'm not sure what to look for but kind of error proof how I update my dataset
 
8:49 PM
Hi can I ask question related to Django ? or your group only allow pure python related topic?
 
If I am building an HTML string with data that has already passed through cleaned_data['field_name] which is called when is_valid() is applied on form submission, do I need to further "clean" such data? or is {{ HTML string }} enough?
 
@boyenec Feel free to ask, but not very many people here know Django
 
I was thinking i'd just keep concatenating my dataset (e.g. old with new = current)
But definitely lots of things can go wrong or do I hard code the expected fields?
 
Where is your data coming from? Are you scraping a website or are you using an actual API?
 
@hello if you already passed cleaned_data['field_name] in your models or views then you don't neeed to be do it again
 
8:52 PM
@boyenec Okay. Thanks. I'm just paranoid. :)
 
@Aran-Fey it basically looks like this. It is going page by page through the website so I think it is scraping
It loops through each page
 
Nah, that's an API. Now the question is whether it's a documented, public API
If it is, then you don't need to worry about the server suddenly returning data in a different format or anything
Websites can change without warning, APIs can't (well, shouldn't)
 
It comes from the URL of the ones people browse
The link there not directly from an official API
so if I type ajax=false it will show the actual webpage people should see
 
I've got many things. What is the best way to check if they are all equal? len(set(many_things)) == 1?
 
Okay. Even if it's not intended for public use, I think it's fairly unlikely that it'll suddenly start returning data that you could mistakenly append to your csv file. Plus, since it's json, it's easy to validate whether the data looks like you expect it to. Check if it contains all the keys you expect, and if it doesn't, throw an error instead of writing it to your csv file
 
9:02 PM
@Pherdindy You might want to take a look at data validation – for example JSON schemas or Pydantic.
 
is there any better way in django to restrict user to edit others people post? right now I am using this "{% if user.id == post.author.id %}" in my html template so user can't edit others people post except his own post. is there any way to redirect user 404 page when he trying to go edit page of others people post.
 
@boyenec You probably need a decorator for that.
 
But it's very, very hard to make these things 100% correct. Even if it's just that you don't know what is the exact criteria for correctness yet.
 
@piRSquared If you're certain that all the values are hashable, sure. If not, probably something like all(thing == many_things[0] for thing in many_things)
 
@Aran-Fey cool yeah was thinking of this but just wanted to know if there a way people usually check since I tend to overlook things until things in actual application
@MisterMiyagi Yeah I guess I just have to be really careful on checking time to time
 
9:04 PM
@hello can you tell little bit more about decorator?? it's new word for me
 
@Aran-Fey that is very reasonable (-:
 
@MisterMiyagi i'll take a look just wanted to see if there was better ways to check
 
@piRSquared You can use itertools.groupby, if you are feeling radical.
 
And back up my dataset regularly
 
62
A: How to write a custom decorator in django?

PhoebeBPlayed around with the various links above and couldn't get them working and then came across this really simple one which I adapted. http://code.activestate.com/recipes/498217-custom-django-login_required-decorator/ from functools import wraps from django.http import HttpResponseRedirect def a...

 
9:06 PM
@Pherdindy I'd dump a copy of the new data to disk every time. If you have the room for it.
 
@hello thnanks
 
@MisterMiyagi I'm feeling less radical and more tubular.
 
@hello do you know how do it with classbased view?
 
@boyenec Do you have a specific question?
 
9:24 PM
@piRSquared yeah I definitely should start doing that so I can reconstruct the dataset didn't think of that since I felt storage intensive but it shouldn't be a big problem for the benefits
 
@Pherdindy Surely the best practice is setting a compound key with a unique constraint and doing an upsert? Lots of phrases there to Google
 
Ok, I'm doing something... maybe goofy. I want a non-space intensive way to get the overlap of range objects. Like range(2, 20, 2) and range(3, 20, 3) This Q&A addresses a naive approach assuming the steps are 1 but I explicitly want steps greater than 1. I wrote this pastebin but wanted some feedback.
wait, its broken.... please hold
... and we're back... fixed
It enables me to do this:
 
*composite key. Not "compound". Sorry
 
[*multirange(
    range(2, 100, 2),
    range(3, 100, 3),
    range(5, 100, 5)
)]
# [30, 60, 90]
 
Why not just...
def multirange(*ranges):
    first_range, *ranges = ranges

    for i in first_range:
        if all(i in range_ for range_ in ranges):
            yield i
 
9:33 PM
@roganjosh Yeah looks like something i'll look into. Not familiar with databases just read a few introductory concepts so I tend to create filters in code
 
@Aran-Fey because that requires I evaluate all of the ranges
 
What does "evaluate" mean here?
 
I'm trying to save space. Doing that would be bad if I tried something like this:
[*multirange(
    range(2, 1_000_000, 2),
    range(3, 1_000_000, 3),
    range(5, 1_000_000, 5),
    range(7, 1_000_000, 7),
    range(11, 1_000_000, 11),
    range(13, 1_000_000, 13),
)]
 
@Pherdindy an awful lot of stuff can be passed-off to the db and do out-of-memory stuff (I don't know what you're doing). It's a good idea to push any obvious filters into the query
 
"evaluate" means resolve ranges into all of its possible elements.
as opposed to keeping it an abstract thing in which the next item can be calculated.
 
9:38 PM
@roganjosh Basically, I just usually need conditions like the ID and date fields shouldn't be the same else it can be tagged as a duplicate. I usually use filters using dataframes not sure if i'll cause performance issues in the long run. Since I felt querying in databases and filtering dataframes seemed to be a little similar I guess
Since i'll probably keep adding thousands of rows to the bigger dataset I may hit performance issues and long calculation times surely. So SQL is better for that right?
 
You can remove duplicates in the query in the same way you do in pandas. I'm not aware of any differences in the approach tbh
Thousands of rows, or thousands of thousands of rows?
 
@piRSquared I don't follow. We don't use python 2 anymore (at least I hope you don't), so looping over a range or checking if an integer is in a range is all done on-the-fly with some basic math. It would only be a problem if you did something like calling list on a range
 
It should reach millions of rows pretty easily
 
In which case, handle it in SQL
 
since i'm tracking stuff and I just keep adding it more so the additions will just get bigger
 
9:41 PM
Well, that doesn't sound good. You must have some boundaries to filter on?
 
I just track things i'm interested in but i'll watch over those over a period of time and make screening tools to see trends. Then i'll add new things to watch over so amount of rows is just linearly getting bigger
 
@Aran-Fey You are highlighting my deficient description, which I appreciate. Let me try again. the range object is O(1) for memory (not sure if I'm saying that correctly). If I wanted the overlap between several such objects, I could turn them into sets then take the intersection. If one range object represented a large number of numbers then I've lost the memory efficiency the range object had in the first place.
I happen to disagree that you can resolve these matters with simple math.
At least, it wasn't obvious to me.
 
@Pherdindy Apologies if I sound facetious but that's what databases do, and why you have WHERE. I don't think I understand the problem
 
I'm saying the range object is using simple math on the inside. I'm not saying intersecting multiple ranges is easily solved with math
 
@piRSquared took me a while that your "space-intensive" is not about the code but about memory :P For what it's worth this is not an easy task, see github.com/numpy/numpy/blob/…
actually, Aran's solution uses O(1) memory, so you're good
 
9:47 PM
@roganjosh yeah just wanted to see if I should learn using databases but it looks important in my case. Going to look into SQLite
I just use csv files as storage lol
 
And your task is harder than np.shares_memory because you want to find all the solutions to the Diophantine equation, and you have more equations in the general case.
 
@Pherdindy All is explained :P
 
I'd just loop as a first guess, choosing the shortest range as a reference
 
@AndrasDeak @Aran-Fey you mean that range's __in__ checks with math??!! OMG, yeah, that works.
 
Yeah
 
9:49 PM
@piRSquared that's exactly what he's been saying, yes
 
/sigh well I'm glad I asked. Sorry AF, I didn't realize that at first.
 
@piRSquared but for the record if __contains__ wasn't pure math it would still be O(1) memory, but it would loop.
 
here's a bit of a smarter implementation of the same idea
 
that is smart
 
Why am I seeing such a weird result lol
 
9:55 PM
because your request was intercepted
 
I'm in australia, so idk. And it's google
 
Have you tried looking at it upside down?
 
lol
Apparently it's a valid page on google cache, but I can't load it: webcache.googleusercontent.com/…
 
@Aran-Fey did you just reimplement len() for a range?
 
n-no...
 
9:58 PM
OK, just checking ;)
 
*frantically checks if ranges actually support len*
 
they even support .index and .count
 
Wow, count? That's some hardcore dedication to the Sequence API
 
yeah, I was surprised to learn that last week or so
hopefully it's a wrapper as thin as bible paper
 
Or was it Container? I can never keep these 2 billion abcs straight
 
10:01 PM
you can index it so probably Sequence
bags are containers and you can't order things in a bag
 
Oh right, Container literally only implements in. So definitely not that one.
 
Is it required that I create a perform_update() method in my ViewSet in Django in order to support it, or is declaring the URL in urls.py sufficient and Django magically does the rest?
I've been trying to read documentation/articles about this but it's not clear.
 
Btw, sqlite3 still updated? I noticed last update to the package was about 5 years ago
 
Sqlite3 is fine. I mean, it has a lot of weirdness, but it's stable in its weirdness
 
10:16 PM
Yeah, it's a finished product. Nothing there to update
 
Cool thanks
Gonna check it out
 
I did watch a presentation about how it's in aircraft. In my hypothetical scenario of a plane going down, I'd probably curse its lackadaisical approach to type-checking as my last words
 
@Kevin did you post it or did I miss seeing it
 
@roganjosh "please mind the gap between the plane and the platform"
 
Josh "It's-a-float-dammit" Pilkington. I guess I could make it work :/
 
10:28 PM
we're all floats down here
(What? Need to make sense? Since when?)
 
The movies would be far more dramatic if you can hack consoles on a plane tbh
"Is there a pilot on board?!" --> "No, but I know how to program. I'll land this thing!"
--> "I just need to check the docs"
 
Brilliant :P
 
11:08 PM
@duhaime @duhaime This is for an app I'm building (not a website). The app should be able to modify an Illustrator File text and export it as PNG. I'm converting the file to SVG to be able to get access to the text level & modify the text. Then now I'm needing to export as png while preserving the text to complete the application. I've achieved to get this process but for some reason I'm not able to include the custom font when running the script in a docker image (but it is working locally).
 
00:00 - 20:0020:00 - 00:00

« first day (3861 days earlier)      last day (1080 days later) »