« first day (1812 days earlier)      last day (3142 days later) » 
00:00 - 17:0017:00 - 00:00

5:03 PM
No, there was no time travel in Lost, because that would be a stupid explanation for what started out as such a good mystery island. la la la la la
 
cbg
 
I loved the first few episodes of Lost
A POLAR BEAR? WHAT?
 
Bah, there wasn't that much time travel. That was like 20% of the plot, max
 
Then I read in a magazine that they had at least 5 seasons planned in which to tell the story, and as a viewer, they Lost me.
 
5:07 PM
What's the best way in python to check if a nested dict has an element and then return its value? For e.g >>> x
{'outer': {'inner': 1}}
>>> if x.get('outer') is not None:
... a = x['outer'].get('inner')
...
>>> print a
1
 
I would do this:
 
I'd probably do it like if 'outer' in x and 'inner' in x['outer']: print x['outer']['inner']
Wacky alternative: print x.get("outer", {}).get("inner")
 
try:
    y = x['outer']['inner']
except KeyError:
    y = None
 
^ +1
 
you could chain some .get's with a default empty dict, but the way you suggest seems most efficient
 
5:09 PM
@MorganThrapp your solution looks great to me
thanks @kevin too
 
Morgan's suggestion looks too poorly specified to me - it could hide the error of the 'outer' key not being there - but so would the others - it's just that it's not an error, so I wouldn't use exceptions here.
 
I think that's desired behavior.
 
@AaronHall True. If that's an issue, then I would go with Kevin's solution.
 
i want the value x['outer']['inner'] only if both keys are present. Else i'd like to return None
Morgan's solution works doesn't it?
 
You need C#'s new Elvis operator
 
5:12 PM
@linuxfan yes, his works
 
@linuxfan If that's what you need, then yes.
 
I think we're now just having a philosophical argument about what construes "exceptional" behavior
 
Oh wait, other languages have it
 
Happy to talk to the experts :)
 
I'd also profile it...
I think exceptions will be slower
 
5:13 PM
(construes? That doesn't sound right. What con- word am I thinking of.)
 
Construe is right
 
@Kevin Constitute?
 
No. Constitutes.
 
Yeah, you just think you're wrong
 
NO MORGAN. IT'S CONSTITUTE!
 
5:13 PM
 
I'll go with constitute.
 
If you expect lots of failures, exceptions are slower. But whether it matters is for profiling
 
Honestly, both solutions are good. I just prefer the whole "Ask for forgiveness not permission".
 
I am the opposite, I prefer to look before I leap. Not perfectly in line with the Zen of Python, but meh.
 
Eh, if my data won't conform to my code. It's clearly my data's fault. I code for what I want my data to be.
Checking what my actual data is would let the data win, and we can't let the data win.
 
5:20 PM
@corvid All of them. I prefer warriors/bruisers the best, so Butcher, Leoric, etc. I'm also partial to some Kharazim or Azmodan though. I also really, really love Murky :D
 
>>> d = {'outer': {'inner': 1}}
>>> e = {'outer': {'in': 1}}
>>> f = {'foo': 'bar'}
>>> import timeit
>>> def ex():
...     for _d in d, e, f:
...         try:
...             _d['outer']['inner']
...         except KeyError as error:
...             pass
...
>>> def get():
...     for _d in d, e, f:
...         _d.get('outer', {}).get('inner')
...
>>> def isin():
...     for _d in d, e, f:
...         if 'outer' in _d:
...             _d['outer'].get('inner')
...
>>> min(timeit.repeat(ex))
2.196000099182129
 
Looks about right. get suffers by having to make an empty dict whether it needs it or not, I'd guess.
 
Oh wow. I didn't realize how much slower exceptions are.
 
plus in _d is false 1 time in 3
So use exceptions for things that are exceptional.
 
Ok, I will.
 
user559633
5:24 PM
You're not my real dad!! slams door
 
preaches mostly to the choir
 
The door is your real dad. Checkmate.
Can't be bothered to double check whether that makes sense, it's Friday.
 
wonders if Kevin is Adam West's secret identity
 
Preposterous, old chum
 
@Ffisegydd Ah murky, so annoying he is. I usually play Kharazim, Sylvanas, or Thrall
 
5:34 PM
I haven't given HotS a try yet
 
@corvid Nice. I love Sylv but just don't do well with her.
I prefer to get in their face (Butcher <3)
 
Let's make a SoPython team
 
@AaronHall nice example with timeit - thanks
 
Lol I'll join you, but I don't know my battle net ID off the top of my head.
Who are good heroes to start out as?
 
Each has a difficulty rating, stick to Normal or below for your first 10-20 matches. What QC said.
 
5:38 PM
It does not matter. When you start you'll have a small subset of of heroes to pick from. The ones you like are gonna be the 'good' ones for you.
 
I'll probably default to ones that I recognize lol
 
I wouldn't suggest one that's Very Hard though, at least not in your first few games, because you literally will hate it as you'll get wrecked.
 
Yeah, I get that. I think I'll be 'alright'. I just need to get the feel of it down
 
It's very different to other mobas.
 
I've watched some gameplay and it appears it's more about working together than outplaying and whatnot
 
5:41 PM
 
Absolutely. It's all about the team play.
 
CHat doesn't expand imgurs?
 
Only if they're an actual image.
As in the page ends with .jp/png/whatever
Ah. No idea then.
Oh you can't type @Ffisegydd. You can only use the arrow.
 
Angband FTW
 
Waiting for OP... [skeleton.png]
My answer to that puzzling question has turned out to be controversial. I wish the asker would come put us out of our misery.
 
5:45 PM
I bet he's sitting back in his chair and laughing about how miserable he/she's making all of you.
 
> Comma-separated value (CSV) files are not supported by SQL Server bulk-import operations
How do they possibly justify this kind of laziness?
 
user559633
It's Microsoft. As if they care about developers
 
He might be waiting for me to make an incredible airtight proof of my answer. My weaksauce attempt at symbolic logic isn't satisfying enough.
 
insert Kappa here
 
... Will he row me to the special island? I have the link cable.
Or have I missed the proper reference.
 
5:48 PM
No, he will mock you with his grey face.
Sorry, I wasn't sure if anyone would get that. It's a twitch emote.
 
Oh, it's that guy.
I recognize him from saltybet.
 
I want to make an android app that lets you use Twitch emotes in your text messages. I feel like I'd probably be violating some sort of copyright though lol.
 
I often wish that I could use Something Awful emoticons on SO. :smith:
 
Someone better start up the dev on that
I think we need an expert in KevinScript though
 
@QuestionC It (sort of) is. If you need any help, let me know. I do it all the time.
 
5:54 PM
Dr. Fizzy Good - KevinScript Consultant.
 
Thanks, but I'm gonna give it the good old college try first.
Give it 110%
Want it harder than the other team.
 
user559633
You can't give it more than 100%.
 
user559633
@Kevin If you type them, most people would probably just imagine them anyway :unsmith:
 
what if he was only giving it 10% previously so he wants to give it 110% now?
(as in 11% now)
 
My battletag is Crowz#1678
 
5:57 PM
I despise the saying "Give it 110%"
 
It's easy. Give it 55%, then go back in time to this morning and give an additional 55%.
 
@corvid okay, I'll be on later and add you if I remember
I hear my odds of winning the lottery are 50-50. Either I win or I don't.
 
Concoct a pyramid scheme where you give 25.25%, and you convince three other people to do the same.
 
Playing a match as Tyrande at the moment. I hate her so much.
I just suck at ranged.
I also suck at support.
 
Just gotta get good, bro
 
6:06 PM
Support seems pretty hit or miss... Rehgar and Kharazim are fantastic, but most of the others suck
 
Support in general is usually pretty lame, at least to me. They should rename it to babysitter :^)
 
Kharazim is awesome because you just run in and hit people and that heals people around you.
 
I dunno, I always had fun playing Sona in LOL.
 
yeah but you have to build to protect the ADC you don't get to go full AP...
where's the fun in that? vision isnt satisfying!
 
I dunno, I just had fun running around and buffing everyone. Plus, Power Chord is super satisfying when you hit 2-3 people in a team fight.
 
6:09 PM
I'm guessing you don't install HotS via Steam?
 
no it's battle.net
 
@RobertGrant Nope, via the battle.net client.
 
@corvid you are NA right?
 
Yep, I'm always na
 
@corvid Don't be so hard on yourself, you're applicable to me.
 
6:11 PM
Me and Bob will be representing the EU.
 
in our inter-python tourney for NA vs EU in HotS?
 
(I'm gonna need some practice)
Also, saying "gonna" when playing against the US is right out
Wow, apparently the Battle.net client is 250MB
I remember when games were a few kb
Or maybe that's a lie and the info was phrased misleadingly
 
it's kind of a blizzard 'hub' now
 
Pokemon Red is 58kb, so yes, games used to be relatively tiny
 
Is it normal if at 33 years of age I started getting in to Pokemon now?
 
6:16 PM
not at all
 
what is wrong with me.....
 
it kind of amazes me that LoZ:OT downloads are only like. 26MB.
 
in fact you will be able to duel people IRL now for pokemon
 
how so?
 
I don't want pokemon IRL, I want a Pokemon The Matrix.
 
6:18 PM
hi
 
I forget what it's called, but it's like a cellphone app or you can use pokemon's device they're coming out with. Anywho, it's like 'real life' pokemon
 
Wow, 4GB download. I'm going to have to do that somewhere else!
 
I was solving one competitive coding problem, when I wrote `(a**(m-2))%m` I got timeout error ... but when I used `pow(a,m-2,m)`, it got accepted.

Amazed to see that solution getting accepted but wondering why `**` is slow.
 
Open source projects grow faster than their maintenance -> too bad
 
It's not so much that exponentiation is slow, it's that modular exponentiation is fast
 
6:23 PM
cool
 
(7 ** 30) % 2 has to calculate out the full decimal form of 7**30 before doing mod 2 on it. pow(7, 30, 2) can do mod 2 on each successive operation, which greatly reduces processing requirements.
 
Thanks.... this is really awesome.
 
@Kevin were you a mathlete?
 
Nah, extracurriculars would have cut into my TV time.
6
Q: How is ** implemented in Python?

NopeI'm wondering where I find the source to show how the operator ** is implemented in Python. Can someone point me in the right direction?

Ultimately, both pow and ** call the same function... But with **, the third argument z is always the same as x, which really hurts the run-time
Uh, I think. I can't actually read the source code quoted there.
 
6:44 PM
@Kevin What are the args?
 
Oops, by x I mean v.
int_pow(v,w,z) is equivalent to (v ** w) % z
 
Oh
why would a pow function need/want to modulo it?
 
It's a common task in cryptography.
 
What's the set operation for something that is in one set, but not another?
 
7:01 PM
Oh that isn't working as intended... maybe it has to do with a set being filled with objects?
 
The only set not filled with objects is the empty set
 
:)
Can't you use the subtraction operator?
 
@corvid do those objects have __hash__ implemented?
otherwise you'll be doing uniqueness by object-identity
 
far-out thought What if you could take the complement of the empty set in Python?
like whoa, man.
 
MemoryError
 
7:04 PM
what if you had enough memory though?
 
Time will tell...
 
A universe that can contain a computer with infinite memory, is so different to ours as to make any description of it meaningless
 
Use generators. =)
 
user559633
star trek: the next generatorization
 
@tristan I wonder how many people on the site use that Commander Keen avatar
 
user559633
7:10 PM
I think I've only seen one other person using it
 
@tristan I know @@keen uses it over on Sci-Fi
 
There's a moderator over on Scifi that has one
beaten
 
@Kevin My mod powers do nothing here!
 
Suuuure. Like I'm supposed to believe that the big "tank Kevin's latency so I can post first" switch on your control panel is just for decoration
 
user559633
if he tanked your latency, wouldn't your post show up faster?
 
7:15 PM
Depends on whether "tank" is taken to mean "lower" or "make less good"
Alternatively: the switch is usually in the "YES" position, and he switched it to "NO" just now.
 
Ergh. Say you have two arrays. Each is 5 elements, but one is shifted x indexes. Eg, ['d', 'b', 'c', 'd', 'e'] and ['c', 'd', 'e', 1, 2]. How could you extract the ones that are shifted in the second one?
 
second_one[:-2]
 
fixed it
 
7:33 PM
I now see the importance of documentation, now that I'm exploring this source code
Most of the private functions are left with no comments at all...
 
That magic switch thing is cool
 
It's a magical story. A more magical story.
 
>>> from setcomplement import SetComplement
>>> sc = SetComplement('abc')
>>> sc
SetComplement(set(['a', 'c', 'b']))
>>> 'd' in sc
True
>>> 'a' in sc
False
>>> sc.add('c')
>>> sc
SetComplement(set(['a', 'b']))
>>> 'c' in sc
True
>>> sc.discard('c')
>>> 'c' in sc
False
 
Nice.
 
7:44 PM
__len__ and __iter__ are problematic
 
Now bring me the set of all sets that don't contain themselves.
er, s/set/frozenset/
 
you can define a hash function on a mutating set...
 
Relatedly, is it possible to construct a tuple whose first element is itself?
You can do so with a list, but that's easier cuz it's mutable.
 
there's one predefined in fact
 
>>> a = a[0] = [0]
>>> a
[[...]]
>>> b = b[0] = (0,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
 
7:48 PM
>>> from collections import MutableSet
>>> help(MutableSet._hash)
 
10 Kevin brand fun bucks to whoever can make type(x) is tuple and x[0] is x evaluate to True
... Without redefining type
... Or True
... Or tuple. or is somehow.
 
I strongly suspect this is not possible for the same reason you can't struct A { A my_a; }; in C.
In my head at least, the word mutable means "Passing around a reference", and immutable means "Passing around a copy".
 
I withhold judgement. I will not be surprised whether it is impossible or not
 
How's the resume-brushing-up going?
 
I dug up my pre-BigCorp version, so I only need to add one entry
and possibly remove some detail from the Education section, now that I have proven myself to be an actually employable person and people no longer need to know my Humanities GPA or whatever
 
8:03 PM
for i in skills:
  i.years_experience += n
 
Right now I'm fretting about Interview Derp Moments because I, too, don't have a prepared response to "what's your favorite data structure?"
 
If you list yourself as Unlawful Evil then your humanity is the last thing you should advertise
I'd bone up on "What happens when you type google.com in a browser and push enter"
 
@QuestionC in Python you're always passing around a reference. A copy only happens when you make an actual copy. Immutable objects have no need for copy methods, because any "copy" can never change, so all copies would be redundant. Mutable objects allow for copies so that they can change independently of each other.
 
If they try that on me I'll talk about keyboard ghosting for forty minutes
 
@Kevin it's a trick question, the answer is always hash table. :P
 
8:07 PM
"Oh, cool. Write one for us. In C. On this whiteboard. No googling allowed, and yes, we'll ding you points if you can't remember whether it's memcpy or memcopy"
 
That's when you shake hands, thank them for their time, walk to closest pub...get a 16+ year old scotch...and just drink a bit....but just a bit.
 
"Trick question, we have in-house memory methods, you're fired"
 
My favorite is a LinkedHashMapListTable.
It can only be traversed with a RedDepthLastMiddleOut search.
 
"So why do you want to work here?" "Uh, because I desire goods and services?"
 
Rbrb!
 
8:12 PM
"Ok, you're frowning, so I can tell that was the wrong answer. I want to work here because I really care about enterprise synergy solutions"
 
Synergize me, beautiful.
 
No, I don't mind that you're using Python 2.5. Excuse me, I vomited in my mouth a little for unrelated reasons.
 
"What makes you a rockstar?". "Well I'm glad you asked:" Quickly point them to your git repo after you have conveniently performed this magic: github.com/avinassh/rockstar
best. repo. ever.
 
@Kevin WAS uses Jython 2.1 for it's admin scripting stuff.
That's before boolean literals were a thing in Python.
 
8:15 PM
:-(
 
I. What.... 10 minutes?
 
I think the fine print is 500 sessions of 10 minutes.
 
Rockstar promises 2 minutes!
T W O!
 
Here's the code for my SetComplement, if anyone wants to see it: github.com/aaronchall/PythonDeadEnds
 
What was the name of the twitter for the Earth-destroying asteroid running for president?
That question somehow didn't turn up any (relevant) hits on google.
 
8:28 PM
I'm gonna point out that github doesn't highlight your best code that's helped the most people (as opposed to some other site thingy)
 
My name is Smod. You have insulted my forefathers. Prepare to die. https://twitter.com/arstechnica/status/649941822639329280
 
Ty
 
8:45 PM
Not necessarily anyways.
 
8:58 PM
weekend rbrb :)
 
9:30 PM
I'm using itertools.count() to make a thread safe incrementing counter. Is there a way to grab the current count value without incrementing?
 
I can just keep a record of it from every time I do a next() then I guess
 
I mean, the longer version of that answer is: "There's a better way to do what you're trying to do than what you're doing"
but the short version is no.
 
What would the better way be?
 
maybe wrap a threading.Queue with a mutex, pop the value, and push the value+1 (storing the value so you can do work on it)
I'm not really sure. That's what I'd try if I needed to "re-get" values from a theadsafe counter
(though to my discredit, I never would have thought of using an itertools.count at all!)
 
9:35 PM
I take no credit either. A friend was looking through my code and moaning
I couldn't be bothered with anything clever so I used a global
This is just for a statistics thing. Counting how often the code does certain things, in and out of threads. So as long as the incrementing part is thread safe, I guess if I just store a copy of the value in the class, the worst that could happen is the code will read an out of date value (out by a single increment).
 
9:57 PM
You could probably do something like:
import threading

class Count(threading.Queue):

    def __init__(self):
        self.put(0)

    def increment(self):
        val = self.get()
        self.put(val+1)
        return val

    def get_value(self):
        val = self.get()
        self.put(val)
        return val

    def set_value(self, new_val):
        self.get()  # pull current value out
        self.put(new_val)
 
10:14 PM
then maybe make a decorator for the functions that need to be tracked?
my_counter = Count()

def count_calls(c: Count):
    def wrapper(f):
        def wrapped(*args, **kwargs):
            c.increment()
            f(*args, **kwargs)
        return wrapped
    return wrapper
@count_calls(my_counter)
def foo(arg):
    do_stuff_with(arg)
 
 
2 hours later…
11:50 PM
@AaronHall I'm waiting for the ListComplement sequel -- everything that's not in the list, but in reverse order.
 
00:00 - 17:0017:00 - 00:00

« first day (1812 days earlier)      last day (3142 days later) »