I really like the concept of Fortune Cookies in *nix systems, and I absolutely love the Hindi movie Andaz Apna Apna. So, I thought I would write up a simple fortune-cookie server which serves random quotes from the movie. A lot of my friends liked it.
So, I thought it will be even nicer if I could generalize it, and add a bunch of other movies and TV serials, that are popular. So I wrote up Elixir, which is a generic fortune-cookie server written in Go. This new fortune-cookie server was hosted on rand(quotes), and had quotes from movies like Quentin Tarantino’s movies, Lord of the Rings, and the popular TV shows Breaking Bad, and Game of Thrones.
Using Elixir, it is extremely simple to write a fortune-cookie server which serves quotes from multiple quote databases. All you need to do is create the a file that contains the quotes you want to serve, one per line, and give it a name like
foo.quotes. Place it in the directory where the server was started from, and those quotes would be serve from the
To make it more fun,
/foo?f=cowsay returns the quote in the cowsay format! Something like this
1 2 3 4 5 6 7 8 9 10
You can create many such quotes databases, and also add/delete/modify them while the server is running, and the server will pick up the changes.
A full-featured fortune-cookie server would look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
Implementation Note: To implement the feature of keeping tab on the quote databases, without having to restart the server, one way was to use the Inotify subsystem in Linux, using Go. But this didn’t work for OSX. So I wrote up a quick and dirty implementation which does
ioutil.ReadDir(".") periodically, and filters all the files which have a