« first day (3830 days earlier)      last day (1110 days later) » 

5:05 AM
dipping toe into a linux vm. KDE Plasma or Gnome?
 
 
2 hours later…
6:56 AM
I like Gnome for their clean (almost minimalist) user interfaces. I dislike Gnome for the lack of customization, the bugs, and the stupid ideas shoved down your throat. (Desktop icons? You don't need those!)
That said, Gnome Shell for life
 
7:07 AM
Try them all and decide, I've grown to dislike all of the new ones (i.e Plasma 5+ and Gnone), but not as much as I dislike OS X or Windows. That said, if you started with Windows you might like Plasma 5, if you started with OS X you might like Gnome.
Though if you actually like OS X you might find Gnome extremely offensive, so... try it out I guess? Anyway I do most of my usage inside either some web browser or a virtual terminal/shell (for me, Konsole), so as long as the window manager doesn't actively try to get in my way (i.e. all my usual mouse/keyboard shortcuts work the way exactly I expected it to) and looks okay enough that's all I care
 
 
1 hour later…
8:24 AM
@Aran-Fey agreed
 
 
3 hours later…
10:54 AM
Good sunday everyone ^^
 
11:14 AM
can if x is None or x == 0 be shortened to if x in (None, 0)? Without None and multiple checks, in is convenient over multiple or checks, like if x in (10, 15, 100). But in effectively does an equality == check, right? so does that make if x in (None, 0) incorrect? I'd say yes, it's incorrect unless ...
unless there's no way for x to be a class, and is just a standard type or built in or a class which has no __eq__ shenanigans. using this answer which details some of the innards: stackoverflow.com/a/14247383
* wrt "in does an equality check" - it calls __contains__ or successively calls __getitem__ over a collection and then does the equality check with each
In this example, ignore the 0, coz otherwise it's just if x since None and 0 are boolean false. maybe (None, -1, 100) as the potential values of x being checked is a better example
*if not x
so would the correct and shortest (and clearest) version of that be if x is None or x in (-1, 100) ?
 
11:33 AM
I'm not sure I agree that x == None would be "incorrect", but other than that, yes to everything
 
it's just that that particular example is specified in the docs, a pep guide and many SO answers - which is good for beginners to understand. but if a class (or any type) doesn't override __eq__ to return a "different" answer with other is None, then x == None should actually be fine, I think. wondering if there's a flaw in my logic or missing information
so if x can only be a built-in type then the shortest correct version of the snippet above would be if x in (None, -1, 100) (and also for user/external classes doing nothing funny with __eq__)
 
Right. It's generally recommended to use is when comparing against singletons. In my eyes, that makes total sense for booleans, because booleans can compare equal to ints, which is often undesired. But other singletons like None or ... or NotImplemented? Someone has to specifically create an object that compares equal to those. If someone thinks it's a good idea to write such an object and pass it into a function I wrote, that's none of my business.
 
11:52 AM
strArr = ["B:-1", "A:1", "B:3", "A:5"]

dictionar = {}
for el in strArr:
    element_splitted = el.split(":", 1)
    if element_splitted[0] in dictionar.keys():
        dictionar[element_splitted[0]] += int(element_splitted[1])
    else:
        dictionar[element_splitted[0]] = int(element_splitted[1])

dict(sorted(dictionar.items(), key=lambda item: item[1]))
why do I get the error with list object is not callable ?
 
12:14 PM
i couldn't reproduce any error from your code snippet
which means you should probably restart your kernel and try running this again
 
yes i somehow overriten the sorted keyword...
 
yep, that would do it :)
 
@Aran-Fey thanks, fair enough.
 
1:11 PM
@aneroid I'd always spell out x is None in this situation, because it's semantically very different.
 
2:05 PM
Welp it took me six hours but I managed to parse the 5% of the .swf file format that my important file uses
Along the way I only encountered one typo (missing "= 0"s on STRAIGHTEDGERECORD table in appendix A) and two unspecified behaviors (whether the element following a RECT should always be byte-aligned, even if it isn't a must-be-byte-aligned type; whether a Shape4 object uses RGB or RGBA for its color-based attributes) and one apparently nonstandard formatting in my real data (FileAttribute tag is 4 bytes long, not 1)
 
Hah, why am not surprised that a file format that's already dead still has an incomplete spec
 
Did I mention the spec hasn't been updated since 2012 :>
 
Must be a real important project if you went to such lengths
 
didn't know this world had ever seen a complete spec tbh
 
I believe experts say that in some ways the spec isn't complete even for the specific version it purports to describe. I didn't encounter any glaring holes, myself. But again, only did 5%.
That said, I'll give the file format and documentation a B- in spite of these oversights. The format's length-prefixed tag structure made it easy to skip over difficult features and implement easy ones first. The documentation also had a very thorough walkthrough of a small yet valid swf file, complete with hex dump. This is far from my least pleasant experience with binary format parsing.
> In 2008, the specifications document was criticized by Rob Savoye, the lead developer of the Gnash project, as missing "huge amounts" of information needed to completely implement SWF, omitting specifications for RTMP and Sorenson Spark.[11] The RTMP specification[34] was released publicly in June 2009.[citation needed] The Sorenson Spark codec is not Adobe's property.
 
2:19 PM
Good thing it's dead
 
Until I reimplement it in HTML5. Can't killswitch this one, browsers >:-)
I'll leave in all the vulnerabilities, maybe add a couple for good measure
@Aran-Fey The data I'm trying to extract could, in principle, be re-recorded by hand in maybe 90 minutes. But I don't want to do it because it's boring, and I can't force the intern to do it unless I first induct him into the next level of industry knowledge
And that requires a whole thing, with black candles and animal masks and a rented castle on a secluded island near Venice. Parsing is easier, ultimately.
 
Your company has important data stored in swf files? O.o
 
Yeah, I find it a bit odd too. Maybe it made sense at the time, since the data is more or less a collection of vector images, which swf/flash can natively store/render. I have a feeling that the sensible alternative, SVG, had shaky support in the browsers our customers used in 2012. Keeping in mind that our customers are always 5 years behind the curve.
Not their fault, that's just how it is in my weird corner of tech
 
 
1 hour later…
3:40 PM
@AndrasDeak I understand that that's how it should be done, including to handle classes that might implement eq as def __eq__(self, other): return self.val == otherwould fail x == None but pass when x is actually assigned None (since x is not a class instance) - but barring that situation - what's the impact of it being semantically different?
while I'd continue to do if x is None or x in (-1, 100) - if there's a guarantee of x being only a built-in type or an instance of a class with no __eq__ method, then how would one justify (read: teach) that if x in (None, -1, 100) is wrong?
especially when the == None pitfall won't occur
 
@aneroid readability. Clear code.
If it's default or the passed value is so and so: do thing
readable to me, obviously
 
hmm. good point as well. will think about it but will stick to the safe option generally.
 
If you're using None as a sentinel value, then on a semantic level it makes sense to use referential equality (i.e. "is") rather than value equality (i.e. "=="), because you do not want any other value to be considered equal to it. It should be absolutely unique, and the user should not get the opportunity to change things by making a funny __eq__ implementation.
 
@AndrasDeak also, if the reason is "readability/clarity" it implies it's not "airquotes wrong"
 
@aneroid Aran-Fey already told you it's technically fine
 
3:49 PM
yes, that's what I was keeping at the forefront (in my head)
just curious if you had a different/technical reason why it might wrong
 
Presumably I'd have said so if I did
 
@AndrasDeak got it :thumbs up:
@Kevin wrt "user should not get the opportunity to change things by making a funny eq implementation." - agreed. and I'm restricting the use-case to 'x' definitely not being an instance of such a class.
for whatever reason, apart from expecting the user to "accept" this truth, I find this harder to explain than if __name__ == '__main__'
 
Possibly unpopular opinion: I think Python's semantic insistence on "is" for sentinel testing is unimportant in most cases. I rarely see types that have custom logic for comparison to None, and it's double-extra rare that I have a value that could be either None or some arbitrary type that I don't have any information on. If I'm adhering to strong typing principles, then I can easily determine where == None is functionally identical to is None.
... But I have no problem following purely stylistic rules just for the sake of fitting in, so I do is None anyway.
 
yeah, for safety, in my classes, I generally add if other is None: return False (coz my object can't exist if it's None) before the actual equality check
# ie something like
def __eq__(self, other):
    if other is None:
        return False
    return self.val == other
or return other is not None and self....
 
I like to skip any None checking in my __eq__s and just do return self.color == other.color and self.num_spokes == other.num_spokes and let the AttributeError occur naturally. My particular flavor of strong typing design means that I rarely want to intentionally compare a Foobar instance with anything that isn't a Foobar
 
4:00 PM
yeah, it adds a ton of boilerplate to my class(es) but the downside is that without it all user-code has to have the is None check before doing comparisons (assume not very experienced coders). choice was my pain vs failing tests / improper behaviour
anyway, thanks all, for the inputs. the views are clear
 
 
1 hour later…
5:15 PM
@aneroid I'm not sure I understand that example. Normally there are very few specific types your objects can compare against as equal, so None should be the same as frozenset or my Potato class or whatever else that your class can't handle. I don't see why None should be special-cased in this situation.
"I can figure out if my object is equal to instances literally any other class... except for NoneType".
 
Hello all
@roganjosh thanks a lot for your reply on the issue and sorry for the days late respond, I wasnt able to login any sooner. so let me post the issue again because I didn't touch the code for over 2 days.
class bag(db.Model):
 id = db.Column(db.Integer, primary_key=True)
 name = db.Column(db.String(), nullable=True)
 box= db.relationship("box", backref='bag')

 class box(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(), nullable=True)
  bag_id = db.Column(db.Integer, db.ForeignKey('bag.id'))
  item_id = db.Column(db.Integer, db.ForeignKey('item.id'), nullable=True)


 class item(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(), nullable=True)
 
"My users complain less if I make '== None' return a value rather than crashing" is arguably valid design choice ;-)
Even if it only hides the user's logic errors and makes their code behave incorrectly without their knowledge, if they're happy, that's one less support ticket :-D
 
@LoopingDev are you really using one space for indentation?
 
so the end result that I expect from this query is

x [{box.name: box.name, bag.name:bag.name , item.name:item.name } .. etc]

if you take a look at how I collected the data, I had to query(lets call it "x")
then loop into the query (looped in "x" ) ,
then query each foreigne-key into the query(x)

I dont know if `joinouter` would have a better performance impact than this.
@AndrasDeak it's copy-past issue I guess, I tried to clean it but the text space is very narrow for this chat.
 
@LoopingDev if that's a "no" then OK
@LoopingDev but that's a bit too much code for chat. Next time please post a link to a code paste site instead.
 
5:26 PM
I'll try next time, thanks!
 
it's easy
 
so what about the code. is the way I'm joining the query together is just the same as using joinouter method ?
i figured that I'll have to join every (bag "id") then use outerjoin to join it to every "item" which would result in another loop of queries.
x = bag.query.filter_by(id=0).all()
for row in x:
      d = dataclasses.asdict(row)
      if row.box:
          for i in row.box:
              k.append(i.item.name)
      d["item_name_list"] = k
      f.append(d)
if that is just as good then maybe I should leave it like this.
 
My default assumption in cases like this is "if both Python and the ORM can do it, then the ORM can do it faster"
Unfortunately I don't know whether join outer is functionally identical to your existing code, so my "if" is still just an "if"
Your code snippet there, and the bigger one above, look a little odd to me because they do k = [] in an odd place. I'd expect it to be inside the for row in x: loop, because each row should get its own item name list.
If k is created outside of the loop, then it will continue to hold all the names of all previous rows, which is probably not what you want
 
6:04 PM
Hey guys I am implementing a minimax algorithm to play tictactoe and it works perfectly, however when trying to implement the alpha beta pruning the ai seems to starts to stop playing optimally the algorithm is here dpaste.com/9SLRNHVTU lines36,37 and 60,61 implement the pruning, but seems to cause the ai to make silly moves
 
@LoopingDev No, it isn't just as good and it isn't idiomatic. If you're going to use the ORM then I think you should use it properly. Where is the join
I'm not sure it requires an outerjoin either tbh
I think I'm just generally a bit confused about the expected output for your application
If it's just going to be passed to the frontend then jinja2 can cope with the queryset and you can just access attributes there
 
AAB
cbg
running a postgres query using psycopg2
select id, min(price) as min_price from table where categ=%s group by id order by id
I get different results when I run select id, min(price) as min_price from table group by id order by id
for eg for id 41 the min price is 14500 in first query, in 2nd query its 13550 the correct result,
 
Err, isn't where categ=%s the elephant in the room on that one?
 
AAB
Isnt the first query the same as seocnd one apart from the filter on categ?
@roganjosh the first query applies group by on all id that match categ right
why would the result still be different
 
Yes, but there's nothing in your posts to suggest that the the 14500 value has a categ = %s
Whatever %s is in this case
 
AAB
6:17 PM
@roganjosh okay let me clear up
I have pid, cid, categ, price here pid is unique cid is not can be same for mutliple rows
categ is an int value
so for the dataset
 
"SELECT id, price, categ FROM table ORDER BY price DESC" and print the result. Then look to see if the categ value matches your search filter in the first query
 
AAB
@roganjosh if categ = 2 for all where id = 41
 
In fact, I don't know what we're debating here. It's almost certainly the loss of categ=%s that's changing the results
@AAB yeah, and the second query is giving you the table's maximum value, regardless of categ=2
 
AAB
@roganjosh hmm I know for sure where id = 41 categ is 2 so both should give same result
:/
 
"I know for sure" probably isn't good enough. Have you tested that with a query?
Systems have messy data all the time. If you're going off "Bob in Engineering told me so" then that's gonna be an issue
 
AAB
6:27 PM
@roganjosh yup its not there :( sorry about that.
 
I didnt add the join because I simply couldn't joint every bag the items and I couldn't join every box to the bag because not all of the bags has items and not all of the boxes has bags.
( i kept getting an error that stated there was no foregine key between the two classes, I assumed that is what it meant )

Unfortunately, i can't use jinja, I need to respond to the Ajax/fetch request properly.

when I query the box , it also pulls the bags inside that box ( that is good ) but it doesn't pull the items inside those bags ( it just prints the id of them instead of their names)
because I simply couldn't join every bag to every item*
 
@AAB I'm not sure what you're apologising for. Are you saying you've found the issue?
 
AAB
@roganjosh the data was not there as in for some of id = 41, the categ is null for some reason :(
 
Well, mystery solved at least, and hopefully lesson-learned. "That can't happen" should never be believed... unless it's my system, of course :P
@LoopingDev "i kept getting an error that stated there was no foregine key between the two classes, I assumed that is what it meant" Then you assumed incorrectly, I'm afraid
 
AAB
@roganjosh yea cant believe I am so stupid just had to see the data once and I am thinking what iswrong with the query :(
 
6:36 PM
You don't need a FK to do a join, it will just be used (if possible) if you don't tell the ORM what to join on
@AAB Don't beat yourself up about it. It's all learning
 
@roganjosh maybe I gave up too quickly ^^ you are right, I'll take another look at it
but what scares me that whenever I see any example on join , it just joins two full tables , no filters by anything .. am I asking sqlalchemy to pull half it's database ?
also if I added filter by a user , that could only be applied to one table
 
AAB
@roganjosh thanks as always for spending your time :)
 
It seems like you'd end up pulling half the DB anyway with your double loop
 
it doesn't exist in the other.
@Kevin yeah, that is what I thought , then why would I change the code at all , it's already doing that by itself lol
 
@LoopingDev no. You need to think about SQL differently. You can build queries up in multiple parts before they're executed. Chaining the selects and filters does not mean they will be executed in order - SQL is a declarative language and you're just building component parts of a single query
At least, that's what you're doing in SQLAlchemy. The syntax is similar in pandas but then chaining is executed sequentially
 
6:44 PM
Getting down to brass tacks, you don't need to have an answer to "why would X be better than Y?" if you can benchmark both and determine that X is better than Y
Fast code is fast regardless of whether you understand why it's fast
I'm not trying to squash anyone's curiosity here, I love theorycrafting more than anybody. I'm just saying... Prioritize.
 
you are probably right, I keep thinking of sql the same way I think of python because I used both of them together and it's not seems right .

so basically I need to write a method to query a list with those conditions
1- get all the boxes under user id (0)
2 - get all the bags connected to each of those boxes
3- if there is any item inside those bag , pull there Id and Name as well.
that is how we do it in english,
how to write it in sql ?
 
Are you asking me to write it for you?
 
that would be appreciated but if there is a link I could take a look at, that would be appreciated as well, coz I need to learn not to bypass this issue only
 
heh
 
sql commands are very vage .
there is Join and JoinOuter ... or so I've heard lol
 
6:51 PM
@LoopingDev It's a wonder any of us cope
 
@LoopingDev it sounds as if one has to learn SQL to use SQL
 
I'm less inclined to call them "vague" an more inclined to call them "a pain in the butt" :-)
Circumvent this problem entirely by using an ORM instead of interacting with sql directly
 
They are using an ORM :P
 
Are they using it right?
 
Another job well done [dusts off hands]
 
6:52 PM
No
 
well
 
@Kevin that make sense, I can feel it sometimes lol
@AndrasDeak i thought I know, but apparently not everything.
 
Do you often know everything in a subject?
 
@Kevin lol
 
@LoopingDev I'm not prepared to write this for you. We've spent plenty of time on different things and I think you're starting to lean on the room too much. If you've heard of joins but don't know the different types, well... what's stopping you looking that up?
 
6:54 PM
I have eight years of experience with SQL but unfortunately it's just experience with the first weeks' worth of information, times 400
I'm really good at writing select * from thing;, I can do it with my eyes closed
 
Oh my
 
Lowercase SQL? What is this heresy?
 
Sorry, they don't teach style best practices until week 2.
 
it doesn't have injection vulnerabilities
 
Efficient, sleek, maintainable. Peak performance.
 
6:57 PM
@roganjosh that's fair, and hoesntly I did and I even watched couple of videos on the subject, but all they did they got me more confused, I'm not giving up thought but yeah I'm very thankful for the heads up, hints, tips .. etc, sometimes whenever I feel lost I think about the experts in this room, which happens quite often lol
 
SQL should be uppercase because it means the dev who wrote it was venting their frustration by - essentially - yelling at the DB. If you see someone write lowercase SQL, you know they haven't spent enough time with SQL yet.
3
 
@Kevin (It's precisely none of those btw)
 
ಥ_ಥ
 
@Aran-Fey LOL!
 
I'm so sorry
 
6:58 PM
@Kevin LMAO
i thought you wrote select * from everything lol
works everytime on every query , problem solved ^^
 
Very flexible 10/10
 
@LoopingDev youtube videos? Tiktok? Or some course?
 
youtube so far is my go to as there is usually a good competition there.
 
In my experience, good technical videos dry up when you get into more specialized topics, so it pays to get comfortable learning from text resources
 
7:03 PM
@LoopingDev just to be clear - if you give it a decent go then I will try to help if you're still stuck
But I don't think you're going to learn much from YouTube on this. You'll need the docs
 
I would also try to help, if I was provided an MCVE. But nobody has ever ever ever given me a proper MCVE involving sqlalchemy, so I'll probably continue to just give out corny aphorisms
Measure twice, cut once. You ain't gonna need it. Keep it simple. A bird in the hand.
 
@roganjosh appreciate it so much, I will get it done very soon and thank you so much for all the effort, I'll definitely jump back here if I got stuck again
@Kevin I appreciate it as well, thank you so much!, thought I did a very good MCVE example today though
or at least I think so :P
 
I'll go back and double check... Nope! Kevin's Marvelous MCVE Challenge still remains unclaimed :-)
 
so I think that is what I need to learn
https://docs.sqlalchemy.org/en/14/orm/tutorial.html#querying-with-joins
>>> for u, a in session.query(User, Address).\
...                     filter(User.id==Address.user_id).\
...                     filter(Address.email_address=='jack@google.com').\
...                     all():
...     print(u)
...     print(a)
 
Who will inherit my fantabulous chocolate factory B-plus quality tech support
 
7:12 PM
@Kevin hola
@Kevin please accept stackoverflow.com/a/20002504/918959 this here, so that whatever garbage gets written from time to time doesn't float to top :)
 
Yeah alright
 
That 2-upvote runner up was getting a little too close for comfort :D
 
@roganjosh the community wiki answer was on bottom when I read it today :D
default sorting is "active" :(
 
Oh wow, ok :/
 
Cbg
 
7:16 PM
cbg
 
@LoopingDev That does look like a promising approach. Your final code may end up a tad more complicated, since you have three tables instead of two (... I think?), but the basic technique should still apply
 
First day tomorrow in first dev job :-D
 
Excited? :)
 
More nervous
 
@Kevin yeah, but looks like I'm on the right page though ;)
 
7:17 PM
@Kwsswart What kind of information is your utility function taking into account? If it just gives a flat score for each of win, loss, tie, then it might not be able to choose a marginally better move over a marginally worse one
 
@roganjosh actually I do not know what's the default sorting order, I thought it is active, but seems to be votes. Even worse :P
 
For example, if it thinks it's doomed to tie, it might choose a move that locks it out a possible win against an imperfect opponent
 
Mine is always on votes. That has to be better than "active"? Active is just gonna dredge up an awful lot of crap on established questions (though that's not a bad thing if we can banish those answers)
 
well, you never get the good answer to the 10 year old question with Votes :(
 
Rock, meet Hard Place
 
7:21 PM
I'm not exactly sure how you'd assign a utility score to "leaving the opponent room to make mistakes", but if you can manage it, that would give some useful fidelity
 
@Kwsswart You'll be fine :) You've shown you're a quick learner
 
@Kevin essentially its calculating whether the board state passed is going to lead to a 1 0 or - 1 in order to assess which move would be best
@roganjosh thanks mate
 
@Kwsswart tictactoe?
that 3x3 game?
youth of this millennium...
 
@Kevin hmm thing is it is essentially aloting each board state along with all possible actions within that state and then for each of those actions recursively doing this again until a terminal state is achieved... Works perfectly without the added alpha-beta pruning just with it seems to change the results
 
don't you remember wargames
@Kwsswart it does not make sense to play 3x3 tictactoe with alpha-beta pruning
 
7:34 PM
@AnttiHaapala yeah busy trying to make the Ai play as good as possible without the backdraw of having to assess every single eventuality thus speeding it up
 
the only way you can win is if the opponent makes a mistake
alpha beta pruning assumes that the opponent is not doing mistakes :D
 
I know I'm not wanting to win lol
 
Basically when playing the Ai without it plays optimally but when adding the pruning as above it seems to make random silly moves that allows me to win... Which makes me think I am doing it wrong
 
I explained it above^
since all sensible plays of tic tac toe will result in tie, then it thinks all are equal :D
 
7:38 PM
Oh damn lol so what would be the best method to allow it to make decisions faster
Love that video lol
 
you have wrong game.
make algorithm for reversi for example. That is rather easy but it is a good game :D
it is also really easy to score, really hard to calculate 62 turns deep,
simple rules...
 
Perhaps will take a look into it lol trying to learn more about algorithms and how ai works
 
anyway alpha-beta pruning should work for tictactoe but...
@Kwsswart so if your algo starts, then your algorithm should start at corner.
 
no it doesn't....
essentially the entire algorithm without the board making its calls is here dpaste.com/HQBYP7SZT
If it goes first it goes center top usually followed by trying to corner until it ends in it having multiple options to win nomatter the more
Move
 
9:09 PM
yup
 

« first day (3830 days earlier)      last day (1110 days later) »