« first day (4939 days earlier)   
05:00 - 13:0013:00 - 20:00

5:37 AM
Do we have a good dupe target for "update on a hashlib hasher object is for streaming data to hash, not for computing individual hashes"?
 
6:05 AM
5
Q: Strange python's hashlib.md5 behavior, different hash each time

Mikhail F.I've faced some really strange behavior trying to calculate md5 hash of string. Returned hash is always wrong (and different) if I pass string that was result of concatenation. Only way to get real hash I've found is to pass string that wasn't modified in any way after creation. Python 2.7.13 (v...

 
That looks good! Thanks.
 
while at it, here's a dupe that I don't have the python-3.x hammer for stackoverflow.com/questions/53723619/…
 
Hammer applied.
 
 
3 hours later…
9:21 AM
means = [nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 0.692323603997432, 0.7859046968489375, nan, nan]
baaaaatman xD
 
 
3 hours later…
12:10 PM
I'm trying to implement units, and the static typing is... a challenge. Is it possible to achieve this?
t: Time = Minute(10)  # Valid, "Minute" is a measurement of "Time"
print(t.to_number(Second))  # Valid, outputs 600
print(t.to_number(Time))  # Invalid, Time is "abstract"
 
I don't understand. Why would you call a function and pass just a type?
 
IIRC recent typing knows the difference between "type" (like int) and "type form" (like Number). Not sure if that's released already, though.
 
@roganjosh In order to convert a Time to a number, you need to specify a unit. Do you want seconds? Minutes? Hours?
 
Even so, what would one expect t.to_number(Time) to give?
 
An error, that's why it's invalid :D
 
12:17 PM
Or is that a shorthand for the typing issue rather than actually how it would be called?
 
Oh man, t in Seconds would be a neat syntax instead of t.to_number(Second), but the type checker veto'd it :/
 
huh, that would indeed be pretty neat for type conversions
FWIW, practically I would use a union here, since you need to implement each conversion anyway. But that's probably not useful for your concrete usecase?
 
I think the syntax would be "as" not "in" but it would be nice syntax
 
Can you have a separate protocol for concrete types? Presumably, if you go for automatic conversion they need some metadata such as how many base-units they express.
The abstract type won't have that.
 
@MisterMiyagi Ideally I'd like to make it possible for users to define their own units without too much boilerplate, so I'm trying to make the code as reusable/generic as possible. But yeah, a Union is indeed starting to look like a good idea
 
12:26 PM
class P(Protocol):
    factor: ClassVar[int]

class Minutes(P):
    factor = 60

def to_nums(seconds: int, unit: type[P]) -> P: ...

to_nums(100, Minutes)
to_nums(100, P)  # Argument of type "type[P]" cannot be assigned to parameter "unit" of type "type[P]" in function "to_nums" "P" is not a concrete class type and cannot be assigned to type "type[P]"
This works for PyRight at least.
MyPy also does it right. Only concrete class can be given where "type[P]" is expected
 
FWIW if you're using units like "Second" then my favourite approach would just be to make it unitless. (I mention Second in particular because it looks like you don't know the precision needed). Jsprit (the vehicle routing library I worked a lot with) does this - your application sets the reference time unit when you call it
IOW you could have every time integer being 1 second, 1 hour, 1 day, whatever. It's your responsibility to keep your units consistent in your code that calls into the library. It just sees "10" when it gets passed to the solver
 
@MisterMiyagi Interesting idea, I'll play around with it
 
@roganjosh And thus the user defined leap was born. ;)
I'm kidding, of course. No idea how you folks manage to deal with real clocks.
 
@roganjosh This is for situations where the units actually matter. Like time.sleep() for example. You wanna sleep for 5? 5 what?
 
Ah, yeah, then it's totally different if you have to make system calls that another library understands. Outside of that, though, I loved the flexibility of the jsprit idea of just making things unitless for the solver. I had multiple different systems running, some in units of seconds for fast-paced, high-density delivery companies, and others running in minutes for long-haul. Same library, just a flick of a Config param in my own code. All it wanted was integers
 
12:37 PM
@Aran-Fey 5 chicken drum sticks, please!
 
@roganjosh Yeah all code should be unitless for sure. We assume SI units everywhere and note it in the variable name if it is not in the appropriate SI unit
 
That's literally how you blow up rockets.
 
@MisterMiyagi Well only if you work with people who stubbornly cling to stupid standards :)
 
SI units are super practical for everyday life, but they are by no way always the correct unit.
 
@MisterMiyagi True
 
12:44 PM
As a genuine question, do you think that typing could have stopped the rocket explosion? I think no. There is an off-chance but any number of numerical mistakes could have been made in the process
 
The only reason I can see for other units to be used is for numerical precision, which would make very small or very large base units necessary
Are there other reasons?
 
International collaboration
 
@roganjosh I don't understand?
That's what the SI units are for
 
@roganjosh Typing can't fix every problem. But so far it has been very good at catching my footgun science projects.
 
But I don't think the presence of an elaborate Enum or strict typing checks alone will ever fix the issue
@Hakaishin I mean, that's your ideology. Our US counterparts might not quite agree that SI is the best unit, or one they would naturally code in
 
12:51 PM
Meh, if the whole world is ok with writing english code even though english isn't their mother tongue, then the 'muricans can handle using SI units
 
@roganjosh Lol calling SI units an ideology is so unhinged that I don't think we should continue talking
 
There's a slight problem in the fact that the UK still uses miles as a measurement of distance, and mph in measuring speed. (And pints at a bar, the consumption of which helps confuse things futher) :P
@Hakaishin ok
 
05:00 - 13:0013:00 - 20:00

« first day (4939 days earlier)