« first day (2259 days earlier)   

12:00 AM
I've just used my powers for good D:
(wrote a gimp script in python for the missus)
one of the "built-in" scripts shadow type with a local variable...
 
12:12 AM
I have the following script that verify an ip address.
    import re

    ip = "10.87.89.12"
    validated_ip = re.match(
         r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(["
         r"0-9]|[1-9][0-9]|1[0-9]{2}"
         r"|2[0-4][0-9]|25[0-5])$", ip)

    print validated_ip.group()
 
okay
ctrl+k will code-format multiline
don't worry about the extra whitespace, it's manageable:P
suggestion: use python 3
 
Would do that
I want to see if anybody can explain me the logic. I know some of the regexes. Like individually but not has a whole.
 
it seems you forgot to ask the question
but now I assume it is "how does this work?"
 
Like I [0-9]| <-- match 0 ... 9 and or
 
"I have the following script" sounded as if you'd written it
the thing with regex is that it's mostly a write-only language
 
12:16 AM
from ipaddress import ip_address
ip_address('10.87.89.12')
 
it's very hard for other people to read it, and "other people" includes the author in 2 months
I think that's a pretty shitty regex btw
 
great to know
@davidism is that included within python
 
I mean, it shouldn't be too hard to come up with a regex term for "integer between 0 and 255", and modify it slightly for the first one because that shouldn't start with 0, I guess
well, maybe my picture of ipv4 IP addresses is what's off, dunno
@davidism too bad it doesn't handle the BunnyNetwork addresses
 
Yeah, I was disappointed too.
 
12:20 AM
@davidism this is great. Thanks
 
There's also netaddr, which has some extended behaviors, but generally you can stick with the built-in one.
 
wim
I use the subnets space in netaddr
didn't know there was a core lib thing for that...
oh, new in version 3.3 :(
the app I needed it in is on 2.7
 
It is great that they thought about ip. I think is because they see that a lot engineers are using python for automation which is my case.
 
And because if you throw a stone in a shrubbery, three core libraries pop out.
see also "batteries included"
 
12:43 AM
cabbage
 
cbg
 
Anyone interested in nuking some spam answer in stackoverflow.com/questions/41274028?
 
that's rude/abusive, not spam
but flagged anyway
(it's a chronic "troll" of the site, doesn't really give up)
 
ok, I'll flag it correctly next time. To bad that posts containing "sex" 100 times don't get blocked by default.
 
meh, the guys in SOCVR usually jump on garbage like this
I guess chat's less active with the holidays nearing:)
Hmm, the flagging popup warns you if your last flag was declined, and asks that you check it out. Nice.
nevermind
 
12:50 AM
that was so close :D
 
I don't think it was a coincidence:P
 
it says it was deleted by community. :)
 
if a mod pops a spam flag on the post, it gets nuked by community, I think
 
fortunatly the funny comments are sill visible
 
that way the spam filters get well-fed
Just don't mention that user by name in chat, ever. They are reading the transcripts.
 
12:53 AM
alright. Now you got me worried. :)
 
nothing serious, we just wouldn't want them to feel any attention
flag/nuke and move on:)
 
1:47 AM
good night
 
DSM
Rhubarb for @AndrasDeak!
 
passes baton to DSM
rhubarb:)
 
2:10 AM
ring ring ring ring ring ring ring winterbash phone
 
DSM
Heh. Cute.
 
DSM has the spork!
 
DSM
I am sporkful.
 
 
2 hours later…
3:54 AM
Question: i am trying to find out how to have distinct numbers, example: given 4, 6 ,6 ,6 how would i make it so i have 4,6,8,10?? given a random list of numbers?
 
how are you generating these numbers, how are you trying to store these numbers?
what have you tried?
 
lets assume the numbers are generated randomly unsorted
i have a number lets say n, we want to % each number so that its == 0
but each number has to be distinct in the list, so if you have duplicates, you need to increase it to a multiple of n
 
so, if you generate numbers 4, 6, 8, 6
what should the final structure look like
 
assuming n = 2
4, 6, 8, 10
 
why 10
 
4:08 AM
with results being 2 , 3, 4, 5
because each number must be distinct
 
this doesn't make any sense to me, sorry.
 
its cool, dont stress it
 
I'm just not following the logic you are trying to do. However, if you are looking for a structure that doesn't allow duplicates, look at sets. But sets do not preserve order.
@Nightmare ^^
 
i need to take into account the duplicates, so i cant use a set because it will remove all duplicates
 
let's see if I get this....
numbers being generated are:
2, 55, 22, 4, 2, 10

n = 2
so, 2, 22, 4, 2, 10 would be kept since % 2 of those numbers equals 0. However, you have a duplicate 2 there
so, that second 2 "goes away", but you need to still preserve the total length of the data
right?
 
4:20 AM
nah lol
 
OK. I'm done. 😀 good luck
 
its cool
thanks for the attempt, my fault for lack of description, but ill solve it sooner or later
 
good luck! If you manage to work out more of it and get stuck somewhere, show the snippet of code you're working on and what's going on.
Don't know how much long I'm on for....and it's pretty dead here for the next few hours.
 
thing is that i solved a harder problem and i cant solve this easy question lol
 
are the numbers generated as a multiple of n already?
randomly?
 
4:24 AM
okay lets say i wanted to by n outfits
and im willing to pay a minumum of 4, 20, 152
so i have 3 outfits i want, but each outfit let say cost 2$
that means for the first group of outfits i can buy 2
the second group i can purchase 10
and the last group i can purchase 76 outfits
but lets say i want to buy 2 groups of outfits, and ill pay minumum of 4 and 4 each
but these numbers must be distinct
so i increase one of the 4 to a 6
now i have 4.6 as minimum costs
saying i can buy 2 outfits for the first group and 3 for the second group
 
4:46 AM
?
 
@Nightmare sorry. I'm falling asleep here, it's late. Maybe someone coming around might read this and has a more functional brain than me tonight 😀
 
DSM
♫ you've done enough ♫ take a deep breath ♫
 
@Nightmare Do the numbers all have to be even?
Sounds to me like: 1. Sort list. 2. For each repeated number, increase to the next multiple of n
 
^^ yeah
that
that's why you're wearing the superman hat.
 
4:51 AM
Anyone see Assassin's Creed today?
 
nope
I need a fellow nerd's review
what's your review?
 
If you are into the games, you should see it.
I liked it.
 
great
 
Special effects are really good. The plot is okay.
very much like the game in a movie.
every city is parkour-friendly
 
naturally :P
 
4:53 AM
both modern and historical
 
@Nightmare Are you saying the following: Given positive integer n, and given a list of integers [a_0, a_1, a_2, ..., a_k], find [a_0 + m_0*n, a_1 + m_1*n, a_2 + m_2*n, ..., a_k +m_k * n] such that all values are distinct and the sum of the list is minimized?
 
for a0 find m0 such that (m0-1)*n < a0 <= m0*n, then the first element is m0*n
repeat for a1, but with the additional criteria that m1*n > m0*n (assuming the a's are sorted)
 
I sense a math-off about to happen
getting my popcorn.
 
seems more logic than "math" although as far as I am concerned, math is more about logic than numbers anyway.
 
AoC is almost live
almost forgot
 
4:57 AM
hmmm...not sure if I'm gonna do it tonight
 
come on. You're already here
:)
 
DSM
Yep. And since I'm in front of a terminal I might actually give it a go tonight instead of waiting until tomorrow. :-)
 
I'm looking at cryptopals atm.
at least I was planning to get back to it until I started chatting here.
 
I'm wrapping presents and listening to Genesis
 
Bible on CD?
In the beginning....(in a Morgan Freeman voice)
 
DSM
4:59 AM
While seasonally appropriate, I think he means Phil Collins & co. :-)
 
hehe
yeah. Calling All Stations.
I think I'm in the smaller group of people who liked that album.
I really liked it a lot
 
smaller than what? The other group that liked it?
 
I don't think it was received as well as other genesis albums
unless I'm mistaken
 
DSM
Went down a wrong direction in part 2 so there's no way I'm going to score, but at least my skills haven't entirely rotted:
5) Dec 22 00:04:34 DSM
 
sick!
WTG DSM
 
DSM
5:14 AM
@idjaw: last year was much better, but every year it takes a little longer to get the brain in gear. :-)
 
nice
 
DSM
Anyway, I think I'm going to let part 2 bubble overnight in my brain. Evening rhubarb for all!
 
rbrb dsm
 
now talk about unevennes
 
What is the opposite term for "Lazy Evaluation"?
 
5:21 AM
spent all my time getting parsing right for part2 and the part2...
normal evaluation :? :D
eager? :D
immediate?
 
:D
And which one is more Pythonic :D
From wiki: "The opposite of lazy evaluation is eager evaluation, sometimes known as strict evaluation. Eager evaluation is the evaluation strategy employed in most programming languages."
 
5:37 AM
cbg
I just logged in and got 3 hats. Total hat count is 12 now :P
 
TypeError: unhashable type: 'dict'
 
5:54 AM
do you guys think this is really deserving of downvotes and a cv? stackoverflow.com/questions/41276489/…
seems pretty clear what they are asking, is a legitimate question, and if you are not comfortable with the language, can be hard to figure out at first.
Seems like a reasonable thing to ask...
 
@MohammadYusufGhazi lazy/eager evaluation of what?
 
wim
@DSM nice, congrats
 
@idjaw isn't the question basically "why is x - 1 is less than x by one"?
 
6:12 AM
I am stoopid
my algo works for the example input...
but it is stuck elsewhere on the board for the damn actual input and doesn't seem to get anywhere from there :D
just moving bytes around
 
Does anyone have experience with database structure for a client who wants a form that he can change the questions on, but all the past form submissions still contain their original questions (and question order)
 
Cabbage :-)
 
@MarcusS I thought about that but I don't know how to solve it either :D
 
@AnttiHaapala view spoiler
 
6:21 AM
I am using it :D
@MarcusS need better h(x)
 
@AnttiHaapala view spoiler
 
?
 
6:25 AM
Hm, if it's just moving stuff around then I imagine something is wrong with the visited/frontier set?
(i.e. getting caught in cycles?)
 
@MarcusS @RobertGrant @AnttiHaapala view spoiler
 
yeah it is definitely getting caught in cycles, reordering the stuff in the other corner :D
@thefourtheye aoc
aaargh just noticed
 
Oh... Okay then :-)
 
wim
6:41 AM
I'm off.. goodnight all
 
night
 
lol I went to reddit
 
What will be the ideal way to load the module and unload it? Compatible for both Python 2.x and 3.x. I want to load the module on demand basis as it uses too much memory
 
do you mean module = reload(module)?
 
def do_someaction():
load module
my_action()
unload module
It should be loaded within the function and won't remain in cache once function execution is over
 
@MoinuddinQuadri there is no way of unloading a module.
you can delete all references to it that you can find... but it is not guaranteed to free any memory either
 
@MarcusS: Yes, kind of. But more elegant. But the link you forwarded is helpful though
@AnttiHaapala: Like this`del sys.modules['module']`? Is there a way to make sure memory is released?
 
no, and the link marcus shared doesn't work.
all modules are cached in sys.modules, that's the one place to start
but then you need to drop all references to stuff within that module
 
meaning you cannot have functions, instances of classes or so, imported into any other place...
or contained anywhere,
no function calls, no held generators etc etc.
 
7:03 AM
In all honesty I wouldn't bother trying to "unload" a module
Just load the thing and use it
 
@AnttiHaapala I do not want to use the references anywhere else. It is been just used at one place for the internationalization of URLs and since most of the URLs do not need internationalization. I think dropping the module will work.
 
I'm wondering if I can get some insights into a Pickle module issue I'm having. I'm trying to save the state of a class {World}. And this class has a dict attribute called {Rooms}. Insight this dict attribute I have instantiated class objects. But when pickle.dump(...) gets to saving one of these dict items, it can't find it associated with the top-most {World} class, and I get the error: Can't pickle <class 'world.StartingRoom'>: attribute lookup StartingRoom on world failed
 
@sadmicrowave the classes need to be defined at the top level of their modules
 
so, in this case, the reference to "StartingRoom" looks like this:

world._world = {(2, 1): <world.StartingRoom object at 0x1036a72b0>}

The dict key is important because it specifies the world location for this particular room. What other way could I instantiate "StartingRoom" so that I can still access it within the World class by it's x/y access coordinates (2,1)?
 
7:25 AM
@AnttiHaapala view spoiler
 
7:51 AM
Cabbage
@user2357112 Sorry, I couldn't hammer it since it didn't have the tag...
 
cbg o/
 
how do I setUp a test package with pytest?
with nosetests, I would put setup_package() in __init__.py
 
8:19 AM
cbg'ning
 
8:44 AM
cbg
 
@PM2Ring Done!
 
Ta
 
can someone help me with a nim problem?
say 2 plays are playing nim, and there are piles 2,3,4 and they can remove more than 1 from each pile, who will win ?
 
@Nightmare Have your read the Wikipedia article?
 
i have not sir
 
8:55 AM
You should do so. It's very good.
 
depends on what version: who's the winner? the person who takes the last stone?
 
yea marcus
 
cbg, all
 
@Wayne Werner print the input and output in your answer then — nik 10 hours ago
wat.
 
they can remove 1 or more from each pile
 
9:00 AM
@MoinuddinQuadri your mission smacks of premature optimisation: what's the reason for this obsession?
 
@Nightmare the nim-sum of the state is just the xor of the values
If you have piles [a1, a2, a3], the nim-sum is a1 xor a2 xor a3
If it's 0, the current player can win
 
oh ok thanks
 
So [2, 3, 4] is a losing position since it's nim-sum is 5
 
gotcha
 
(sorry, it's late, I have that backwards -- nim-sum of 0 means it's a losing position)
For instance [0, 0, 5] is winning (nim-sum of 5) and the winning move is to just take the whole pile and leave the opponent with [0, 0, 0] (nim-sum 0)
 
9:05 AM
yeah i figured lol
 
9:19 AM
what if any player can skip their turn on a pile?
who it be xor summation and the number of piles ?
 
Indefinitely?
 
if they can skip 1 pile after they skip noone can skip that pile?
like there is a skip on each pile, and once someone uses it, it can no longer be used from that pile
its tricky lol
i was thinking if there were even number in each piles and even number of piles the original winner would lose
 
I don't know what you mean by "skip that pile." If the position is losing, it doesn't matter which pile you pick -- anything you do will give the opponent a winning position. Skipping one pile vs. another won't make any difference
Unless you mean like [1, 0, 1] and skips exist on both piles, and the player can use all the skips at once and force the entire position on the opponent
 
like say you and i were playing
and there is 1 1, and the first pile has been skipped by you, and i skip on the second pile, then you remove 1 and i remove 1 i now win
nevermind -.- i dont know
 
Yes, by all means change the rules of the game. That's what politicians do ...
 
9:31 AM
not sure I follow -- I think you have to clarify exactly what you mean / what a skip allows you to do exactly / how many each player has / if they both share skips or maintain their own set / etc
 
say there are n piles
then there are n passes in the match
as long as the piles are not zero
so if a pile becomes zero, number of passes -= 1
but if the player is losing, he/she can use a pass to gain the advantage
 
So there is one "skip" associated with each pile, that is shared between both players? If player 1 uses the first pile's skip, the second player no longer has the ability to "skip" the first pile at any point in the future?
 
yes
 
So what is the function of the skip? Skip the entire turn?
 
skip the turn to force the other player to pick stones, or skip if available
i was thinking that the skips would be negated and the xor summation would work, but i lied to myself
 
9:39 AM
I mean, the idea of skipping turns means the game is no longer a combinatorial game in the traditional sense (the whole reason the xor operator works for these games in the first place is because it assumes the players are taking turns, and that from any winning position there exists at least one move to a losing position, and from any losing position, all moves lead to winning positions)
i.e. it becomes another kind of DP / memo type probem
 
:/
 
only reduces to a nim game if all skips have been used
 
so in the xor summation, we assume that all skips have been used
 
Yeah
 
so how can we take into account the skips? any idea
 
9:52 AM
DP
 
ugh >.<
i quit, later, thanks for the help btw
 
one sec
 
i was jk
an optimal move is one that leaves a multiple of 4,2,1
in the pile
 
from itertools import product

def nim_with_skips(old_state, cache = {}):
    key = tuple(old_state)
    if all(pile_size == 0 for pile_size, skip in old_state): #final loss state
        return False
    if key in cache:
        return cache[key]
    for pile_index in range(len(old_state)):
        pile_size, skip = old_state[pile_index]
        new_state = old_state[:]
        if skip > 0:
            new_state[pile_index] = (pile_size, 0) #use the skip
            do_we_win = (nim_with_skips(new_state) == False)
maybe something like this (to better see how skips vs non-skips influence the outcome)
 
o.O
 
10:02 AM
re-cbg
 
i think there is a pattern in the skips outputs
 
Eh I can't edit that post but I added a thing that shows when the nim_sum matches the actual outcome
 
its cool, really helpful
losing position if player 1 goes first right?
 
it's possible for player 1's turn to be either winning or losing depending on the situation
 
yeh
 
10:06 AM
why does psycopg2 return Decimal type instead of normal float?
 
Because it's psyco, bra! Watch out!
Yes, that's the best I can do in this heat
 
What's the specification of the database field that's being returned? I suspect it will be a fixed-point numeric field
 
another question, why isn't Decimal json serializable
damn man
@holdenweb yes
 
That is weird
 
@holdenweb There is one open source library on which I am contributing. One guy has opened a bug that whenever the newer version of library is imported it is consuming too much memory. He has 40 independent scripts, and each import is consuming around 15 MB. Due to 600 MB extra usage of memory, his system is getting crashed
 
10:11 AM
I have to write an ugly code to convert Decimal to float
and then serialize
 
@khajvah Why not just convert Decimal to string? That way it will always be reversible.
 
@PM2Ring or that
 
@Nightmare JSUK there is a light bug in the code above (add a continue if the pile size is 0, or remove the pile + skip from the state if it's 0 if you want to re-use the memo from smaller subproblems)
 
ohh ok thanks
 
@MoinuddinQuadri This means each of 40 processes has increased its memory usage? Or a single process that repeatedly reloads the same package/module?
@khajvah but using a float to represent a fixed-point number is likely to lead to inaccuracies. Will the application tolerate them?
If not, then you'd be better to use a correctly-formatted string representation
 
10:24 AM
FWIW, reduce(int.__xor__, piles) is a slightly better way to compute the Nim sum than the version on the Wikipedia page, since it avoids using a lambda.
 
If n = number of piles is even (i.e. n = 2k), skips won’t matter. Let’s say you’re in a losing position and you skip because pile 1 still has one available: I’ll just use pile 2’s skip. And then you on pile 3, me on pile 4, … , you on pile 2k-1, me on pile 2k. Now it’s back to your turn and it’s still a nim-sum = 0 scenario, so nothing changed.
 
@holdenweb true. Mine was an XY problem
I need to store Decimal and also datetime in Redis
both aren't json serializable
I can use pickle
pickle does the job. Not sure about the performance though, might have to test
 
@holdenweb Each of the 40 process increased the memory. Package is loaded only once in each process
 
OK, how significant is the delta between the satisfactory and unsatisfactory versions?
Does this issue only affect a single user?
 

« first day (2259 days earlier)