« first day (2335 days earlier)      last day (2605 days later) » 

12:00 AM
33 mins ago, by anu
ok got it
:P
 
Count your blessings that people can't be thrown to the knives....yet.
 
wim
12:18 AM
I have a list of data, and a list of indices
>>> L
['p', 'o', 'X', 't', 'X', 'a', 't', 'X', 'o']
>>> idx
[2, 4, 7]
what's the most pythonic way to delete the elements at indices, in place?
 
del backwards?
 
wim
that's what I had, too, but it doesn't handle negative indices nicely (you'll to pre-process the list)
 
hmm
why not shift negative indices by len(L)?
 
wim
you can
but it's not exactly pythonic
you can't just mod, because indexes < -len(L) should raise exception
 
maybe deleting stuff from the middle of your list isn't pythonic either :P
 
wim
12:28 AM
well, it's an issue that came up in real code
not a hypothetical question
the contract of os.walk requires you to process the list of directories in-place
 
I know, but you might be too philosophical about it
in this scenario, having negative indices is unintuitive to me
new_idx = [ix if ix>=0 else ix+len(L) for ix in idx] # pythonic AF
 
wim
right, but it's better to code defensively
doesn't handle large negative indices
they need to raise exception
it's quite tricky, you see!
 
Why the hell would you have large negative indices? Is a chimpanzee calling your method?
 
wim
defensive programming
 
defensive against the nazis?
 
wim
12:32 AM
forget it
you obviously don't have the same ideas about code quality as I do
 
No, I don't have the same ideas about users as you do:D
your application (as in: deleting stuff from os.walk via indices) didn't exactly sound like a textbox put on a website where Joe can write unicode emoticons if he wishes
no offense meant to any Joes
Yes, I think you have to preprocess your index list.
there are multiple pythonic ways to do the filtering itself once you have a suitable index list
 
anu
12:50 AM
guys, how do i pass a private instance variable to a method ?
 
What's a private instance variable?
 
anu
class Foo:
	__bar = 1 # private instance variable
 
that might actually be a class attribute
 
anu
i need to pass __bar by default if no argument is passed to class method
@AndrasDeak yeah, that's true
lets go with class attribute and class method
 
wim
L = list('poXXtXatXo')
indices = [2, 3, 2, 8, -5]

for idx in sorted({(i%len(L)) if (-len(L) <= i < len(L)) else L[i] for i in indices}, reverse=True):
    del L[idx]
 
12:54 AM
>>> class Foo:
...     __bar = 1
...     def meth(self,bar=__bar):
...         print(bar)
...
>>> Foo().meth()
1
like this? ^
 
wim
gosh, so ugly.
 
@wim I'd write a function for handling indices, map that over idx, and use that to loop over for deleting the elements
 
wim
it's nicer in the stack trace if the IndexError is raised from the list object itself, rather than from some random internal function
 
oh, you're using L[i] to throw an error
 
wim
Yeah
 
12:57 AM
guess that works too
 
wim
I don't consider this pythonic at all, but it has the necessary behaviour
 
yeah, it's really ugly
 
What is pythonic
 
anu
 
@idjaw using a function to filter the indices
 
wim
12:58 AM
I don't know, but I know it when I see it :P
 
funky oneliner is definitely not pythonic
 
wim
def multi_del(L, indices):
    idx = set()
    for i in indices:
        L[i]  # raise if necessary
        idx.add(i % len(L))
    for i in sorted(idx, reverse=True):
        del L[i]
 
Readability counts.
Beautiful is better than ugly.
 
wim
equivalent. probably more pythonic.
 
anu
node=None
self.__root=<BinaryTree.BinaryTreeNode instance at 0x100a77248>
self.__root.getData()=1
for
	def find_max_element(self,node=__root):
		print "node="+str(node)
		print "self.__root="+str(self.__root)
		print "self.__root.getData()="+str(self.__root.getData())
 
1:00 AM
@wim def multi_del I would say is Pythonic
readable
if Pythonic is, I look at this code, understand it, would be OK working with it if I inherited that code and it is easily testable
 
if node == None or node.getData() == None:
@anu we typically test for None-ness using is, since it's a singleton
 
anu
oh ok
 
I have no idea what's going on in your pastebin but I have to go to sleep soon anyway
node=None
self.__root<BinaryTree.BinaryTreeNode instance at 0x107284248>
 
@wim @AndrasDeak Your earlier convo reminded me of something I saw earlier today: reddit.com/r/gifs/comments/5y0kd6/users_as_seen_by_engineers
 
@anu the above that suggests that __root and self.__root are very different
 
wim
1:04 AM
@MarcusS hahaa, good one!!
 
the class attribute is None, while the instance attribute is not None, but you're passing the class attribute to your method by default
@MarcusS :D
 
anu
so how do i pass the instance attribute
?
@AndrasDeak
 
you don't, you just refer to self.__root like you did
the bound method already has access to self so you're fine
you only have to check whether the default parameter should be used
 
anu
hmm ... the problem is that i am making recursive call to the same method with the node variable changing. and my base case uses "None"
 
so set a sentinel default value
 
anu
1:08 AM
what's that ?
 
what usually None is:P
        DEFVAL = object()
	def find_max_element(self,node=DEFVAL):
                if node is DEFVAL:
                    node = self.__root
or something like that
 
anu
yeah, that can work
 
I've never actually used this, and as I hinted at, it's really late here so I might be making even less sense than usual
 
anu
no it should work, i needed another placeholder object anyways
object() should do just fine actually
 
Cabbage. Your code's fine, Andras.
 
anu
1:11 AM
i don't see why it should not ... so far.
thanks @AndrasDeak
 
@PM2Ring cbg, thanks:)
 
@anu I haven't had a close look at your code, but I noticed a few strange things. Why do you think you need those double underscore attributes?
In the first code you posted you use list as a function argument. Don't do that - it shadows the built-in list type. And some of your stuff makes me wonder if you understand the difference between class attributes and instance attributes.
 
anu
huh ...
let me check
 
I also notice that you're using Python 2. If you have a choice, you should be using Python 3 - Python 2 reaches its End Of Life in 2020.
 
anu
oh.
i guess you're right .. i don't need the class attributes. i am only working with instance attributes anyways
i didn't not realize that there is a difference till @AndrasDeak pointed it out
 
1:27 AM
and if you're using python2, then class Foo: will give you an old-style class, which is even worse than regular python 2:P
 
It's fine to use class attributes to store default values. It's probably a good idea to read up about class attributes though - how they work and when they are generally used.
 
anu
ok
 
I think I'll give up on solving my weird bug and call it a day:/
rhubarb
 
1:57 AM
Cabbage :-)
 
 
4 hours later…
5:39 AM
Cbg
Since Rails 3.1, a JavaScript runtime has been needed for development on Ubuntu Linux. The JavaScript runtime is required to compile code for the Rails asset pipeline. For development on Ubuntu Linux it is best to install the Node.js server-side JavaScript environment. - can that really be right!?
Seems nuts.
 
I am new to the chat room can i post code question here?
 
yes
That's the primary purpose of the chatroom :) cbg!
 
@DavidHollenbeck welcome David :-) Please check out the room rules
 
5:57 AM
cbg @DavidHollenbeck
@AndrasDeak c bug?
 
happy women's day !
 
@tilaprimera cbg, hwd.
 
cbg
 
6:14 AM
cbg
 
6:27 AM
Cabbage
@AnttiHaapala What about that upvoted answer?
 
useless
it is just a comment
 
Will it interfere with deletion?
 
no
it will be gone in 3 delvs
I don't think the author minds :d
 
@AnttiHaapala Probably not, since they already tried self-vandalizing. :)
 
I mean the answer author
 
6:32 AM
Yeah. I got that a second after I posted. :)
 
7:52 AM
hourglass = [1, 1, 1, 0, 1, 0, 1, 1, 1]
sum(hourglass) doesn't work
what?
sum(i for i in hourglass) doesn't work either
 
>>> hourglass = [1, 1, 1, 0, 1, 0, 1, 1, 1]
>>> sum(hourglass)
7
>>> sum(i for i in hourglass)
7
 
yeah that doesn't work
 
Works for me?
What's your python version?
 
Take a look at the screenshot
python 3
Full code:
arr = []
for arr_i in range(6):
arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
arr.append(arr_t)

lst = sum = []
j,k,l = 0,1,2
for line in arr:
for i in range(4):
lst.append([line[j+i],line[k+i],line[l+i]])

# hourglass = lst[i] + lst[i+4] + lst[i+4+4]

for i in range(16):
hourglass = lst[i] + lst[i+4] + lst[i+4+4]
print(hourglass)
sum(hourglass)
print(hourglass)
error at the second last line:
TypeError: 'list' object is not callable
 
ctrl-k
And this: lst = sum = [] is your problem
 
7:56 AM
ah i see, I made a list that has the name sum
It works now :/
 
Classic "never use keywords in your naming" :)
 
@SebastianNielsen Yes. Be careful not to clobber the names of Python built-ins! As you have discovered, when you try to use the built-in that you replaced with some other object you get a cryptic error message. :)
 
Learn to think about the errors that you get. Here you were told that the list object that was bound to the variable sum is not callable. Which means that you shadowed a builtin.
 
@AshishNitinPatil Strictly speaking, sum isn't a keyword, it's just the name of a function in the builtin module. The builtin names aren't given special protection so you can rebind them to different objects if you want to. Sometimes that's useful, but mostly it leads to chaos and confusion. OTOH, if you try to use actual keywords like for, else, in as variable names you'll get a SyntaxError.
 
@PM2Ring Ah, yes. Was pondering over the correct nomenclature before commenting.
 
8:03 AM
@SebastianNielsen I bet you thought that error message was talking about the hourglass list, but it was actually talking about the sum list.
 
insomnia cbg
 
Should I flag a question if I am the first one to do so, or should I use a close vote instead?
@MarcusS re-cbg
 
@AshishNitinPatil If you believe that the question should be flagged, then flag it. However, two of the flags are used to indicate that the question should be closed - that's for people who don't have enough rep to close vote, so you shouldn't use those flags, just close vote.
 
@PM2Ring Good to know, thanks!
 
Flags require personal attention by diamond mods. They get a lot of flags to deal with, so it's better if the community can handle stuff by simple close voting. OTOH, flags should be used when necessary. Especially if you see abusive posts or actual spam (i.e. questions that aren't real questions, just an attempt to promote a commercial service on SO) you should flag them and don't close vote them.
 
8:19 AM
Yep, basically, when urgent policing required, flag, else cv.
 
That's it.
 
@PM2Ring actually you can closevote them too
 
@AnttiHaapala IIRC, the consensus on Meta is to not CV spam. Why bother wasting a close vote? But I Could Be Wrong. :)
 
plenty of cv votes
the thing about cv is that it goes to cv queue too so more people might see it :D
"The people who vote to close are likely not using their spam flags, so it takes longer to delete"
 
@AshishNitinPatil If a close-worthy question is attracting answers you may wish to post a cv-pls request here. Read here for details on our policy. Also, there are usually one or more gold badge holders here who are happy to hammer dupes if you find a good dupe target.
 
8:26 AM
22
A: Do I flag a question as spam, or vote to close it as spam?

BoltClockFlag it as spam. It's the very first option you see in the flag dialog. It is a special option that will not only cause a question to be automatically deleted when enough flags accumulate, but also train the anti-spam system to block future attempts. Close votes do not have this effect. If you s...

@PM2Ring there, pretty explicitly
> Once you've flagged the question as spam, you can vote to close it to ensure that it remains closed if it turns out not to be spam, but if you're confident that the post is spam then you're really just wasting a close vote there.
 
Ok. So we're both right. ;)
 
but "wasting a close vote"
when did you run out of close votes the last time?!
 
@AnttiHaapala There are days when it might happen if one is too active :)
 
cbg
 
@AnttiHaapala Well, not since I was busy on SOCVR, but that was a while ago.
 
9:02 AM
I've just been browsing the the CPython setobject.c source. I was hoping to learn if it always converts non-set method args to sets, or if it can iterate directly over the items in some cases, but I got lost. :)
 
have talked about CIA being able to get the Signal/whatsapp/whatever message before encryption?
 
CIA recommends the use of Python 3 / Writing python 3 compatible code / not relying on CPython as the implementation
 
we already knew they had smart employees
 
you don't call them an intelligence agency for nothing!!
 
9:06 AM
:D
 
though that shit is ripped from google python guide
 
other news: I am doing prolog, wish me luck
 
We do not need to wish you luck
you just program the terminals and rules and prolog will deduce luck for you
 
hopefully
 
@khajvah That sort of stuff is only viable if you're using closed-source programs. It'd be pretty hard to hard BS like that in a program that's open source.
 
9:09 AM
@PM2Ring they exploit the OS
Signal is open source
 
they can use agents to influence some decisions... like use of "alternative" cryptographic algorithms etc
 
this kind of shit makes me want to throw away my smartphone
 
@khajvah I use an open source OS, don't you? ;)
 
yeah yeah
well, at home I do
at work I use Macos
 
9:28 AM
"AirHopper, a malware for data exfiltration out of air-gapped and non-networked computers, i.e. computers/networks that are not connected to the internet because they store extremely high risk data. Turns out if you can get a user-level program into the non-networked computer, and get malware onto a regular cellphone in the same room as the target computer, it becomes possible to exfiltrate data.
The researchers showed that it is possible to use the DRAM bus as a GSM transmitter that can talk to the phone. If the user-level program just makes memory accesses at 900 million times a second, electricity will flow through memory bus at 900Mhz, and the bus is just a metal stick (i.e. an antenna), so this creates a 900Mhz signal (the GSM frequency) and this signal can be picked up by any GSM receiver such as the one in your phone."
hmmm lol
yea
picked by GSM receiver, but try to make sense of it
 
yeah I don't think this is practical
 
but a phone could be used as a receiver... but not like it would be really feasible to turn any phone into a receiver.
 
@AnttiHaapala Ooh, SO got it's own meta site. Didn't see that.
 
@AshishNitinPatil wat?!
this is the meta.
the stack exchange network got its own meta after so meta was split into 2
 
Could someone help me optimize my code. I am getting timeout on test case 7 and above, this is the task: hackerrank.com/challenges/crush
    Here is my code:
n, m = [int(i) for i in input().split(' ')] # n = list size;  m = operations to perform on the list
    lst = [0 for i in range(n)]

    for line in range(m):
        j,k, value = [int(i) for i in input().split()]
    for i in range(j-1, k):
            lst[i] += value

    print(max(lst))
 
9:42 AM
@AnttiHaapala Yeah, my bad. I meant SE not SO.
 
@SebastianNielsen why use split(' ') instead of split()
 
I don't know I know it's the same :P
 
it is not the same.
 
It's not?
 
it is not
split() splits by arbitrary whitespace
 
9:45 AM
What is the difference then? I know they both split a string up by ' '
 
And I would use map(int, input().split()), but don't know which one is faster.
 
well, now I know that :)
 
>>> '1 2 3 4          5 6    7'.split(' ')
['1', '2', '3', '4', '', '', '', '', '', '', '', '', '', '5', '6', '', '', '', '7']
>>> '1 2 3 4          5 6    7'.split()
['1', '2', '3', '4', '5', '6', '7']
 
But apart from that, do you see any other part that could be optimized? It's a so simple code, I don't see why I could get timeout.
 
I am not even sure if your code is properly indented
 
9:47 AM
It is @an
 
Any good IDEs for Ubuntu (if you are using one)? I use SublimeText and am fine with it since I switch to the terminal whenever necessary.
 
Hey a little off topic but are you familiar with metasploit @AshishNitinPatil
 
@SebastianNielsen Yes, a little, but is completely off topic if that is your question :)
 
@AshishNitinPatil pycharm
it is not good but it is ok. and it is an ide.
the community edition is free and good for programming python
for serious appdev one needs the paid pro .
 
Yeah, I tried it, will give it a retry. Didn't like it in the first go.
 
9:52 AM
Well, what do you know about getting saved passwords from your victims pc in a backdoor session?
I have tried to approach it in a lot of different ways without luck unfortunately.
 
rbrb, lunch
@SebastianNielsen It is off-topic.
Unless you are programmatically doing it with Python :)
 
Cabbage!
 
No, that's not the case.
CABBAGE @poke
 
 
2 hours later…
11:26 AM
@randomhopeful we have local elections in Finland next month, one of the guys from Punk Syndrome is now running for the seat of city councillor in the elections :D
 
user4371848
hey anyone know how to write tic tac toe AI with python?
 
user4371848
is that only minimax algorithm ?
 
You could probably hardcode the AI decisions for all possible combinations…
(at least after eliminating equivalent cases and rotation)
 
11:54 AM
@AminSamani here a pessimistic simplistic algorithm
print("It's a tie")
 
it's a tie
NO WAIT
phew, I thought I wouldn't be productive today
 
user4371848
Oo so what is your algorithm ?
 
oh BTW @Antti when I was talking about a bug earlier, it was a fortran one, but really a semantic one (two versions of code should give the same result but don't)
I haven't had time to look for it again today
 
I am somewhat disappointed. I googled for it's a tie.
and there was not a single tie fighter meme among the results
 
:(
time to start one
smol puppers, apparently
 
12:27 PM
cbg("all")
 
12:47 PM
"all"
 
1:04 PM
@AnttiHaapala repr?
Also, your new avatar confuses me
 
why???
 
because it’s different
 
is it possible to somehow run a function whenever a new class is being defined like I tried here:
I just get an error: load isn't defined.
 
self.load()
 
Uh, I thought: self.load() = load(self)
apperently not then.
 
1:14 PM
Yes, iff load is a valid reference to an unbound method. But in your case, the local name load does not exist
 
ahh, thanks :)
 
1:58 PM
view from the office here
 
2:09 PM
What is your job title Wayne?
 
Senior Landscape Gazer
 
He's Batman. That view is from atop one of the many gargoyles that festoon the high rises of Gotham city.
 
Noice
Sure he's not one of the gargoyles?
:D
 
A gargoyle would not be able to take a picture using the BatCamera they keep in their utility belt.
 
@WayneWerner nice
 
2:15 PM
Anyone else on Google Earth trying to work out what building he's in? Just me? shuffles out
 
Oh, wait. That's not France.
 
\o sunny nice cbg morning :D
 
creeping: complete.
 
I'm curious in an academic way about whether you could triangulate his position given the position of the buildings visible here
Or would you need additional information not given, like, idk, the FOV of the lens
 
you can definitely take a solid guess because you can use the height of freedom tower.
 
2:23 PM
I think you should be able to calculate his position...
lens warp the image to a degree just need to factor those in
 
consider the hypothetical city layout
A B
 C
 D
 E
 
if you know what the two buildings in front are, you can do it super easily
 
If wayne shares a photo that contains A and B side-by-side, we don't know just from that whether he's in building C, D, or E.
Let's assume that C and D wouldn't be in a photo taken from E because of differing heights.
 
do you also assume the degree of angle when taking a picture of different heights at the same object? I feel like you would have to factor those in...
 
Certainly we could make an educated guess and be right to an accuracy of a quarter of a city block, or whatever... But this is unsatisfying to me.
 
2:26 PM
I feel like you should almost be able to, at the very least, locate the building hes in with the picture he provided
whether it's room 202 or 203 might take a bit more skill and math
 
So it's 110 metres from the right edge of the tower in the centre of the picture to the edge of the building on the bottom right, parallel with the shore
Interesting question comes out of this creeping - can you use the 3d maps on google API to pull building heights?
cause if so then you've got height of that tower, height of freedom tower, and angle betwixt...
And why yes, yes it is quite a slow day in the office, why do you ask?
 
@Kevin You could probably use the background compression to make a good guess about the focal length which will then help you figure out the distance from those objects
 
<3 room6
how you all doing
 
cabbage @idjaw
 
\o cbg bud. did you catch the game last night ?
 
2:32 PM
o/
 
nope. I played hockey last night
 
Just in case you're worried @Wayne, if I do end up calculating your position within an accuracy of half a meter, I won't publicly share it, and I'll probably forget about it within half an hour.
In accordance with the customs of our tribe, for it is written, "be nice", and that includes not accidentally doxxing someone while in the throes of an applied geometry frenzy
 
@idjaw did you win ?
 
nope. Lost 4 - 1
I assisted the one goal though :P hehe
 
Islanders vs Oilers basically :D ? (last night)
 
2:35 PM
@Kevin You would only doxx WayneCorpOfficeRoom though
 
oh man
 
Corporations are also people, and so if we're going Turtles All The Way Down, office rooms must therefore be people too. So even that would be impolite.
 
google3d lets you get pretty into this
coughs
I should probably do some work
 
I can kick you out of chat if you like...you know...to motivate you
 
Nawh.
I've reopened my terminal
look, i'm working
 
2:40 PM
Withnail kicked out for 3 hours -> GET TO WORK
 
hey, hey, GMT dude
 
oh I found a place that sells banh-mi near my office. But the down side: it's a standard grocery store version :(
 
@Withnail ha! corrected.....3 hours
 
it's fine, I'm back into the dull world of event attendee registration
 
I'm in the fine fine world of writing black box tests to understand how this mystery application works, so I know how I have to write the new API calls I have to introduce
it's not fun...because Django.
 

« first day (2335 days earlier)      last day (2605 days later) »