Canned has been updated
I have used canned for some time now to aid my development of apis, and over time some things arouse which made it worth to add some features. If you want to know more about canned check out the introduction
Changes canned 0.1.0
- better error codes, a not found is actually 404 now not 400
- better content type handling, html is now returned as text/html
- support for comments in json, so documenting api responses can be done inline
interested install the new version via
$ npm install canned
And checkout the the repo
Daemons and output in ruby
Backgrounding a process in ruby is easy, just add
This works great but by doing so you will actually lose any output since daemon will redirect stdout and stderr to /dev/null by default. Depending on how you handle logging this might actually not be a great idea, I personally prefer redirecting the output of a daemon process myself so I can add logging easily.
This is easily solve so by passing both parameters for daemon, first to either do or don’t change the working dir to / and the second to not redirect stdout and stderr.
Process.daemon true, true
Just a nice thing which is quickly overlooked.
Using zeus without rails
At the last rubyshift the question came up if zeus could be used without rails, and how to do it. At the time I kind of expected it to be but wasn’t sure if there are any complexities which I didn’t see at the moment because I never tried it. So trying it out it actually works allmost as expected, the only thing needed is a modification to the custom_plan.rb file which defines how the preloading actually works. So just as a quick example I setup a repository which defines 2 tasks
$ zeus rake $ zeus foo
This should get everybody started, as the tasks are pretty obvious and easily modified for your needs.
Rubyshift May 2013, fast rails with zeus
The slides are now up , so I’ll welcome any feedback.
Working with CSV in SQLite
Recently I came across a csv with some reports I needed to work with, and since it was quite a lot of data I wanted some sane way to query it, so I remembered a neat little trick I discovered together with @leif time ago.
Without much hassle you can make sqlite import csv
get the name for the columns, this can be done in most cases simply via
$ head -n1 mycsv.csv > foo,bar,baz
create a table in sqlite to import into, the column names are just copy and paste (for persistence pass a db file name, but this is optional)
$ sqlite3 mydb.db >> create table mycsv(foo,bar,baz);
Still in sqlite import the csv
>> .separator ',' >> .import mycsv.csv mycsv
That’s it, since sqlite actually does not care about the types unless you want it to this works for about any csv. Now you can use the power of SQL to work with the data from the csv.
Just a nice little trick to make working with csv data just a little bit nicer