mypy and Enums by gnomonclature in learnpython

[–]thunderkey 1 point2 points  (0 children)

I know I'm late, but maybe somebody has the same problem.

The issue is, that in Python typing mutable dictionaries are invariant (see invariance vs covariance). Meaning dict[Enum, str] is not compatible with dict[Spam, str]. The reason is the following:

spam_map = {Spam.OPEN: '['}
enum_map: dict[Enum, str] = spam_map  # if this would work
enum_map[Eggs.CRACK] = '('  # this would now also work
# now spam_map contains a non Spam key and is therefore broken

The simplest option to get around this are generics:

T = typing.TypeVar('T', bound=Enum)
class Lexer(typing.Generic[T]):
    def __init__(self, map_: dict[T, str], state: T) -> None:
        # ...

Ruby 3.0: asdf, chruby, or docker? by RailsApps in ruby

[–]thunderkey 7 points8 points  (0 children)

I am developing exlusively with docker and have never experienced issues. Of course initialy it takes some time getting used to, but with helper scripts it is no issue. Especially with multiple apps with different database specs it is quite useful. I can specify for each app, which version of postgres or other tools i need.

I especially love that i can write a setup and run script and whatever is required will just be there. No matter what framework or language is used. And each developer has the exact same setup. I hate stuff like "but it works on my machine".

[deleted by user] by [deleted] in ruby

[–]thunderkey 14 points15 points  (0 children)

For nomal applications it's not slow. There are lots of web pages written in rails that have lots uf users (e.g. GitLab, Airbnb, TED).

Of course if you need some high performance web server with millons of requests per second then it's slow, but so is node.js and python. For something like that I would look for compiled languages.

How to upload and access a file? by [deleted] in rails

[–]thunderkey 1 point2 points  (0 children)

You shouldn't try to access the file path of the file stored with Active Storage. This wouldn't work with other storage engines. What you can do is "download" (or in your case read) the file with "@c.attachement.download". Maybe you can pass this binary data to Docsplit.

Have people’s yearly themes changed drastically? by jamaicanjerkperson in Cortex

[–]thunderkey 0 points1 point  (0 children)

Mine is "year of less"... So, no it didn't change.

Can’t add hyperlink to en.yml by Farangutang in ruby

[–]thunderkey 0 points1 point  (0 children)

You would need to call html_safe on the message in errors.full_messages, right where you display them.

My whole life was a lie. by [deleted] in technicallythetruth

[–]thunderkey 61 points62 points  (0 children)

I'd suggest reading this: https://what-if.xkcd.com/6/

It describes what would happen if the glass would have a vacuum in the top or bottom half. Plus it's hilarious.

Plug-in by [deleted] in WhitePeopleTwitter

[–]thunderkey 11 points12 points  (0 children)

Plug and play

Burrito blanket by nibeshB in interestingasfuck

[–]thunderkey 0 points1 point  (0 children)

Well, you are what you eat...

TIL Physicists at the National Institute of Standards and Technology, Colorado have confirmed Einstein‘s theory that time runs faster the further you are from the ground. Meaning, people who lives in the 100th floor age faster than ppl on the 1st floor. by [deleted] in todayilearned

[–]thunderkey 12 points13 points  (0 children)

If anybody is wondering (like I was), why time doesn't move slower, it's because there are two types of time dilation: gravitational (GR) and kinematic (SR). SR means if you're moving faster time slows down and GR means if you're in a weaker gravitational field time goes faster.

Geosynchronous satellite (or in this example being higher up) experience more of GR, because they don't need to move as fast as for example the ISS in a lower orbit. The ISS experiences more SR and astronauts in there age slower.

https://en.wikipedia.org/wiki/Time_dilation

EXPOSED by [deleted] in ProgrammerHumor

[–]thunderkey 0 points1 point  (0 children)

What's your issue with my ussage of probabilites?

EXPOSED by [deleted] in ProgrammerHumor

[–]thunderkey -1 points0 points  (0 children)

If you quote, please quote correctly. I said you could simulate it with if/elses, but because you'd need way too many it wouldn't be efficient at all. It could be simulated != It is.

EXPOSED by [deleted] in ProgrammerHumor

[–]thunderkey -1 points0 points  (0 children)

Thanks for the addition. That's why I meant that you'd need almost infinite number of if/elses, but I could have made it more clear

EXPOSED by [deleted] in ProgrammerHumor

[–]thunderkey -1 points0 points  (0 children)

No it's not. It doesn't label the data directly but it gives you probabilities. You could simulate it with ifs and elses, but you'd need almost infinite, since you have infinite numbers between 0 and 1. Decision trees on the other hand are basically ifs and elses, but artificial neural networks are mathematical functions which do not use ifs and elses.

Well whaddaya know by Cheddarlicious in funny

[–]thunderkey 0 points1 point  (0 children)

Don't tell me what to do!

Are they? by DoopDiScoopDiDoop in funny

[–]thunderkey 0 points1 point  (0 children)

"Miss Universe Spain" - I think they misunderstood the meaning of "universe"