« first day (2088 days earlier)      last day (2864 days later) » 

1:24 AM
I have a very very strange problem pastebin.com/JLBYxzFD , here is a log that my app is generating, and here is the code pastebin.com/BGPVX0cx I'm wrestling with this referencing problem for 3 hours, sometimes it happens, sometimes not, I don't know what it is ( if you look at the log comments begin with <-- )
If anyone looks up to code , the important part is in UserServ :D
 
DSM
1:42 AM
I had a quick skim but I'm afraid it's a little hard to follow. :-) Is there a driver we can run to generate your expected output?
 
you mean to test this
?
 
DSM
Well, yeah. It's not really an MCVE right now, and there's not really an easy way to help you make one, because it's just code.
 
Yeah, I'll post it on github, the whole page, it's chat, code isn't self driven without clients
Tomorrow, its 4 AM here :) I'm going to sleep now :)
 
DSM
But when you write your tests you'll need automated conversations anyway. :-)
Enjoy the sleep! Tomorrow all might be clear.
 
Thanks, good night to you too :)
 
 
2 hours later…
3:35 AM
Is there any way to change an scientifically notated number from math.pow into a string with all the zeros?
 
How do you mean?
 
I've done 2 to the power of 1000 and it's become a number in scientific notation. How can I transform it into a string while saving the zeros?
 
>>> math.pow(3, 60)
4.23911582752162e+28
>>> int(_)
42391158275216203520420085760
 
Ahh
Stupid me
Thanks @JonClements
 
DSM
Remember to decide whether you want to preserve all the precision or not: by using math.pow you're working with floats.
 
3:43 AM
'{:f}'.format(1.5e-6) -> '0.000002'
 
Umm... any reason you can't do 2 ** 1000 if you don't need floats?
 
DSM
3:56 AM
Not as far as I know. Plus I'm not sure I know what saving the zeroes means anyhow.
 
Plus - I'd have imagined powers of 2s is going to be very efficient anyway :)
 
DSM
G
I know it's time to sleep when I find myself asking "why is planking no longer a thing?"
Just-after-midnight rhubarb for all!
 
rbrb!
 
4:28 AM
Hey guys
 
howdy
 
 
1 hour later…
5:33 AM
Cabbage :-)
 
cbg pups - how goes it?
 
Monday morning :-) Bright as the sun. How about you?
 
I'm always the same old :)
 
Olu
Good morning
 
Morning :)
 
5:46 AM
Awww... Atleast we are cute puppies, unlike the ugly humans :D
 
6:02 AM
@thefourtheye of course :)
 
 
1 hour later…
7:12 AM
cbg
 
7:45 AM
hello guys :)
 
cbg
 
@wonderb0lt long time no see - how's things?
 
@JonClements Good, good! I have a Python project at the moment which reminded me of the fact this channel still exists. :)
I see you're still sporting a healthy blue color :)
 
8:03 AM
Is hypothermia healthy then? Yup - got my sheriff badge a couple of weeks ago - so I've lasted a year :)
 
Cabbage!
 
How long is the term of a dictator moderator?
 
cbg @poke
@wonderb0lt there's no term - it's either until you step down or f* up enough to get sacked
 
So like a proper dictator then. Very well!
 
Isn't the spelling of "coup" strange?
 
8:11 AM
Yup - no doubt due to it's latin/french origins and then the traditional English bastardisation of words...
 
Isn’t the spelling of “soup” strange?
(sorry)
 
Cabbage
@poke No stranger than "you". :)
@JonClements You'd think so, but 2 ** n is not optimized, and 1 << n is significantly faster, especially for large n.
from timeit import Timer

commands = {'stars' : '2 ** num', 'shift' : '1 << num'}

def time_test(loops, reps):
    timings = []
    setup = 'from __main__ import num'
    for name, cmd in commands.items():
        result = Timer(cmd, setup).repeat(reps, loops)
        result.sort()
        timings.append((result, name))

    timings.sort()
    for result, name in timings:
        print(name, result)

    #Find the ratio of slowest / fastest
    tlo, thi = [timings[i][0][0] for i in (0, -1)]
    print('ratio: {0:f}\n'.format(thi / tlo))
rbrb
 
Interesting - you'd have thought 2**n could be optimised into a bit shift op...
 
8:30 AM
How do I deprecate a class in Python?
 
@JonClements couldn’t peephole do that?
 
@poke I'd have thought so :)
 
class XY:
    pass
original_XY = XY
def XY(*args, **kwargs):
    print('XY is deprecated')
    return original_XY(*args, **kwargs)
maybe? ^^
@JonClements I’m actually wondering whether it can do that since it’s a [X] [Y] [Z] bytecode where the [Y] is the variable one
 
@poke rather than use print, use the warnings module
and you can put that warning in XY.__init__
no need to wrap it in a function ;-)
 
import warnings

class A:
    warnings.warn("class A is deprecated", DeprecationWarning)
    ...
 
8:34 AM
Wasn’t a serious suggestion anyway :P
 
class XY:
    def __init__(self):
        warnings.warn("XY is deprecated, use FooBar instead", DeprecationWarning)
@vaultah: not in the class body.
 
why not?
 
That'll trigger the warning when you import that module.
What if there is other code in that module that is not deprecated?
If the module is deprecated then just put it in the module.
 
well, that can be desirable :p
 
But then you would put the warning into the module, not the class.. :P
 
8:36 AM
import warnings

def deprecated(klass):
    warnings.warn(
        '{} is deprecated'.format(klass.__name__, DeprecationWarning)
    )
    return klass

class Test:
    pass

@deprecated
class Test2:
    pass

t1 = Test()
t2 = Test2()
 
cabbage
 
I don’t really understand the peephole logic…
 
Then if you wanted you could adapt deprecated to provide custom messages...
 
@JonClements But that also warns when the class is defined (module is imported) instead of when it’s being used
 
Blah... well - you can always adapt the decorator to avoid that :)
 
8:42 AM
@holdenweb Haha, it's fine. I was despairing that someone was earning $10k/month on pantheon.
Morning cabbage
 
@Ffisegydd it's short for "coup d'etat"
so I'm pretty sure it's French
 
no, you cannot use any deprecated decorator on the class itself... :/
because this class is to be subclassed :D
only I've decided that it is braindead.
now I decorated the __new__ method, it shall do.
 
What did that class do to become deprecated? Be written in python 2?
 
because using subclassing for an API is a bad idea.
In Python doubly so.
 
(sorry, that's all I can do before my first coffee)
 
8:45 AM
def deprecated(c):
    class deprecatedClass (c):
        def __init__ (self, *args, **kwargs):
            super().__init__(self, *args, **kwargs)
            warnings.warn('Deprecated!')
    return deprecatedClass
Maybe?
 
hehe nice
 
Morning cbg
 
sucks that class decorators are not that well thought-out
 
@Withnail cabbage
 
@AndrasDeak my son has a move where he poos so much it goes out of his nappy, under his clothes and onto his head. He calls it the Poo d'État.
 
8:49 AM
:D
I seriously hope you're not joking
with the he calls part
 
haha. sophisticated punning toddler.
 
having a child shit all over themselves, while them being able to vocalize this fact in an erudite way, would be priceless
not exactly what I'm trying to say but again, too early for me to express myself as well as I'd like:)
 
Well, you're no my son.
 
exactly:D
but I'm content with not pooing on my head
you've got to take what llfe gives you
 
I've been up since 5, I've only had one coffee and I need a nap. a) you're doing much better than me, and b) I may actually be a toddler-manchild.
 
8:57 AM
just make sure your diaper is fully sealed
 
I'll probably snooze in the bathtub, just to be sure.
 
@Withnail with a toaster balanced on the side? :p
 
No, I've had breakfast already.
 
@AndrasDeak Good to see that you haven't been eaten by werewolves from Überwald. :)
I don't know Pandas, but this smells like an XY problem: stackoverflow.com/questions/38178438/…
 
cbg
JS universe is so full of hacks
 
9:05 AM
@PM2Ring :D I went the other way;)
and I'm told bears are a more common problem nowadays
 
I never understand why people want to use JS server-side.
 
@PM2Ring big-ass syntax problem there, highlighter shouts too
 
I was just trying to test front end JS
 
' ' ' is the key...
 
Realized I need 5 .js's to get it working
 
9:07 AM
@AndrasDeak But at least there's two of those, so they cancel out, eventually. :)
 
ugly as hell
@Withnail my guess is that there are many JS developers
 
@Withnail Using JS server-side makes sense when the only other language you know is PHP. :)
 
:D
 
haha
 
this whole thing is bunch of hacks slapped together
 
9:09 AM
morning guys
 
so I decided to not write tests.
 
...how did you get access to my source code @khajvah? :o
 
can we do this in python.
	def value(self):
		return {update: lambda x: return self.model.value.append(x)}
 
@Withnail :D
 
im getting an error. but basically want to create a function within a function
 
9:10 AM
what error?
 
@PM2Ring heh, yeah:D
 
That's not valid dict syntax - unless update is a hashable variable in scope - do you mean to use 'update' ?
 
@Ming lambda doesn't need a return (double ninja!)
 
@Ming also, you don't return from lambda
 
@Ming You don't put return in a lambda
 
9:11 AM
but .append won't return you anything
will it?
 
is this the right way??
def value(self):
def abc(x):
return x * x
def d(x):
return d + d
return {'abc':abc, d:d}
 
I think it can be shortened to just return {update: self.model.value.append}
 
@AndrasDeak @Ming .append returns None
 
@AndrasDeak it'll return None but the .append will stay take place...
 
yes, yes, thank you gentlemen:P
 
9:12 AM
	def value(self):
		def abc(x):
			return x * x
		def d(x):
			return d + d
		return {'abc':abc, d:d}
@PM2Ring sry it part of a larger code. had some mix in there.
but is this the right format??
 
@Ming I'm not sure a function is hashable
 
what's your desired output here?
 
I think you mean `{'abc':abc, 'd':d}'
with a string for the key 'd'
 
Your interpreter will give you errors still - so no - what are you trying to do - functions within functions is valid - but errr... why?
 
but it works though
 
9:14 AM
@Ming yes... because d is a function and they're hashable so can be used as keys in a dict...
 
indeed they are (just checked)
mildly surprising
 
@Ming, I think you want something like this: {'abc':lambda x: x*x, 'd':lambda x: x+x}
 
@Andras not really :)
 
@JonClements to me:)
 
why would you hash functions?
 
9:15 AM
def test():
	def hi(x):
		return 'say ', x
	def anotherHi(y):
		return 'say hi again ', y
	return {'x':hi, 'y':anotherHi}

print(test()['x']('hey im saying hi'))
this code works.
 
looks like javascript
 
@khajvah sry getting too much from javascript. they use return {obj: fn, obj2:fn2}
 
I don't have any knowledge about hashableness and the underlying machinery. I only know that lists are not hashable, and I would assume that a function is more complicated than a list:D But it obviously doesn't work like this.
 
yeah
 
Oooo... Nigel Farage has resigned (again) as UKIP leader...
 
9:16 AM
but if not any other suggestions to improve it?? @khajvah @PM2Ring
 
trying to break a Guinness world record for number of resignations
 
@khajvah So you can do stuff like this: self.brackets = {dict: '{}', list: '[]'}
 
@AndrasDeak lists are not hashable because they are mutable
 
@khajvah ooh, that would make sense. Thanks
 
@Ming I don't understand the reason you are doing this
 
9:17 AM
Jon, there was chat he's going to get offered a g'ment position. Whole worlds of wtf.
 
yeah, @Ming, this looks like an XY problem. If you explain what you want to achieve, there's surely a simpler and more obvious way to do it in python
 
actually. i just want to figure out how to have sub functions within functions. because isnt this a common pattern in javascript?? its useful for many common cases no? @AndrasDeak
@khajvah is this normal for python? because is normal in javascript right?
 
JS and python are a biiit different
 
sub functions within functions..? huh? For what purpose?
And this is Python, not JavaScript.
 
programming patterns are different, a lot
and anti patterns too
 
9:20 AM
so this pattern does not make sense in python??
 
@Ming they are useful in JavaScript because of async stuff(I think)
 
I still have no idea what you are referring to.
 
that ^
 
i just want to know if its pythonic for functions to return functions. thats it.
@poke
 
you don't need to have that function nested inside your function to return it
 
9:21 AM
@Ming it's not unheard of - but like others have already said - I think you're seriously misusing it :)
 
@Ming In very rare cases
 
It's not "very rare" at all.
 
no?
 
Ever used a decorator?
 
@JonClements can i know a reason why its rare as compared to js? is it because there is no usecase for it?
 
9:22 AM
Yeah, it’s really not uncommon, but probably not in the way you expect @Ming. So you should really clarify what kind of thing you expect.
 
well that's kind of different than what he is doing
 
It's not rare.
@khajvah no it's literally exactly the same.
 
@Ffisegydd I wonder if that was a "real" research. The first page looks convincing though
 
It's returning a function from a function.
 
interesting, but nothing unexpected 😔 just a proof of what everybody knows to be true
 
9:23 AM
How you use it is up to each, but the action of returning functions (first class objects) from functions is normal.
 
@khajvah “different than what he is doing” – So far, I still have no idea what he is actually doing.
 
This is also true :P
 
@Ffisegydd to implement a common pattern
 
ok. i think the general consensus is this is not pythonic. thanks for the help guys
 
That’s not the consensus at all…
 
9:25 AM
nope
 
@Ming I'm pretty sure you haven't listened to anything we've said.
 
^ that
 
the general consensus so far is "unless you explain what you want, we can't help"
or something:P
 
But then again, we've not been able to listen to anything you've said because you're refusing to explain yourself.
 
@poke what I mean is that decorator is commonly accepted pattern and we use those functions returning functions for that case only. Outside of decorators, I can't think of any reason.
 
9:26 AM
We still have no idea what you are trying to do, or even what you are actually referring to. So unless you clarify that, we won’t be able to get into any details. But if you don’t want to do that, then feel free to take any implication out of this discussion @Ming
 
@Ffisegydd there is no usecase for this. i just wanted to know if this is a common pattern.
 
buh
 
@khajvah there can be a lot of reasons, but maybe not common ones
 
im not doing anything with it. just wanted to know if "i can return a function within a function"
 
well, those reasons might all be formulated as a decorator...
 
9:27 AM
yeah that's what I said earlier.
 
Then the answer is a simple: yes, you can.
 
or if its pythonic to do so. because in js is common
 
Yes it's perfectly fine and perfectly pythonic.
I do it a lot, both in decorators and not.
 
ok. because lots of comments earlier were different
 
9:27 AM
Yes, they were.
 
I'm getting coffee
 
@Ffisegydd thanks. :)
 
So am I.
 
@Ffisegydd where else do you use them?
 
@khajvah Currying is a very common use case.
 
9:28 AM
I can imagine his thingy that works with a lot of functions can have a builder that puts together custom functions or something
you could have a function that returns a differentiated function, of course that would probably be doable with decorators
there are several interpolators in scipy, which are based on callable objects, which is not the same, but close
at least in my opinion
@Ffisegydd [late answers queue] can a paper go through peer review if the authors are deported to a gulag during the process?
 
I believe several of the more predatory journals operate their own gulags for just this purpose.
 
@poke ok, maybe I didn't use them that's why it's strange to me. I will try some in future.
 
> 2 people viewed your profile in last 90 days
getting pretty famous tehre
 
@khajvah Currying, callbacks, decorators, analysis pipelines, to name a few.
I suppose "analysis pipelines" counts as currying.
 
9:46 AM
functoolz uses it a lot...
 
10:00 AM
:(
Another laptop I'm not able to save
 
@IntrepidBrit Did you do a dramatic: "That's it guys! I'm calling it!" after trying CPR? :p
 
make sure you specify time of death in UTC to prevent any confusion
5
 
Don't you hate it when you're trying to do something horrific and the programming language tries to stop you?
 
@JonClements Haha. Basically. I had to then sit down the owner to let them down gently
@Ffisegydd I can tell you're probably not using C
 
10:04 AM
"God damn you JS I'll shoot myself in the foot if I want to!"
 
@Ffisegydd What did you try to do with that? Usually it will allow anything and everything and leave the developer with a weird stack trace because of the asynchronicity.
 
It's actually Angular, not JS.
 
Ah, I don't know that.
 
10:27 AM
 
10:43 AM
Unclear what they're asking, one and two (a pair of blog-style self-answers, but the questions are literally just blurbs along the lines of "here is a code snippet with lambda functions in Tkinter"). They're also nearly identical, and neither one has any explanation attached to the code block, either.
 
separate Q&A for "OOP style" and "procedural style" ....... no.
modflagging for merge
flagged
 
cabbage
 
I can't delv yet
 
10:53 AM
then just close and dv
 
and the depth of crappiness only struck me after modflagging...
 
since it is a self-answer, there is no harm done by deleting that :d
 
I should really write that "decline own flag" feature request on meta
 
no one else wouldn't be helped by that :D
 
who knows!!11 :D
 
10:55 AM
Umm... it does look like they're trying though - considering the amount of crap that normally comes onto the site - probably with some editing to expand it/format it better - it'd possible it'd be useful :)
 
OK, no need to ask, it's status-planned on MSE. Since end of April
 
@JonClements go ahead, edit it :d
 
Haha "not my job" :p
 
I am voting for "quexit"
 
10:57 AM
@AndrasDeak I'm not doing anything with it - but I marked your flag as helpful as I can see why :)
 
lazy mod :d
 
thank you, I just noticed that you handled it:)
 
@AnttiHaapala Yeah yeah... I know... bad puppy :)
 
good puppy doesn't strain himself for no good reason:P
 
hey guys. can functional and OO paradigms coexist together in codebases or do they conflict?
 
11:04 AM
@AndrasDeak Congratulations on hitting 10k!
 
thank you:)
I'm having a ball in NATO:D
 
@AndrasDeak woot - congrats!
Now you get to see all the deleted rubbish :)
 
thank you too:)
@JonClements yes!:D
 
The good thing about 10k rep is that you can see all the deleted answers. The bad thing about 10k rep is that you can see all the deleted answers.
 
I've been waiting for this for so long
well, since 7-8k
deleted crap and the NATO tool were my motivation to reach it
I always felt like a peasant when facing links to deleted posts:P
 
11:11 AM
I feel like a glorious leader, whose 10k+ minions have whittled away the dross that I don't have to think about
 
I also expected to delete some stuff, but I quickly realized that most of the delete-worthy crap are removed way quicker than the 2-day limit imposed on my kind
but that's OK
 
@AndrasDeak the other thing you get with 10k which is a bit under-rated is that in the review queues, when you click the "history" tab - you see the complete history by everyone and not just yours :)
@AndrasDeak so try stackoverflow.com/review/close/history for instance :)
 
You know you’ve reached a bad place, when you have an iframe with a frameset inside…
 
If someone asks you why you did it, deny all responsibility and say you were framed.
 
I didn’t do it.
I’m just seeing it.
And I’m not liking what I see.
 
11:23 AM
@poke I was (frame)set up! I've been framed!? :p
 
wow…
 
Have reshowered and re-coffeed. Attempt at the day, No. 2. I feel like I'm channeling Andras's inner coffeedesire.
 
Is that a good thing?
 
It's a powerful thing. Good or bad? Remains to be seen.
 
11:39 AM
@PM2Ring how about: ' '.join(itemgetter(*positions)(words)) ?
 
my network connection is acting up...:/
JonClements thanks, I was aware of that:) Although I admit that I'm part of the underraters, at least yet
 
I only just found out about itemgetter and attrgetter - amazing.
 
You n00b Bobby G :p
 
@JonClements :) I've just added a list comp, but I don't want to totally bamboozle the poor kid. OTOH, it is probably a homework question...
 
:o omg. Even i knew about them! :p
 
11:42 AM
@Withnail I had mine, and I already feel more capable than a chimpanzee <it's something.gif>
 
@PM2Ring well - technically you added a gen-exp :)
 
I'm sort of about undergrad-in-the-morning levels of cognisance.
 
@JonClements Oops! That was a typo. I almost always feed .join a list comp.
@RobertGrant I'm pretty sure that itemgetter runs at C speed, but it's definitely better than the equivalent lambda.
 
That's cool
 
@PM2Ring you're normally the timeit guy :)
I'd be surprised if itemgetter didn't out-do a list-comp though
 
11:46 AM
Solving this in one line made me feel a bit smart
Waits for JC to somehow solve it in no lines
 
@RobertGrant that's Martijn territory :)
 
@JonClements I haven't time-tested it myself, but I vaguely remember someone (probably Martijn, maybe Antti) extolling the virtues of itemgetter.
 
From here you look the same :)
 
@RobertGrant now I know where those obscure constraints in SO questions come from
 
@AndrasDeak Out of interest Andras - why haven't you accepted your own answer? (stackoverflow.com/questions/37872171/…)
 
11:49 AM
Is running through the hackerrank problems worthwhile?
 
@RobertGrant I hope for your sake you haven't just offended Martijn :p
 
@Withnail I've found the Python ones helpful, just introduces things I haven't come across before
The algorithms one I've stopped for a bit until I'm cleverer
 
@IntrepidBrit oh, thanks. First I waited to see if there are major complaints/huge errors in the answer. Then I waited for the bounty to wear off. Now I still have a few edits to do when I have the time (based on the commenters, for which some research is needed; and based on feedback from Bhargav Rao).
I guess I could accept before doing those edits, especially since I don't know when I'll have the time to clean it all up
 
Fair enough. I figured there would be a reason for it ^^
 
just to avoid dragging people in, thinking it's unanswered
so thanks for the reminder:)
fortunately accepts don't bump posts
 
11:53 AM
You're welcome
 
12:05 PM
@RobertGrant 77 characters
python3
ah sorry missed the even odd, that's going to add some :P
91
 
12:25 PM
@AnttiHaapala :O Mine is 121
@RobertGrant Okay, we both had almost the same solutions :D
@AnttiHaapala Very clever :-)
 
@RobertGrant That's rather tricky. I can do it in 101 chars, in Python 3.
 
@thefourtheye can you see my solution?
 
Prohibiting join and for makes re-joining a bit messy. I originally used reduce, but then I figured out how to do it with map. But I'd like to see Antti's 91 char solution.
 
@AnttiHaapala Yes. These are practice problems. Once you solve the problem yourself, you can see others' solutions.
 
12:40 PM
gtg. rbrb.
 
@AnttiHaapala “Access Denied”
 
it's a trick, you just need to hack it
 
82
my new case is not showing because it didn't result in a greater score
but it uses '...'.find(x)//5
 
12:55 PM
Sorry. My solution is actually 107 chars; I didn't notice I had to read from stdin.
 

« first day (2088 days earlier)      last day (2864 days later) »