« first day (3166 days earlier)      last day (1776 days later) » 
02:00 - 16:0016:00 - 23:00

2:13 AM
cbg
@PM2Ring yeah
@PM2Ring I would do that next time
 
2:54 AM
@U9-Forward Somebody with some competence in tensorflow gave me a satisfactory answer, and it turns out to be more sensible than I thought it'd be
go figure
 
@cs95 Haha i just saw it right before you messaged me
 
 
4 hours later…
6:39 AM
rbrb
 
7:35 AM
cbg
 
7:46 AM
Hi, I have a question.
In Django. But django room is not activated.
 
9:44 AM
@MiladHatami django questions are on topic here
 
10:18 AM
>>> classmethod(3).__get__(None, str)
<bound method ? of <class 'str'>>
>>> classmethod(3).__get__(None, ...)
<bound method ? of Ellipsis>
>>> classmethod(3).__get__(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __get__(None, None) is invalid
That's what's invalid?! Really?!
 
10:36 AM
cbg for a bit
@Aran-Fey Wow i never knew i could do ...
 
It's very useful... it makes a lot of pseudo-code valid python :D
I'm still figuring this one out, but here's today's puzzle: Guess the output of this code...
class Foo:
    @classmethod
    class Bar:
        def __new__(*args):
            print(*args)

Foo.Bar(5)
 
Hmmm...
is it:
(5, ...)
Just guessing
@Aran-Fey Can i run it and see?
 
I don't want to spoil it, so... see for yourself
 
Ugh, i never could guess that
 
it's probably more obvious what is going on as __new__(cls, *args)
 
10:45 AM
@Aran-Fey I remember there was a link to some quizzes of outputs or something, but i seem to not find the link
 
Oh yes...
You can add this there.
 
Yeah, I will
 
@U9-Forward The ellipsis was added to Python back in Python 2 days. It was added for the benefit of Numpy, it doesn't do anything of significance in core Python.
 
Yeah
 
cabbage beautiful people
 
@JonClements I'd be happy to help with reviewing the job postings if you still need someone.
How to get in contact?
cbg @DeveshKumarSingh :)
 
11:14 AM
rbrb
 
Wow. 16GB for the source code of a program. opensource.stackexchange.com/questions/8421/… I think they need to do some refactoring. I guess the bulk of it is some kind of essential data, but still...
 
@Reblochon great thanks... I'm just having to do a few other bits before I get back to that but glad you're interested... will give you a ping later on when I've got the boring stuff outta the way :)
 
Sure, whenever you are ready @JonClements
 
 
1 hour later…
12:21 PM
Publicly embarrassed myself by bungling several pull requests in a row, lads
I really should figure out how git actually works, one of these days
 
@Kevin where's the fun in that? :p
 
There isn't any, which is why I haven't done it yet ;-)
I do remember a nice article that explained git by designing a hypothetical version control system from the ground up. Every time they added a feature, like "changing a single byte in a 10kb file should not require a 10kb addition to the history-tracking file", they would explain how that might be implemented, and show how git already has that feature
 
re-cabbage
 
I owe about half of my rudimentary understanding to that article. Too bad I got distracted before I could finish reading it.
 
12:35 PM
@Kevin have you played learngitbranching.js.org ?
It is fun ;)
Also you might remember tom.preston-werner.com/2009/05/19/the-git-parable.html which is less crucial
The game is what actually teaches you using git
 
@AndrasDeak That is indeed the article that I was thinking of in my previous message. Nice detective work :-)
 
> Git is a simple system
^ lies
 
@Kevin nah, these two links are my library of git
 
The question I am interested in answering today is "after I bungled my first PR because the branch I was working on was downstream of my local master branch that happened to be 3,000 commits out of date with the master fork, was it really necessary to create an entire new branch, or could I have somehow fixed the giant mess I made?"
 
Hmm, can't you just merge the master into your branch?
 
12:41 PM
either way you have to rebase onto master. Question is what branches you want to keep.
 
Quite possibly I could have fetched (pulled? rebased? merged? idk) those 3,000 commits from the master fork into my local master, and then fetched them from my local master to my bugfix branch, but I wasn't sure if this would have wrecked the file history if the project maintainer approved my PR
 
@Aran-Fey local rebase > merging master if you ask me
@Kevin you could've fetched remote master and work on that
 
did the 3000 commits touch the same code that you modified as well?
 
Really, the game will explain this, I strongly suggest that you play it :)
Takes an hour or two if you take your time
 
The more you enthusiastically recommend it - the more dubious I get... :p
 
12:43 PM
@MisterMiyagi I don't think so. The file I was working on was last changed nine months ago, so my local copy may have been up-to-date even when I was 3,000 commits behind.
 
then you can rebase/fast-forward without a problem breaking anything
 
I thought that might be the case, but I have a scorched-earth policy when I'm trying to contribute to a public project
 
The thing is it really is simple on a high level! Very easy to grasp. The actual API is a mess but that's a different matter.
 
@Aran-Fey git is simple.. but it's interface is complicated/counter intuitive/anti-user
^^kinda kevin'd
 
Independent verification :P
 
12:46 PM
Insert joke here about merge conflicts
 
If both I and an asspression-fan agree it has to be true
 
that's what it must feel like when both angel and devil on your shoulders agree about something
 
Insert reference to Good Omens here
 
I learned Git from Ry’s Git Tutorial. Unfortunately, the author decided to publish a book and took down the original website, but the material can be found here. Also unfortunately, I did that tutorial over 5 years ago and have barely used Git since then, so most of my Git knowledge has evaporated. :(
 
I'm sure you must all be tired of handling my git 101 quandaries by now, so I hereby commit (heh) to going through "Learn Git Branching" today, or else face relentless peer mockery
Get the Hat of Shame warmed up for me
 
1:00 PM
@Kevin \o/
You can thank us later ;)
 
1:16 PM
Currently learning how to detach HEADs. Yet another entry for the Problematic Terminology book, next to master-slave relationships and killing child threads
7
 
@Kevin you going all French revolution on your code? :p
 
Also disowning child processes
 
don't forget about reaping zombie children...
 
Hmm, don't know if I like the way git checkout can change the current branch or change which commit HEAD points to. Those seem like conceptually different tasks to me.
Or, hmm
 
@Kevin On a somewhat related note, Computers Don't Argue.
 
1:23 PM
Perhaps I should think of "change the current branch" as a particular subset of "change which commit HEAD points to".
 
> [...] The actual API is a mess
I mean, checkout can also just create a branch by adding one innocent flag
 
I don't expect a sensible interface, but I do expect to complain about the unsensibility of the interface
I rescind this particular complaint, however. More to come, surely.
 
user10984358
heya
 
user10984358
can anyone here suggest me a plugin or config file edit so I can use my webcam in Sublime Text 3??
 
Use it in what way?
 
user10984358
1:29 PM
the open cv module that lets you use the webcam
 
user10984358
for some reasons it doesn't open my webcam when I run in sublime 3
 
user10984358
the exact same code works if I run in spyder
 
user10984358
cap = cv2.VideoCapture(0)


[Finished in 6.9s with exit code -6]
 
@Kevin "git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space."
11
 
user10984358
thats the output I get if I run the code in ST3
 
1:33 PM
Oops, I used revert when I was supposed to use reset, and it added a commit on top of the commit I wanted to obliterate. I thought I could fix this by doing reset twice, but nothing's happening. Not sure whether I misunderstand how reset works, or if this simulation isn't perfectly representative of how reset actually works
 
user10984358
@MisterMiyagi on an entirely different note, is one sposed to understand the above sentence if they were following in on the convo?? O_0
 
@TheNamesAlc I think it's deliberately confusing, and possibly a reference to the A monad is just a monoid in the category of endofunctors, what's the problem? joke
 
surprisingly enough, the Monad quote actually was useful to me ^^
the git quote is just hogwash
 
user10984358
I will look into that
 
user10984358
sorry to barge in though
 
user10984358
1:36 PM
can you suggest me something related to what I asked earlier??
 
I figured it was an extra technical way of saying "branches are labels pointing to nodes in the commit tree"
@TheNamesAlc Don't worry about that. I consider Python questions to always supersede non-Python conversations in here.
Feel free to completely ignore my git ramblings.
 
user10984358
I'd join in if I knew git but a friend of mine said don't care how it works just type the commands in order, IT WILL WORK
 
Re: the webcam problem. exit code -6 may indicate that an error occurred. because anything other than a zero usually indicates an error.
It's curious that you're not getting an exception though.
 
user10984358
well the same code works in spyder
 
user10984358
I didn't even change a thing
 
1:39 PM
Yes, that's quite curious.
 
user10984358
the code works in sublime if I provide a video path, which means the rest of the code is peachy (acc to me at least )
 
Did you have to do anything special to get it working in spyder?
 
user10984358
well they both use the same anaconda python
 
user10984358
I thought it was a Mac thing at first but for some reasons I realized I had Spyder and so I checked on it and it worked
 
user10984358
file->open->run
 
user10984358
1:40 PM
nothing else
 
Is there any other code in the script besides cap = cv2.VideoCapture(0) ?
 
Anyone using authlib? and can tell me what the current_token is? what properties does it have etc?
 
user10984358
yeah, 140 ish
 
user10984358
if its of any worth this is what I get in the ST3 output area on full execution
 
user10984358
[Finished in 2.1s with exit code -6]
[shell_cmd: python -u "/Users/thenamesalc/Downloads/object_detection_tutorial.py"]
[dir: /Users/thenamesalc/Downloads]
[path: /Volumes/Learning/College/Lab/BigData/packages/pig-0.17.0/bin:/Volumes/Learning/College/Lab/BigData/packages/hadoop-3.1.1/bin:/Volumes/Learning/College/Lab/BigData/packages/apache-hive-3.1.1-bin/bin:/Volumes/Learning/College/Lab/BigData/packages/apache-cassandra-3.11.3/bin:/Volumes/Learning/College/Lab/BigData/packages/mongodb-osx-x86_64-4.0.4/bin:/anaconda3/bin:/Users/thenamesalc/anaconda3/bin:/usr/local/mysql/bin:/Library/Framew
 
user10984358
1:42 PM
if you want to know what the script is about, its just a modified script from the Tensorflow object detection API
 
user10984358
I just added in the webcam part
 
It would probably be useful to add some logging to the code to determine how much of the program is running before it exits. Ideally this would let you discover exactly which line is causing the problem. A bunch of print calls would do in a pinch, but you can get fancier if you want.
 
user10984358
lemme try a print at the last line, that should do??
 
user10984358
a print above the cv2.videoCapture(0) prints, rest doesn't (middle and one at the last line)
 
Adding a single print to the end of the program will let you know whether the exit is occurring in your actual program body, or if it's happening during cleanup. If the print doesn't appear, then you'll need to sprinkle more in.
 
user10984358
1:46 PM
I added in three prints, one above the webcam part and one after it and one at the last, only the first print was "printed"
 
user10984358
this has lead to me believing that I need some plugin or edit some config file in sublime to get this working, I've had no issues with running anything in sublime before, is this more of a sublime question now or is there a way I can tweak the code??
 
#if the code literally looks like this:

print("before VideoCapture")
cap = cv2.VideoCapture(0)
print("after VideoCapture")
rest_of_code_goes_here()

#... Then that implies that VideoCapture is responsible for the exit.
 
user10984358
thats it
 
user10984358
buncha imports at the start aside
 
user10984358
the light doesn't even turn on, it turns on way before the display is when I run on Spyder
 
1:52 PM
I'm tempted to say "some IDEs will inspect the state of objects while a program is running for diagnostic purposes, and this can cause a program to fail if those objects have impure behavior (in other words, if their state changes when you look at their state)", but I don't think that Sublime Text is that kind of IDE.
Not that I'm well-informed on the matter, having used ST for like ten minutes ever
 
user10984358
well I appreciate the help, I guess I will post one on the ST 3 forums to see if I get anything
 
Bounty, and canonical answers hunters: stackoverflow.com/questions/56581237/…
 
user10984358
I hate Spyder
 
user10984358
get that bounty dont wanna keep ya waiting, thanks again!!
 
(Re: git problems. I think reset does work in this simulation and I do have an approximately correct understanding, I just got the syntax wrong. git reset thing does not, in fact, mean "obliterate the commit pointed to by thing and move it one commit up in the tree")
 
1:57 PM
@Kevin the commit which HEAD points to is the "current branch", is it not?
but if it's also a branch name then that gets stuck to HEAD too
nevermind, rescinded :P
@Kevin I don't think I've had to use revert in the wild, and reset only when I wanted to undo a fresh commit
@TheNamesAlc that's a very good way to ruin any repository
 
reset would have been useful yesterday. Or maybe not; everything is made doubly complicated by the fact that I'm working on local copies of branches and forks hosted online
 
never embrace cargo culting
 
It doesn't help that I have to enter my twenty character password every time I need to connect to the server. Yes, I know there's a way to type it in once and have it remembered for the rest of the session, but I couldn't get it working since it only works in git bash and I couldn't figure out where I installed it
 
@Kevin that actually makes it great. You can untangle your local copy before anyone seeing it. Don't forget that branches are just pointers to commits, so often you can just get away with creating a new branch on another commit and deleting the old branch. Without any references left to the old branch it won't be able to cause any trouble.
 
There might be a way to make dumb old cmd remember my passphrase too. I suspect this is the case because I never need to type it in for KevinScript. So either it memorized my passphrase for that project specifically, or I never had a passphrase for that project to begin with.
I can't find any indication online that the former is possible, so the latter is probably the truth, alas
 
2:04 PM
Maybe you checked out KevinScript through SSH and CPython through HTTPS?
 
Hmm, unsure. I know that I have at least two files in my .ssh directory.
 
your repo's local .git/config would tell you
 
rbrb
 
I'm not sure why I assumed you were working on the CPython repo, but whatever
Just goes to show that half of my brain is thinking about something else
 
2:10 PM
well he did commit to cpython
 
@AndrasDeak I agree that it's nice that I can mangle my local copies all I want without anyone being able to see my fumbling. I don't know if reset by itself could have fixed my problem, though.
...
 |
C0042
 |
C0043 <- local master
 |   \
 |    \
 |     \
C0044   \
 |       C0044b <- *bugfix
 |
3000 commits go here...
 |
 |
C3044 <- server master
Here's my local commit tree. Just doing a reset would move bugfix up to the same commit as local master, but I don't want it to point to local master, I want to point it to server master.
(In any case it's fine if C0044b becomes inaccessible to me since it was just a one-line change. So I don't need to bend over backwards trying to move that node to make it a child of C3044)
 
you have to (read: can) rebase bugfix onto the remote master
Next time you can even do git fetch upstream master (or whatever name the remote has, and give or take syntax issues) and then git checkout -b bugfix upstream/master or something like that. Some projects (e.g. numpy) outright suggest that you delete your local master, YAGNI.
 
@Aran-Fey Not an unreasonable guess, since that's one of the few public projects I've made PRs for in the past. But actually I'm contributing to MTG Forge, an open-source card game engine.
 
a visual understanding helps when you know nothing of Git and have to resort to trawling through hundreds of git posts on stack overflow hoping the next one will work and at the same time not wanting to disfigure your source tree beyond repair
 
I'm intrigued at the idea of checkout -bing straight from the remote master. At the very least it would save me some public embarrassment if I could create branches locally before creating them on the server.
Probably there are no obstacles preventing me from doing so, I was merely too dumb to do it the right way yesterday.
 
2:21 PM
Don't be unjust to yourself. You were merely too ignorant to do it the right way yesterday.
@Kevin since I'm not known to be a reliable source, here's numpy's suggested dev workflow
 
incidentally, I think I got the git commands right
 
I think the lead devs of Forge merge straight from their personal fork's master to the official master, with no branching involved. I suspect this is not best-practicey.
 
@DeveshKumarSingh hammered
@Kevin probably not
 
I still don't know what a fork is or how any operations work when performed between forks, so I'm going off instinct there
 
2:27 PM
as far as I understand a fork is just a repo that started off from a state of another repo at a given point in time
Starting from the fork they are just two independent repos, but things like github automatically offer you to submit PRs to masters of your "parent" (in the forking sense) repo. But that's above git.
 
yuck, the accepted answer from that dupe is plain terrible. No respect for locales.
 
I forked numpy years ago when I first wanted to contribute, which is my origin, but ever since I've just been fetching upstream (which is numpy's numpy repo) and only using my fork as a stepping stone to issuing PRs from origin to upstream (both of which are remotes compared to my local work)
 
The more I try to learn git the more I'm convinced that there has to be an easier solution somewhere out there
 
well if you don't like git then svn or hg might work for you, they are probably different
 
I thought I had a decent understanding of the underlying concepts, but... nope
 
Kef
2:32 PM
a GUI client helps a lot
 
git gui is extremely useful for my personal projects, which need nothing more than the ability to diff/stage/commit locally
But if more than one computer is involved, I really need a deeper conceptual understanding.
 
git GUIs make it very easy to break things :P
 
Kef
at least I was finally able to setup a local repositury, which pulls from a public fork and pushes to my github repository to sync up my working machines =)
after breaking the local repos a dozen of times with console git
 
Kef
and yeah, git gui is awful
 
2:43 PM
From the interactive tutorial: "just remember you can always undo or reset to fix mistakes :-)"... Boy, I wish I had known those were options for the previous ten exercises.
 
hehe
 
I also wish those commands were available in a regular git environment, but that one might be a futile wish.
git burn_crops --salt_earth=True
git deploy_thermite_charge
 
remember: you can always copy your entire repo to another directory before doing something drastic :D
 
Of course, I always make backups of my git repos, and name them "KevinScript", "KevinScript new", "Copy of KevinScript new", "KevinScript new new actually new 6_17_2019", and so forth in that fashion
 
2:48 PM
Wow, what kind of stone-age solution is that? Nowadays you can just store your git repo in a svn/hg/bzr repo smh
 
Kef
xkcd had that one
 
any one has experience with bash regex matching? As in how different are they with python's regex?
 
bash regex is pretty limited IIRC
 
I didn't know bash did regex. Tools like sed and grep and awk do.
 
They have ~= which is supposed to perform some kinda pattern match
 
2:51 PM
Ah
 
here trying to wrap my head around how to use it and combine with this
 
@Kevin thanks for sharing your plight. Knowing that git is challenging to others (seems like everyone) makes me feel a bit better about the extent to which I am able to use git.
 
@DeveshKumarSingh I think the latter is not regex, but globs
Wildcards I mean.
 
okay, then I suppose I will look up more about this
But what's the difference between regex and wildcards
 
everything
compare 'foo*.bar' and 'foo.*\.bar'
if they are the same thing in bash then it would seem that bash does not to regex after all :P
 
2:58 PM
okay let me find out
 
I always understood "wildcard" to mean "a string where an asterisk stands for any number of characters of any type". Regex has considerably more features than that.
 
> An additional binary operator, ‘=~’, is available, with the same precedence as ‘==’ and ‘!=’. When it is used, the string to the right of the operator is considered a POSIX extended regular expression and matched accordingly (as in regex3)
 
wildcards support ? (which is equivalent to (?s). in regex) and * (which is equivalent to (?s).* in regex) and nothing else
 
so =~ does do regex, and your latter link is not that
 
okay so there may be special meaning of characters, different then python regex
 
3:00 PM
Yes, there are a lot of regex flavours. For instance what you need to escape and what not varies.
Some flavours use \(\) for grouping, others (). Some use + as an operator, some \+.
 
Is there a formal definition of "wildcard" or is it just ad-hoc defined by the consensus of all the popular tools that use wildcards?
 
probably the latter
 
I'd expect it to be an ad hoc thing
 
Reminiscent of all the questions on SO about "binary files" as if that's a real format
 
okay, then I just need to find the correct document which tells me about bash regex and how to use it
 
3:02 PM
I'm pretty sure bash regex is just a subset of python regex
 
@DeveshKumarSingh "POSIX extended regular expression"
 
Hmm, is it normal to have no idea which git commands require you to specify a node/branch, and which ones assume that they're operating on the current branch? Because I have no idea.
 
@Kevin it's normal, though most probably work on the current one if you don't specify any. I spend a lot of time reading manpages when I do nontrivial things. This is the "crazy API" part.
 
if self.board["TL"] == player.type and self.board["TM"] == player.type and self.board["TR"] == player.type or \
self.board["ML"] == player.type and self.board["MM"] == player.type and self.board["MR"] == player.type or \
self.board["BL"] == player.type and self.board["BM"] == player.type and self.board["BR"] == player.type or \
self.board["TL"] == player.type and self.board["ML"] == player.type and self.board["BL"] == player.type or \
self.board["TM"] == player.type and self.board["MM"] == player.type and self.board["BM"] == player.type or \
How would you write the above code shorter?
 
I see multiple issues...
 
3:04 PM
okay, first experience of having a decent bit of time playing with elastic canvas... I'm reasonably impressed...
 
@Justin How are those and-and-or-and-and-or sequences supposed to be grouped?
 
Ah, the old "brute-force checking every tic tac toe direction" problem...
 
@DeveshKumarSingh posting a raw link does very little to actually help the people who need guidance
 
I have tried this -
    if (player.type in {self.board["TL", "TM", "TR"]} or
        player.type in {self.board["ML", "MM", "MR"]} or
        player.type in {self.board["BL", "BM", "BR"]} or
        player.type in {self.board["TL", "ML", "BL"]} or
        player.type in {self.board["TM", "MM", "BM"]} or
        player.type in {self.board["TR", "MR", "BR"]} or
        player.type in {self.board["TL", "MM", "BR"]} or
        player.type in {self.board["BL", "MM", "TR"]}):
But it doesn't work.
 
No, it doesn't.
 
3:06 PM
step 1: learn about chained comparison: X == Y and Y == Z can be written as X == Y == Z
 
@Kevin yeah... I wonder how many times I've seen the equivalent now, where I just looked at that and though TL (top left), BR (bottom right) and figured it's a 3x3 tic-tac-toe attempt :p
 
cbg
 
step 2: learn about itertools.product which can generate all those 2-letter pairs for you actually that's not the right tool for the job
 
Here's a link to my answer and check the comments. - codereview.stackexchange.com/questions/222431/…
 
good thing that or binds weaker than and I guess
 
3:10 PM
I think I just discovered an undefined behaviour, b64decode seems to accept an arbitrary amount of padding and it isn't documented anywhere
 
I wrote a tic-tac-toe implementation as a test when I first used github, but I think I extremely overengineered the getWinner implementation so it would work for arbitrary sizes of board and N-in-a-row requirements
 
Why am I worried about this? Cause PEP 8 says - Limit all lines to a maximum of 79 characters.
 
>>> import base64
>>> base64.b64decode(b'abcdef======================')
b'i\xb7\x1dy'
 
@Justin that's not why you should be worried
 
I expected an "Incorrect padding" Error
 
3:13 PM
@Justin The first thing I'd be inclined to do is to separate data from logic by storing the index names in its own data structure. This doesn't reduce the line count of the code, but it does make the conditional logic lines shorter.
 
@AndrasDeak - I am worried though. It's like - breaking rules. All PEP 8 checkers say the same thing - "Line too long"
 
e.g.
def is_winner(player_type):
    runs = [
        #horizontal
        ["TL", "TM", "TR"],
        ["ML", "MM", "MR"],
        ["BL", "BM", "BR"],
        #vertical
        ["TL", "ML", "BL"],
        ["TM", "MM", "BM"],
        ["TR", "MR", "BR"],
        #diagonal
        ["TL", "MM", "BR"],
        ["BL", "MM", "TR"]
    ]
    for a,b,c in runs:
        if self.board[a] == self.board[b] == self.board[c] == player_type:
            return True
    return False
 
can't you guys just use indices?
 
That whole loop could also be refactored to return any(self.board[a] == self.board[b] == self.board[c] == player_type for a,b,c in runs)
 
@Kevin Woah! That's amazing.
 
3:14 PM
@MisterMiyagi beyond the scope of the question
@Kevin or any(all()) for extra line shortness :P
 
Furthermore I agree with MisterMiyagi that it may make sense to change how self.board is indexed. You could make it a list-of-lists, so it can be indexed like self.board[0][2], or you might unroll it into a single list of length 9.
 
Or have Board class override __getitem__ to accept a tuple of keys and return the tuple of values, so that self.board(a, b, c) will give you the tuple.
 
@Kevin 1difying sounds like a setup for indexing errors
 
@Justin That's like losing 3 limbs in a horrible car accident and being worried about a pimple on your forehead. Yes, violating pep8 is a bad thing, but you have bigger problems to worry about - like actually making the code work
 
people living above the level of C should not have to index multidimensional problems as 1d arrays
 
3:17 PM
You can see my not-as-overcomplicated previous implementation of getWinners at github.com/kms70847/Tic-Tac-Toe/blob/master/state.py#L99. It stores the entire runs structure in the string "1 2 3, 4 5 6, 7 8 9, 1 4 7, 2 5 8, 3 6 9, 1 5 9, 3 5 7", then uses string parsing shenanigans and getByIdx to turn those indexes into x and y coordinates
 
@Aran-Fey - I agree.
 
@AndrasDeak Yes, although it might be an acceptable tradeoff if the alternative is writing code like return any(self.board[ay][ax] == self.board[by][bx] == self.board[cy][cx] == player_type for (ay,ax),(by,bx),(cy,cx) in runs)
 
@Kevin It doesn't work though. Even after 3 X's have occurred in a row, the game still continues. Why is that?
 
I give "Requiring parentheses in one's argument unpacking list" a Cognitive Load rating of 3/5
@Justin Strange, the function works OK on my machine. For example, ideone.com/lN4paa correctly identifies that "X" has won.
 
if self.board.change_board(position, type) is not None:
        return self.board.change_board(position, type)
^ likely cause of the bug
if self.board[position] is " ": <- or maybe that
The longer I look the more code smells I find. Time to stop looking
 
3:32 PM
Hmm, can't say I approve of using is on a string literal. Even if it almost always does the same thing as equality for smallish strings.
 
seems... ah.. unwise.
 
@Kevin - Try it on the full code provided here - codereview.stackexchange.com/questions/222431/…. Then it doesn't work.
 
On a somewhat related note: Is there a way to reliably create two ints with the same value but different ids?
 
@Kevin - Replace the existing is_winner function with your function and try it out.
 
though I guess whether or not it's "reliable" will depend on the interpreter...
still works on my PC
 
3:38 PM
@Justin Ok, I just tried it. ideone.com/Mtg72B. It succesfully identifies that X is the winner.
(output is a little mangled there because ideone doesn't display the user's response to input() calls, but bottom line: it prints "Player X is the winner!")
 
@Aran-Fey may I ask why you care about the id?
 
@Kevin - Thanks a million(*million)! You've been a great help(*10)! Thanks again for solving my problem!
 
@Aran-Fey Cheaty solution for 2.7:
>>> x = 1
>>> y = 1l
>>> x == y
True
>>> x is y
False
 
@AndrasDeak It's for my serializer - I want to ensure that the serializer correctly deduplicates integers/floats/etc to save space
 
"Deduplicates"?
 
3:44 PM
Creating three equal ints that have unequal ids is beyond the scope of the exercise :-P
@Justin No problem :-)
 
@AndrasDeak Basically if x == y and x is not y and x1, y1 = load(dump([x, y])) then x1 is y1 should be True
 
I interpret Aran-Fey's problem as "My program is supposed to identify numbers that are equal but not referentially identical. In order to test this behavior, I need to create numbers that are equal but not referentially identical. How can I do this?"
 
Pretty much
 
Isn't trying to deserialize into identical python types pointless overengineering/premature optimization? Are you worried that [1000]*1000 will take up more space when deserialized?
>>> sys.getsizeof([1000]*1000)
8064
>>> sys.getsizeof([1000+1-1 for _ in range(1000)])
9024
I guess that's it
 
I'm more worried about the file size, but you're probably right that it's not worth worrying about
so, minor revision: how can I generate two strings that are equal but not identical? :D
 
3:49 PM
"file size" sounds like the forward direction of serialization. Wouldn't you serialize by value anyway?
I'm probably just missing your point.
 
you underestimate my serializer. It correctly preserves references between objects. That's not necessary for ints/floats/strings/etc, so I want to write a test that verifies that those types are deduplicated
 
so for those types you do want to serialize by value
 
yeah
 
floats don't ever get cached I think
>>> x = 0.0
>>> y = 0.0
>>> x is y
False
zero would be the first one to be
since interning is an implementation detail I'm not sure you can get any guarantees for when it doesn't happen...
 
Even PyLong_FromLong returns the interned copy of small ints, so even with the power of the C API I don't think you can get a referentially unique int.
 
3:55 PM
@DeveshKumarSingh Look at the man page for grep on your system. That should be pretty close. There's a little bit of info in the man page of bash itself, IIRC. But mostly, bash, sed, and grep will be very similar in their regex dialect. grep has extended and plain regex.
 
@Kevin well creating 257 twice will probably work
 
Agreed. Using an int outside of CPython's interning range seems like a reasonable way to test int deduplication.
Caveat emptor since that range could change in future versions, but oh well.
 
or some other implementation might decide to intern that number because why not I guess
 
The thing is... I know I can't use an int in the [-5;255] range, but there's no guarantee that the peephole optimizer won't notice that I hard-coded two 256 literals in the same function
 
At the very least you can write your test so it fails noisily if you try to create referentially unique ints and that uniqueness gets peephole optimized away before you can even test your serializer
 
3:59 PM
256 is still interned according to my experiment. But you can always poke a needle in the peephole with 256+1-1 or even 256+0 perhaps
 
02:00 - 16:0016:00 - 23:00

« first day (3166 days earlier)      last day (1776 days later) »