« first day (2076 days earlier)      last day (2890 days later) » 

12:12 AM
Is it better to move timer a global from this code, and can this be a way of repating function
def ping_pong():
    global users
    for user in users:
        try:
            users[user].send_message("PING")
        except StreamClosedError as e:
            print e
    Timer(30.0,ping_pong).start()
Does this lead to infinite recursion ?
 
what is that Timer from? does it call every 30 sec? or only once per call? are you stopping the timer when you ping_pong?
 
threading.Timer
It should repeat every 30 secs
 
why wouldn't you just use a while loop there (assuming your just trying to ping clients)? I can't see why you would need to use recursion in that case?
 
I don't want recursion, but this must be on another thread
Like you mean to while loop function and start it from another thread
That might me better solution
 
also, t = Timer(30.0, ping_pong, [users]) (then t.start()) and you can just pass the users to the function
well not the way it is written but you can pass lists to the function like that
    def ping_pong(local_users):
        for user in local_users:
            try:
                users[user].send_message("PING")
            except StreamClosedError as e:
                print e

    Timer(30.0,ping_pong,[users]).start()
 
12:25 AM
I don't need them passed, that will ping every single one of them, so they're global, just trying to understand does this create infinite number of Timer objects (recursive), or it ends up after creating timer object to call it again(repetative). I think second thing makes more sense.
 
tkinter Entry widget question: How do you get the word located at the cursor position?
It's not .index(), because you are required to pass in an index.
 
oh, you mean calling ping_pong within a Timer within itself -> yeah, that will be infinite
cause Timer can't end cause it keeps spawning itself though there would be some fun race conditions at 30 secs (as they start to close and spawn at the same time)
 
so the best thing is to spawn another thread and use time.sleep() in while and repeat
 
12:41 AM
kinda depends on the number of users/threads which would be needed and if you only want to pass when ping is successful or want a timeout (I assume that is why your trying to do the Timer).....actually, what are you trying to do?
before I go deeper into something you may be very close on already
 
So the tcp problem is because it's reading is passive, and if websocket client goes out of internet and didn't send disconnect package the user is hanging on server side waiting to reconnect, so if i try to send out any package to dead connection, it should raise StreamClosedError, and if it doesn't the user is still alive, so I'm going to remove user when StreamClosedError appears, this is just a test to see will it work
 
ahh...so literally just run every thirty seconds, K. Then I would do it the way I showed, pass user list to ping_pong(and assign to variable so it is easier to stop it later if error/problem) and run the for loop over the users - which should only spawn the single Thread
 
12:56 AM
Ok, will try yours, and the Timer solution, thanks :)
 
def ping_pong(local_users):
    #local_users could also just be a list of the keys to check on the global
    for user in local_users:
        try:
            users[user].send_message("PING") #note use global if editing and updating local at end
        except StreamClosedError as e:
            print e #see could mess with local_users here but leave global alone and update after completed

t = Timer(30.0,ping_pong,[users])
t.start() #assigning to t as it is easier to debug/stop later
^ little better explanation of what I meant
 
what about repetition ? It need's to be called every 30
 
actually, this has some better answers
34
Q: Python threading.timer - repeat function every 'n' seconds

user1431282I'm having difficulties with the python timer and would greatly appreciate some advice or help :D I'm not too knowledgeable of how threads work, but I just want to fire off a function every 0.5 seconds and be able to start and stop and reset the timer. However, I keep getting RuntimeError: thre...

 
yeah, there are many answers on topic stackoverflow.com/questions/2223157/…
:)
I've looked them all
including one you linked
 
hisssssssssssssss cbg snakes
 
1:09 AM
hello @idjaw what's up
 
hey!
relaxing after a long day out in the sun.
 
the answer by swapnil jariwala is pretty much exactly what you want there (create a Class for handling a continuous thread call until cancelled) - sorry I thought you had wrapped it in a thread already and just needed to call Timer at 30 sec intervals from it
 
Nope. I don't know, still trying to find better way to know when socket is dead
Lucky you @idjaw, here in my place, one day is like in Sahara, and the second day it rains like we're in the rain forests around Amazon
The weather is all crazy
 
1:24 AM
Funny. I'm hoping for rain because we just fertilized our lawn.
:P
 
2:22 AM
Alright, fixed my python questions.
 
DSM
Fixed in that you have answers, or that you had bad questions before and now they're good?
 
I have answers to my bad questions
ANd they are good answers.
It works flawlessly.
 
DSM
Congratulations, then!
 
Yep.
Autocomplete is fucking nightmare to work with.
You also need to test edge cases.
You cannot use regex
You can only work with tcl/tkinter widgets and limited implementations.
 
tkinter is a nightmare in general
 
2:26 AM
Ah, so I thought it's not me.
Especially in a multithreaded tkinter environment.....
Ughhh...
 
 
3 hours later…
5:53 AM
cabbage
 
Cabbage :-)
 
cbg \o
 
6:34 AM
cbg guys
is there any way to make the function take the default argument if None is passed instead?
some clever hack instead of if...else
 
6:53 AM
Huh?
What if you want to pass in None though?
 
for this case, None means pretty much nothing, so not passing and passing None are equivalent
 
They're still very different operations.
Don't allow passing nothing then, make it so you have to pass something, and if the something is None then do x = x if x is not None else default
But I'm still not entirely clear on what you want
 
@Ffisegydd That's the if check that I do now
was wondering if there are some hacks
 
7:10 AM
morning guys
 
@Ming morning.
 
I'm trying to understand the concept of hashes.
c = [1, 111, 3, 4, 5]
print(hash(c[0]))
print(hash(c[1])
why does it give me the same value as the array
 
Missing bracket there
 
whereas, for dictionary structure, it gives me a random number
yeah. realised that
comparing these 2 codes.
phone_book = {}
phone_book["jenny"] = "0165565643"
phone_book["lenny"] = "012334956"
print(hash(phone_book['jenny'])) # some random number
print(hash(phone_book['lenny'])) # -194507119 etc..

c = [1, 111, 3, 4, 5]
print(hash(c[0]))  # 1
print(hash(c[1]))  # 111
dictionary gives random hash number. assuming its the memory allocation. but list just gives the exact value (1 & 111)
 
>>> hash("0165565643")
3504713500554593035
>>> hash(0165565643)
30862243
 
7:14 AM
@khajvah Why use hacks? Why not just write decent, readable code?
 
>>> phone_book["jenny"] = 1
>>> print(hash(phone_book['jenny']))
1
 
@Ming it's for integers only.
 
Yeah that ^. Ninja'd Fizzy'd
 
@Ffisegydd oh yes. ur right. forgot that mine was a str.
 
another question: nosetests tests should be written as if they are running from the root directory of the project right?
my tests stopped running for some reason
 
7:19 AM
No idea, I use py.tests and there it'll recursively look through your structure for things that look like tests, or you can pass a flag with the specific directory.
 
i mean the imports inside the tests.
it used to work but it can't import now
 
@Ffisegydd does it mean hash('somestring') shows me the exact pointer to memory on my ram?
 
eh my tests are huge mess. gotta spend a month on cleaning up
 
so if i hash(1) . it returns 1. which means it points to memory 1 on my ram?
 
@Ming No.
You can find what the hash function does through some googling.
 
7:24 AM
"One use is a data structure called a hash table, widely used in computer software for rapid data lookup."
 
That is true.
 
is a hash basically same as unique_id in a database @Ffisegydd
 
you wish
 
@khajvah why not. a hash function gives the index of a value in a table. thats how a dict can lookup its value with O(1). is that correct ?
 
@Ming Dude. Do some research. Hashing is not a niche thing.
 
7:33 AM
got this on wikipedia
Hash functions are primarily used in hash tables,[1] to quickly locate a data record (e.g., a dictionary definition) given its search key (the headword). Specifically, the hash function is used to map the search key to an index; the index gives the place in the hash table where the corresponding record should be stored
"the hash function is used to map the search key to an index" Am i understanding it wrong?
"the hash function is used to map the search key to an index" == unique_id in a database
is that wrong?
 
Hey Python people
I found this newly posted answer in a NATO type thing, and it seemed to good to be true for me. So far, 2 people have unsucessfully searched for potential plag. Maybe one of you can give it a go?
@Ming A hash means you have some original text (lets take "Password" as an example) and then you run it through a cryptographic hash function that spits out some other (seemingly random) combination of characters. The lenght and content of that depends on the hash function. Now, from this combination of (seemingly random) characters, it is not possible (or shouldn't be, in a good hash with salt) to extract the original text from that.
 
@Ming keep on reading, keep on doing research, this is not a free tutorial service where you can do a small amount of work and then just expect us to fill in the gaps for your laziness.
 
@Ming all hash function does is return an integer from an object and make sure to return the same integer when you pass an equal object again.
 
@Magisch whether it's plagiarism is only part of the problem IMHO. It looks like a rant to me.
 
But if you run something through the hash function, you'll always get the same character garble for the same password
Effectively allowing you to compare against passwords without storing them
 
7:41 AM
@Magisch I realise you're trying to help by answering Ming's question :) but I'm also trying to get him to do his own research, rather than just expecting to be fed answers by the room :P
 
It actually just tickled my fancy a bit
:p
 
@Ffisegydd mmmmaybe search this site called Stack Overflow, I hear they have good answers? stackoverflow.com/questions/17585730/…
 
I only got here to inquire about this newly posted answer
 
@tripleee Yes, and Ming should go away and learn to find an answer like that by himself
 
@ming really ^ sorry for the misdirected ping
 
7:42 AM
Ah ok, no worries :P
 
8:07 AM
@Magisch @khajvah thanks for the help. appreciate it. its much clearer now.
@tripleee good link. thanks.
@Ffisegydd i did spend 1 hour just reading on hash function and watching a video from cs50 in youtube before asking questions here . Just wanted to clarify a point that i didnt understand fully.
 
These "method can be static" warnings are annoying
 
8:33 AM
 
9:08 AM
Cabbagey mornin'
 
9:27 AM
Ok. Than you can certainly guide me in which direction I should go? — user4618280 46 mins ago
why are people so demanding
 
cabbage
 
@khajvah It just needs one more delete vote
@AndrasDeak cbg
 
how's your birthday, @Bhargav?:)
 
Just like the other days :-)
 
aaaaww:( ;)
 
9:41 AM
happy birthday
 
@khajvah Thanks
unrelated answer (on the canon) stackoverflow.com/a/37964105/4099593
 
@BhargavRao why does this have this many upvotes?
 
@khajvah has 2 downvotes and no upvotes.
 
@BhargavRao I meant the question itself
 
That's a famous problem in python. :-)
Self answer by nick.
 
9:51 AM
oh i see
 
@BhargavRao How can one cast a delete vote on that? I just looked for it in the review queue - not there. Is it a privelige associated with a badge, or rep score I haven't got yet?
 
20k
For new stuff, otherwise you have to wait N days, assuming you have 10k.
 
Ah - cheers Fizzy - that would explain it
 
@JRichardSnape 20k. I want to ask on meta to reduce it to 10k with addl boundaries
 
10:08 AM
2 days I think
 
Cabbage.
 
cbg
 
@PM2Ring cbg \o
 
Is it bad if a motivational letter goes "I want to work in exchange for money"?
 
Yeah, 10k only lets you delete questions, you need 20k to delete answers. Which is slightly weird, since when you delete a question it takes all the answers with it.
 
10:12 AM
oooh, I had no idea answers were 20k only:(
@PM2Ring I guess that's the point: avoid delvoting rival answers
or ones using eval
 
Also, from stackoverflow.com/help/privileges/moderator-tools You must wait for a question to be closed for 2 days before you can vote for deletion. This restriction is removed for trusted users when a post scores -3 or lower.
 
@BhargavRao how was the OP able to post an answer to a protected question?
 
@tripleee Just in; They had 11 rep.
 
@BhargavRao ugh, I see ... that's a rather low boundary for "protection"
 
@tripleee it's against crazed spammers and people who only register to say "Thank you"
 
10:15 AM
@AndrasDeak what effects would it have if the limit was raised to, say, 50?
 
there are a lot of people between 10 and 50 who would be more than capable of writing proper answers
of course for a question to become protected there has to be some problematic history
usually old questions, to which I agree it's unlikely that a 30-rep user will give a brilliant new answer
but SO is all about answering, you don't even have to register for answering
the system would never do such a horrible thing as to prevent people from answering all those nice questions:P
 
I'm asking if there is any analysis of protected questions to demonstrate that answers by users in this particular rep bracket tend to be useful
 
@AndrasDeak I guess so, but it's still just a single delete out of the 3 needed, and surely if the system trusts someone enough to del-vote a question they should also be trusted enough to not do petty stuff to promote their own (or their friends') answers. OTOH, I guess it's not unknown for people to post an answer and then close-vote the question...
 
@tripleee I'm pretty sure there isn't, but you can search/ask on meta:P
@PM2Ring yup, people are assholes
 
This is a pretty comprehensive post stackoverflow.com/q/1894269/4099593
Has 5 to 6 ways of doing what's asked.
 
10:19 AM
omg numpy answer
and a "quick" eval
@BhargavRao the 52k answerer turned eval to literal_eval, I removed my downvote
 
@AndrasDeak Yup, rewrote the json answer.
 
Answering and then close-voting can be legitimate for dupes, when the new answer focuses on the new question and nicely summarizes (&/or updates) the answers at the dupe target. But if someone does that they ought to make it a Community Wiki answer, IMHO, just to demonstrate that they aren't rep-whoring.
 
@BhargavRao I saw you edited, didn't notice the time stamp:D
 
Unless the guy answering happens to be Martijn, because he's probably hit his daily rep-cap anyway. :)
 
@PM2Ring well if that's the case, it might be more reasonable to leave the question unduped at least by the answerer
dupes should be where the answer to the other question is directly applicable
I've self-deleted answers in the past where I realized that there's a good dupe
 
10:23 AM
@AndrasDeak Maybe, but if it doesn't get hammered then a new crop of answers will surely spring up.
 
if that's a problem, then it should be hammered rather than answered:P
but sure, I can imagine corner cases where this is OK
but not in general
 
@BhargavRao what's this google you speak of?
also, you'd need to know the keyword "parse":)
 
Google's a search engine too!
 
The updating thing is fairly important in Python, since there are lots of great answers which are in Python 2. Sometimes the required changes are minor, but it's not unusual for the Py2/Py3 differences to alter the relative merits of different answers.
 
10:28 AM
something something unicode
 
Cabbage Bobby
 
I emerge unscathed from Oxford Python
 
Yeah, Unicode. But also the fact that lots of Py3 functions return iterators instead of lists. Sure you can wrap the final result in a list(), but that may end up being less efficient than some other approach which was less efficient in Py2.
 
How big is an Oxford Python?
 
10:33 AM
Hehe, I managed to snatch an accept from alexce :D
@IntrepidBrit 16 feet long. Can swallow a human easily.
 
Bloody hell. That's intense.
 
@PM2Ring yup
 
I sometimes wonder if it'd be feasible to calculate a time-adjusted score for questions and answers, i.e., some algorithm that takes into account the fact that votes flowed a lot more freely in the Golden Era of SO, when the user base wasn't full of clueless newbies and there were still a lot of low-hanging fruit to get easy points from. But I suspect that such an algorithm would require magic, not just mathematics. :)
 
10:50 AM
Where's that famous post that timed the results for EAFP and the LBYL approaches? I am not able to find it atm.
 
Do we have a good dupe target for this: stackoverflow.com/questions/37965638/… ? I've already linked "Python list of lists, changes reflected across sublists unexpectedly", but I was hoping for something more specific.
 
That's a huge block there, Looking at it
 
@IntrepidBrit the real question is: how much does it recommend DjangoGirls tutorials over all others? Ans: a lot.
 
cbg
all :)
 
@PM2Ring Nope, Can't find one.
@MarkoMackic cbg
 
10:59 AM
@RobertGrant Wait what? I didn't realise there was such a thing.
 
@BhargavRao I just found this one, but it's appending dicts: stackoverflow.com/questions/32057828/…
 
The copy-clone a list is the best fallback :-)
 
Apparently
They also mentioned TwoScoops a lot
 
@BhargavRao This one? stackoverflow.com/questions/2612802/… I guess it'd do if we can't find anything better.
 
Yup, That's the one.
> Whenever the dictionary is sparse, The LBYL method scores over the EAFP due to memoization.
Is that true? --^
 
11:10 AM
Does Two Scoops only do books? If so, can they really be counted on as distributing best practices? It's not like they'd be open to open criticism
 
@BhargavRao Ok. I've Cv'ed it. So you can hammer it. :)
 
@PM2Ring So you went with the fallback :-)
 
@BhargavRao Yeah, I'm sick of Googling. I guess we should keep a look out for a better dupe target, since it is a fairly common problem.
 
@IntrepidBrit it's probably written in consultation with django devs, so I guess that depends on whether you think django follows best practices :)
 
@PM2Ring I usually search in the linked posts of that question. But this time I couldn't find one for that.
 
11:18 AM
I had great hopes for "Appending to a list in Python: adds last element every time?". It has an answer by Martijn, but it's building a list of dicts.
 
Answer by Martijn, implies that it's a great target! ;) (for a future post)
 
youtube got invaded by highly trained monkeys
yet again
 
@khajvah Annoying, isn't it.
 
Never seen that before, TBH.
 
Turns out, YouTube going offline enables buffering on videos you still have open in your tabs.
 
11:31 AM
I have seen it 3 times
 
I’m able to rewatch them without problems.
and they are fully buffered
something that never happens usually..
 
yeah they don't fully buffer
 
dupe stackoverflow.com/questions/37966559/… Either target is ok, but I like mine better. :)
 
We get both anyway
 
Hi
is it possible to export a list of class instances to csv file ?
 
11:40 AM
now that's really interesting question lol
 
it’s called serialization
 
but why in csv
 
doesn’t really matter what serialization target format you have
 
ok
 
11:44 AM
@poke that is interesting :)
 
@poke anyways, you must write your own serialization, can't serialize class directly..
 
Wonder if they check if the server's still there, and if it is then they start to delete cached video
But if not they leave it, so you can keep watching and you won't notice it was gone
 
It depends of class structure @Hamza_L but it's sure possible :)
 
@MarkoMackic If the class provides a decent __repr__ or __str__ method then serialization is trivial.
 
it's the first time I develop with Python
and the class is simple :) , 3 properties : name, age, location
I just wanted to export a list of person to a csv file
 
11:49 AM
@MarkoMackic CSV is easy to read & write. And it's more compact than JSON or XML. OTOH, if you attempt to modify the CSV by hand it's much easier to make mistakes than with a more structured format. And it can be harder to find & fix those mistakes, too.
@Hamza_L See the sections on __repr__ and __str__ here: docs.python.org/3/reference/datamodel.html#object.__repr__
 
@PM2Ring do you agree that this case could be solved easier using txt file with "name,age,location" per line ? It's easy to reconstruct line by line too. without any using of csv, __repr__ and __str__
 
thanks
 
well it turned it bold why ?
 
@MarkoMackic Because double underscore is a bold style command. But you can escape it using backticks. `__stuff__`
 
now did :)
 
11:54 AM
I think I have a solution : convert the instances to dictionnary
with dict
dict.
__dict __
 
Yes, you could use the class's __dict__, and send that to the csv DictWriter. BUt it's still nice to give a class a __repr__ method. It makes it much easier to work with and test the class, even if you don't need to output the repr string in the final production code.
 
I never understood using unit testing, although it seems so important for production code
@Hamza_L of topic, where are you from
 
Tunisia
thanks @PM2Ring ;)
 
No worries.
 
12:12 PM
@MarkoMackic huh? any code really. if you edit a program you haven't touched in a long time, how do you know you are not breaking functionality when you make changes?
 
I don't know, I comment my code alot
 
@MarkoMackic and you never make bugs?
my experience is that creating test cases uncovers bugs even before your users see them
and then you have the added benefit that you occasionally catch a stupid regression before committing a change
there are many different development styles, but not thinking about test cases is like not thinking about version control
 
I will try to get them into my routine :)
And I make bugs, of course
 
Mar 15 at 16:34, by DSM
Word of the day. dunderbold: the unintentional bolding of words due to an absence of code-quoting.
;)
oh, @Marko mentioned it first, so there ^
btw Marko, what are you doing up so early?
 
On my regular keyboard I disabled that key by unfortunate mistake..
@AndrasDeak finishing :p
 
12:18 PM
@MarkoMackic :D
it's almost done, right?
 
I always find some bugs, not sure any more ..
But It's good to be optimistic so almost done :D
 
morning cabbages all
 
cabbage inspector
 
yes, that's my name. Show me your cabbages, so I may inspect them :P
 
12:25 PM
cbg inspector :)
 
@inspectorG4dget I'd love to see what urbandictionary says for "cabbage" in this context:P
 
blame your silly language and its apparent hate for commas
I always remove most of my commas, lest I overuse them
 
gotta love top-voted definitions
 
12:28 PM
commas save lives: you can either eat dinner with your aunt, or have her for dinner (let's eat, aunt Sally)
 
yeah I know
but nobody seems to use commas before addressing others, so I gradually believe that this is proper grammar
 
or "help Uncle Jack, off a horse"
 
Is there any way to not touch JabbaScript in 2016?
 
I don't even know what it is, so I wanna say yes?
 
12:30 PM
@inspectorG4dget doo doo doo dodoo ----- can't touch this
fortunately there are no tunes in text so you can't tell that I have no idea how the song goes
"song"
I was going to say "melody" but that's an even worse fit
 
Cbg!
 
:)lol
jabba script?
 
yeah
 
I love that this already exists. I was just thinking that it should
 
12:34 PM
what does it?
 
Judging by its name it combines two of the most beautiful things found in the two relevant galaxies.
 
morning everyone
 
some syntax apstraction to js I think
 
"an experiment in lightweight syntactical additions to javascript" oh G
 
I've got an interview tomorrow. What do?
 
12:42 PM
Attend.
 
true
 
@corvid read about basic algorithm stuff that you will never explicitely use
 
Knock the hell out of them
 
I got rekt a month ago on basic algorithms that I couldn't remember.
 
get up-to-date with n log(log n)) algorithms
 
12:47 PM
@khajvah what if the company exclusively develops palindrome and directed graph algorithms?
 
@corvid bretty interesting
 
I wonder what PY developer should got under his belt to cope some killing questions
 
the answers to said questions
I know, it's deep
 
Saw this today, Quite rare
 
collections.defaultdict is holy
 
12:53 PM
simple things in life: I just realized that I computed the correct equation to a line!
 
If anyone here had exp with socket, what's the best way to determine socket failure from server, I'm currently using ping-pong messages, but wondering is there usual way to do it
 

« first day (2076 days earlier)      last day (2890 days later) »