Sometimes Python makes some useful things unnecessarily complex for weird and inconsistent reason … e.g. “code blocks.”
Daniele Procida explores how a certain naivety (being unsophisticated) can lead to beautiful and useful things.
Update 2021-08-15: the original video from DjangoCon 2018 is not available any more. It seems Daniele gave a similar talk at EuroPython 2018 also.
Dan Luu has a nice collection of interesting Hacker News posts.
@something ||= SomeModel.create_with(some: "stuff").find_or_create_by(foo: "bar")
This will either find a record
or create it with
SomeModel.create(foo: "bar", some: "stuff")
. Very useful.
found = ModelA.find_by(id: id) || ModelB.find(id)
I stumbled over this during a code review. It was supposed to look for a record in two distinct tables.
if nothing was found while
. Hence either you get something (from any model) or you
This is a great idea. ?
This is so moronic I almost fell off my chair laughing: it seems like the TSA spent $47,000 on a “random lane picker.” Please, you be the judge whether it was worth it:
It needs to be operated manually … with hygienic gloves! ?