I knew there was AR’s
method but I didn’t know it had a very useful companion
@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
Very entertaining talk about some of Ruby‘s quirks. 😀
I just felt the need for a script that could extract the audio track of a video, transcode it and save it as an mp3 file … 2 hours later I was finished (get the Gist). 😀 It uses VLC to do hard work. 😉
Thanks to Kris Hom for the inspiration. 🙂
- Check whether VLC is installed
- Should also work on Linux now
- Increase default bit rate to 192kbit/s
- Fixed bug where the file/playlist would repeat endlessly
- Also look for VLC in “~/Application/”
I take my head off to Jim, that’s a great way to approach a weird intersection of mathematics and programming. 😉 For those who are curious … he uses a very simple mathematical algorithm to explore how you can express recursions in Lambda calculus and thus “derives” the Y combinator.
Totally useless, but worth every minute. 😉