« first day (4337 days earlier)      last day (836 days later) » 

06:35
@Kevin I was thinking about it earlier, but is it common to check the fps from tkinter? I did that with pygame, but didn't know this was important/needed for tkinter.
06:56
@NordineLotfi When I first tried it, it wasn't a pleasure experience and then I found tkinter with basically 5% python knowledge and tkinter grew my python knowledge. And then I gave PyQt a try and it was pretty easy because I knew how event driven programming works and the basic components and what they expect to be served and bla bla. But one thing I'll give you, the codebase of PyQt is pretty messed up, alot of same classes repeating in multiple modules and what not
07:25
I really relate to the 5% knowledge and "tkinter grew on me", since it's kind of what I did too. I guess I might try Qt again later on
07:58
I just find out stackoverflow has chatroom :)
Hi guys :)
Hi, Welcome
Welcome, then!
thank you!
08:51
@dhiaagr What I said is actually flawed, @Code-Apprentice. Data comes from above (as props from parent components) while state changes within the receiving component * -> this is what I like about hooks as well as all I know about hooks, lol
 
1 hour later…
09:55
@NordineLotfi its gonna be awesome, trust me
Anonymous
10:09
Hello.

I got a dictionary that has the signature [str, Type], which I want to use in argparse. How can I get it to work?
Anonymous
parser.add_argument("--argument", type=my_dictionary.get, choices=my_dictionary.values())
Anonymous
The key and values are different types, which of course results in "invalid choice" from argparse.
Anonymous
I can get it working with some functions that sort this out, but I do want to know if there's a clean way doing this?
To be clear: you have a dictionary where the keys are strings, and the values are typing.Type instances? And you want the user to input one of the keys on the command line, and then argparse should check that the command line contains one of those keys, look up the corresponding Type, and give that back to you in the resulting parsed arguments?
As far as I can tell, that's a simple typo, then: the choices you want are clearly the my_dictionary.keys(), not the mydictionary.values().
Anonymous
Yeah, you could do that, but that requires the user to explicit write any of these:

--argument {<class 'ClassA'>, <class 'ClassB'>, <class 'ClassC'>}

...instead of the keys of the dictionary that are easier for the user to write.
Anonymous
10:16
The dictionary is only used to make it easier for the user to choose between the classes.
Anonymous
Oh, I see what you mean.
Anonymous
It was a typo, choices=my_dictionary.keys() is what I actually use.
Anonymous
But as the "keys" and "values" do not match (str != Type), I'm getting the "invalid choice" error (which is understandable, as the types do not match, haha).
oh.
I tested it, and apparently the choices are checked after applying the type conversion, not before.
Anonymous
So yeah, what I basically want is using a dictionary where "type" is the value of the dictionary and "choices" are the keys. :P
10:19
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> types = {'str': str}
>>> parser.add_argument('example', type=types.get, choices=types.values())
_StoreAction(option_strings=[], dest='example', nargs=None, const=None, default=None, type=<built-in method get of dict object at 0x7f2b6ad14600>, choices=dict_values([<class 'str'>]), help=None, metavar=None)
>>> parser.parse_args(['str'])
Namespace(example=<class 'str'>)
so actually it seems like you already had it right.
although the usage and error messages will also look up and then stringify the value, which is not idea.
I have numerous issues with the overall design of argparse, frankly, and one of my back-burner projects is my own attempt at command-line parsing.
(and yes, I have also checked out the competition. but I am a professional wheel-reinventer ;) )
I suppose you could always just use plain old string choices, and explicitly do the dict lookup in a later step after receiving the parsed arguments.
Hmm I have an actual weird python issue. I have a django server which renders a template with some data. Now I go to the page and the first time everything is alright, but when I reload the page the data is missing, now I print it right before rendering the view and the server shows me it's there, but firefoxs debug console shows me that the request response is empty. How can this be and what would be different between the first time calling a django url and the second time? I also tried ctrl+f5
but it's the same result so it's not a cache issue
Anonymous
Yeah, that would work, which I've already tried. Just wanted to see if there's any other more "clean" way doing it, because well, I must not be the first one that want to use dictionary keys and dictionary values in an argparse argument.
oh, well here's something maybe? pypi.org/project/typed-argparse
oh hmm, no, that doesn't seem relevant.
I planned on doing some work to have a better argparse experience, and also thought of using dictionaries (except I wanted to do something a bit weird, by embedding list of different options for each element inside a dict).
Coming from linux, I like my command-line utility to have a gazillion options, so I thought this could work...
(it kind of does but it doesn't look clean)
@KarlKnechtel I like that way of thinking. I don't believe in reinventing the wheel, because when someone use this argument, it depends too much to be a sure thing, and one can always go further following that logic (eg: why would X lang exist when Y already does? what about that function? etc).
if it already exist and fit your requirements without you having to do it, then doing it still isn't useless per se, just not optimal (unless you do it for other reasons beside time or performance related constraint)
10:35
I feel like I always have to try to reinvent the wheel and fail at it before I get convinced of using what's already has been done before
I'm doing it less and less, but I still catch myself trying to reinvent the wheel here and there
I kind of like challenging those kind of notions, but I still also make version of my own project that try to follow existing things. It take a bit more time, but at some point it become kind of fun
but then again, it depends on the social context too: if it's business/company work related, you might want to take the shortest/best shortcut instead of "experimenting", unless you have enough time to do so, but otherwise, prioritize what's best for your own requirements
 
1 hour later…
12:06
OMG the denvercoder he exists: stackoverflow.com/questions/69857698/…
12:34
ah, I never used Django, but I think you'd need Ajax to check or do something whenever the page refresh, so that Django can then send the updated HTML values, or something along that line
by using the search terms "django dynamic HTML page reload" I get some interesting hits, but since I never used django, I'm not sure which one would fit for your case
So I could narrow my problem down, My custom tag doesn't run on a page reload, I have no clue why. I have disabled djangos caching using:
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    }
}
is the browser caching it or is it on the django side?
and my browsers caches. But I'm pretty sure there are more cache layers in between. I don't get how the filter runds the first time and not the second time I request the page, that seems so odd. I read: docs.djangoproject.com/en/4.1/topics/cache and docs.djangoproject.com/en/4.1/howto/custom-template-tags but that didn't really help...
like if you go into the network tab of the browser inspector, do you see it sending out the requests?
I think it's django site caching but I'm not sure, all that I can observe is that the custom tag get's called the first time I call that page, by seeing print statements in the log and not on the second call
@PeterT yes
12:41
I found this answer for disabling caching on client-side (django)
there also seems to be a cache_control decorator. Other answer also mention disabling caching in other ways
@NordineLotfi Django claims that is not necessary when having: docs.djangoproject.com/en/4.1/topics/cache/…
My tag is very simple it's being called like this {% collect 'a' 'b' 'c' as types %}
I'd try it anyway, even if the docs say it's not needed. Worse case, the docs is right (good thing?) best case, you find some clues or make it work
@register.tag
def collect(parser, token):
    print("Running collect tag")
    print(parser)
    print(token)
    bits = list(token.split_contents())
    print(bits)
    if len(bits) > 3 and bits[-2] == 'as':
        varname = bits[-1]
        items = bits[1:-2]
        return CollectNode(items, varname)
    else:
        raise template.TemplateSyntaxError('%r expected format is "item [item ...] as varname"' % bits[0])
@NordineLotfi That's cargo cult coding and I could try X other things, just to be sure. But the django doc is usually quite reliable and it does explicitly say that after selecting the caching framework you can subsequently chose the sites like mentioned in your answer, which makes me think that having a dummycache should disable the cache correctly
I think this might be your browser fault too, I mean, the docs doesn't mention those details right? Anyway, I'm just hypothesizing, especially since I never used Django :)
there a related answer that mention something like that
I'm not saying to never follow the docs btw, just that, "take into account it might not always be right". It doesn't really hurt to not depend on it and try things that could work (unless time is against you)
I actually did add the @never_cache decorator, but I guess I could check what nginx is doing, good this issue is annoying. Any other idea what it could be that something is called the first time the server is started, but not subsequent times? It does sound an awful lot like caching, but that is such a rabbit hole, that I'd rather search in the light for now...
@NordineLotfi true, Funnily I don't even have cache as a middleware, only the commonmiddleware, let's see if the site even runs without it
12:49
Adding 100 numbers, v0.2: pastebin.com/raw/XT5fv8xn. Larger than v0.1, which just had a single expression with a hundred lambdas in it. But the function definitions are more readable this way. And more importantly, they're more readily code golfed.
@NordineLotfi Nope, just as expected, same result
@Hakaishin hmm, I'm trying to think of other causes but it's hard to find ones I didn't already mention
can you make a small MRE with django? with the same exact problem, etc
@Kevin wow, this is indeed easier to read
@Hakaishin a really stupid suggestion: did you try to completely close the browser and start it again? maybe the cache is still loaded there, but otherwise I don't really know
@NordineLotfi Yes, I'm close to shutting off my pc, but not yet
@NordineLotfi I should try, that would involve setting up a django from scratch, which I have no clue how to do, but probably it's worth it
Ok it's not nginx, accessing django directly gives me the same behaviour, at least something
another obvious suggestion: did you try different browsers? maybe you can see it google-chrome/chromium/firefox/you_name_it show the same behavior
if it's only a specific browser, then you can lower the range of search for the clues
13:06
if he looked into the network tab and saw the requests going out then I think you can rule out the browser as the source. (or just get the site with curl to completely eliminate browser shenanigans)
ah, that's true. I didn't think of mentioning curl either, it's worth trying.
Yeah I tried chrome, same result, let me check again after all the cache shenanigens
(although, I think their site use ajax/js so curl might not work that much afaik)
nope, not for this one
I see, I guess it could work then
13:10
yeah same problem on chrome, it's a django thing pretty sure. I'm just building an mre
13:28
Sweet I have an MRE, let me dig some more into it and maybe I can then share a link here, I'm happy it's really minimal
Alright you should be able to download this: github.com/Kaju-Bubanja/django_tags_issue and the just run 'python manage.py runserver 8080' and go to localhost:8080/polls and then refresh the page
If you don't know django the important files are mysite/settings.py, polls/my_template.html, templatetags/poll_extras.py and polls/views.py
14:09
I guess I will have to resort to creating lists in this akward manner or in the view: stackoverflow.com/questions/4395230/…, sad that this cool way to create lists broke somehow: stackoverflow.com/questions/3715550/…
14:56
Adding 100 numbers, v0.3 through v0.5: dpaste.org/cbAvc
Curiously, pastebin gives me a 404 every time I try to upload that same text. Did I accidentally trigger a vulnerability?
All told, the 100 argument integer adder is composed of 935 characters of various combinations of S, K, and I. About 90% of that is constructing the 98th church numeral. Having to refer to n_32 and plus several times was a pretty big hit. Now, if we wanted to make a 130 argument adder... The 128th church numeral is much easier to define than the 98th.
15:20
@Kevin look better structured I think :o
(also didn't know about church numeral)
@Kevin maybe they have an anti-malicious script detection? probably, given a lot of people upload weird stuff there from time to time
when you say "pretty big hit", do you mean in term of performance or?
Just number of characters in the source code.
Which is not to say that the script has stellar performance. Adding two church numerals A and B takes O(A+B) time.
But the highest numeral we're using is 98, so it's not a huge deal. All of the arguments to add_100 are integers, not church numerals, so adding them is fast.
@NordineLotfi But if all they're doing is putting the text on the screen, they shouldn't need malicious script detection. That would be like if my mailman refused to deliver an envelope containing a piece of paper with the word "<script>" written on it.
@Kevin I think technically that is always the case unless numbers are bounded.
Sure, the malicious paper could theoretically harm a part of the US mail system... If they break half a dozen privacy laws and open the envelope, scan the contents, run OCR on it, save the text to their servers, and run eval() on it. But they're not supposed to do any of that, so there's no reason for the mailman to be vigilant of "<script>"
@MisterMiyagi I think you can get O(log(A)+log(B)) if your numbers are represented as arrays of ones and zeroes.
... But when you get down to the bare metal, can you really set and get values from an array in O(1) time, or is that only a polite fiction? Surely the memory bank for arr[999] is ever-so-slightly farther away from the CPU than the memory bank for arr[0].
Gotta account for that micro-micro-micro-second it takes for the electron to travel an extra angstrom
Not to mention difficulties such as cache misses, page thrashing, and saving your array to the cloud only to discover later that the cloud service changed headquarters and your array is in a cargo container on a six month sea voyage
15:46
Anyone knows hot to get-feature-names-out-from-linear-svc-pipeline? I've been using the suggested
def print_top10(vectorizer, clf, class_labels):
"""Prints features with the highest coefficient values, per class"""
feature_names = vectorizer.get_feature_names_out()
for i, class_label in enumerate(class_labels):
top10 = np.argsort(clf.coef_[i])[-10:]
print("%s: %s" % (class_label,
" ".join(feature_names[j] for j in top10)))
class_labels=clf.classes_

and it simply print empty classes, i've also posted a question here on stackoverflow without any answer
I think strictly speaking you have to look at each digit of each number, so that's at least O(A+B).
You get away with O(1) if both A and B are one "digit" each.
If A and B are the number of digits in each number, I agree that it's O(A+B). And church numerals effectively use base 1, so they're certainly doomed to linear performance.
@MisterMiyagi Hmm shouldn't it be O(1) as long as they're int each, regardless of whether they're single digits or not?
Likewise, ordinary grade-school addition is O(A+B) for numbers with A digits and B digits. You can add a three hundred digit number to another three hundred digit number with just 100 single-digit adds, plus another 0-100 for carrying the one.
If grade school addition were O(A+B) with respect to the value of the arguments rather than their number of digits, then adding two 300 digit numbers would take ten times as long as adding two 299 digit numbers.
@dhiaagr Python int or C int? A python int could, in principle, contain as many digits as you have bits in your hard drive. It would be unreasonable to expect your CPU to add two integers the size of a hard drive as quickly as it can add 2 plus 2.
16:01
@Kevin xDD, that would be very unreasonable indeed.
@dhiaagr only as long as int actually fits into a machine word, i.e. the machine's "digit".
I was talking about Python ints, when I learned about the big o notation, I just kept in mind that built in means O(1), and what you code is O(logn)+
@MisterMiyagi Oh I see! Yes, lol, I thought you were talking about digit as in 1 to 9
Ok, I exaggerate. The maxmimum number of digits is more like ((bits in hard drive) - (size of operating system and running processes)) * (1 - (percentage of space required to store the huge int's header/metadata/etc; let's say 0.10))
Interestingly enough, Python's int is an actual array of smaller fixed-width machine integers. So in the general case, for working with two ints you get the O(n+m) behaviour of working with two arrays.
I've been toying with the idea of making a "base 2 church numeral" that would have better arithmetic speed, and would hopefully not cause a RecursionError when I do twenty_thousand(do_thing)(x)
I wrote an SKI calculus interpreter that doesn't RecursionError unless it fills the entire hard drive, but it wasn't beautiful enough and I had it removed from my presence.
@Kevin Oops, I meant "... With just 300 single-digit adds, plus another 0-300"
16:27
@dhiaagr yah, that's basically the same as class-based components with state and props.
Minus the thises and the didmounts and the unmounts. Which is great for somebody that can easily get lost like me, lol
16:40
@Kevin nvm, I think it's a "hidden" size limit: reddit.com/r/pathofexile/comments/j8mrgk/…
they probably noticed people abusing this as "storage" and started to silently deleting whatever they call/deem to be "huge text files"
or maybe it's some other kind of limit. I know a lot of storage provider have hidden API limit, so that wouldn't surprise me
it's either that or some automatic malicious detector, but there no real way to be sure afaik
 
4 hours later…
20:50
I keep overestimating how much regular people know about computers. Not once, but twice now, has someone renamed a folder and then called me to ask why my program stopped creating files in that folder
being familiar with computers is definitely a learned skill
I remember getting angry at a relative because they failed to understand that whatever software they may use, whatever software. Its options have to be contained in window of the software.
Still they fail to remember the location of simple options because, in their mind, these options can be found, let's say, outside the window of the software, in the control panel of the computer or something and therefore, they have to ask me to do it so they don't break the computer.
In the same window displaying the software*
21:26
Eh, not their fault per se, I'd suggest patience...or running far far away depending on the situation :P
I fully agree, lol, although often the former is the only available recourse
I taught my mother how to google. Frankly it feels great to watch her pull it off now
She'll be midway through a sentence now about how she doesn't know how to do something, but she'll stop herself and say she could look it up. I feel like clapping and cheering every time it happens.
It took probably a year to get her to this level of comfort
That's quite the feat, actually, lol. Especially to siphon through the results, etc
21:41
yeah. basically, i changed my tact. i stopped showing her how to do things, and i started showing her how i figured out how to do things
It seemed to work well in this case. And ofcourse, she's my mother, i can never be mad at her, so that helps :)
That's very sweet, lol. Maybe I should take a couple of pages from your book
22:18
Oh what a thrill is VMWorld VMware Explore

« first day (4337 days earlier)      last day (836 days later) »