Posts Tagged ‘tip’

How to quickly print certain lines of a huge file by number


If you have to work with huge text files, you know that most editors as well as less are very slow at jumping to a certain line in the latter part of a large file. Turns out that GNU sed is very good at it, although it will of course not replace an editor. For most people at least, those who write Tetris in sed will probably be fine.

$ wc -l uniprot_sprot.dat
31510440 uniprot_sprot.dat

$ time sed -n '30000000p' uniprot_sprot.dat
real    0m8.982s

$ time sed -n '29999900,30000000p' uniprot_sprot.dat
real    0m9.242s

Mailtrap with JRuby


Mailtrap, a mock SMTP server in a few lines of Ruby, doesn’t work with JRuby out of the box. One of its dependencies, the Daemons gem, uses fork which JRuby doesn’t implement as it’s not safe on the JVM:

$ mailtrap start
/work/software/jruby-1.2.0/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `safefork': fork is unsafe and disabled by default on JRuby (NotImplementedError)

My quick and dirty workaround was to simply ignore the daemon part and instantiate a non-forking instance of mailtrap running in the foreground:

$ jirb
irb(main):002:0> load 'PATH/TO/jruby/lib/ruby/gems/1.8/gems/mailtrap-0.2.1/lib/mailtrap.rb'
=> true
irb(main):003:0>'localhost', 5555, false, '/tmp/mailtrap.log')

You now have a Mailtrap running on port 5555, and see arriving messages right there in your IRB window. That should be enough for simple tests during development.

EXIF metadata and iPhoto 6


I might be behind the times, but for people stuck with iPhoto 6, here’s a quick guide to getting your photo titles, keywords, comments, and a copyright notice into the EXIF header of your image files.

The AppleScript that works for me is from Andrew Turner. I modified it as described in this comment to enable apostrophes in keywords. In addition, my installation of exiftool from Fink only works from AppleScript when giving the complete path and the location of its libraries, like this: PERL5LIB=/sw/lib/perl5 /sw/bin/exiftool. Also, don’t forget to change the copyright notice at the top.

Save the script in ~/Library/Scripts and make it available by checking “Show Script menu in menu bar” in AppleScript Utility. Now you should be able to select photos in iPhoto and run “Set Exif Data” from the AppleScript menu in the menu bar on them.

By the way, if you’re stuck with iPhoto 6, you almost certainly want Ken Ferry’s excellent Keyword Assistant for iPhoto.