Archive for Software announcements

default_value_for Rails plugin: declaratively define default values for ActiveRecord models

We’ve just released default_value_for, a plugin for declaratively defining default values for ActiveRecord models.

Comments

daemon_controller: a library for robust daemon management

Phusion has recently released a library for robust daemon management. Check it out. Description and tutorials are available on that page.

Comments (2)

Passenger (mod_rails) 1.0.5 released

Passenger 1.0.5 has just been released. Please read the Phusion corporate blog for the announcement and upgrade instructions.

Comments

Beautifying Perl

I totally fell in love with Ruby ever since I started using it more than a year ago. The language’s syntax and constructs are very, very elegant (with a few exceptions… I’m talking about you, StringIO.new.is_a?(IO) == false). The ‘do’ blocks are simply brilliant, they make working with closures a breeze and aesthetically pleasing. Ruby’s Array, Enumerable and Hash classes make heavy use of this.

Compared to Ruby’s syntax, Perl’s seems like something from the 80s. Perl is often the target of “my-code-is-more-unreadable-than-yours-but-I-can-do-it-in-fewer-lines” jokes. I can write readable and maintainable code, but no matter what I do, it’s still nowhere near Ruby’s level. All the referencing and dereferencing of arrrays and hashes makes things ugly. %, $ and @ everywhere, urgh. And working with collections takes more code than in Ruby. I can’t tell you how many times I had to write stuff like this:

Perl
  1. my $foo_is_ok;
  2. foreach my $value (@foo) {
  3.    if ($value satisfies some condition) {
  4.        $foo_is_ok = 1;
  5.        last;
  6.    }
  7. }
  8. if ($foo_is_ok) {
  9.    …
  10. }

In Ruby I can just do:

Ruby
  1. if foo.any? { |x| …some expression involving x… }
  2.    …
  3. end

There’s List::Util but they deliberately left out the ‘any’ function because it’s “easy to implement”. Urgh. -_-

I write a lot of text parsers in Perl. And each time I have to manually strip newlines from a read line with:

Perl
  1. $line =~ s/[\r\n]//g;
  2. $line =~ s/^[\s\t]*//;

Seriously, why can’t I call ‘$foo->strip()’ or something like in Python or Ruby?
And print(). In 99% of the cases I want to print a newline as well, so I have to write print "$foo\n"; Why is there no puts()-like function that automatically prints the newline as well? It would save me a few keystrokes.

But no more. I’ve had enough. Enter the Peanuts library. Now you can write:

Perl
  1. use Peanuts;
  2.  
  3. my $array = Array(["hello", "world", "foo", "bar"]);
  4. puts $array
  5.         ->map(sub{ $_ . "!" })
  6.         ->findAll(sub{ /o/ })
  7.         ->reject(sub{ /f/ })
  8.         ->join(‘, ‘);

This would print “hello!, world!\n”.

Other Ruby-isms include:

Perl
  1. use Peanuts;
  2.  
  3. my $s = String("  hello world   ");
  4. puts $s->strip();       # => "hello world"; This is actually a new String object.
  5. puts $s->Strip();       # in-place version of strip()
  6. print "$s\n";           # => "hello world\n". A String object behaves like a regular Perl string.
  7.  
  8. my $h = Hash({ x => ‘y’ });
  9. $h->merge({ foo => ‘bar’, a => ‘b’ });
  10. $h->Merge({ baka => ‘baka’ });     # in-place version of merge()
  11.  
  12.  
  13. package MyClass;
  14. sub foo {}
  15. Package()->aliasMethod(‘bar’, ‘foo’);     # Now we have an alias! No ugly Perl symbol table messing syntax!
  16. Package()->chainMethod(‘foo’, ‘trees’);   # Like Rails’s alias_method_chain; now
  17.                                           # we have foo_with_trees() and foo_without_trees()

The source code is at this SVN repository:

http://public.railsplugins.net/repos/peanuts/trunk

It is licensed under the MIT license.

Comments (5)

Mikuru 1.0.0 released


Mikuru – named after Asahina Mikuru from The Melancholy of Haruhi Suzumiya – is an extremely simple image gallery generator. Its key features are:

  • Easy to use and easy to set up.
  • No dependencies on databases.
  • The generated gallery has a simple, to the point, quick and easy to user interface.

I wrote this because I went to Abunai last weekend, and I took 150 pictures. I didn’t feel like setting up a full blown gallery system such as Gallery, so I wrote this simple fire-and-forget image gallery generator.

How does it work?

You put a bunch of pictures in a folder, run Mikuru, and it’ll generate an ‘index.html’ as well as a set of thumbnails. There are no other generated files. Simply upload index.html, the thumbnails and the pictures to a web server, and you’re ready to go.

Here’s an example usage session:

$ ls
DSCN001.JPG   DSCN002.JPG   DSCN003.JPG
DSCN004.JPG   DSCN005.JPG   DSCN006.JPG
$ mikuru
MKDIR      thumbnails
WRITE      thumbnails/DSCN001.JPG
WRITE      thumbnails/DSCN002.JPG
WRITE      thumbnails/DSCN003.JPG
WRITE      thumbnails/DSCN004.JPG
WRITE      thumbnails/DSCN005.JPG
WRITE      thumbnails/DSCN006.JPG
WRITE      index.html
$ scp -r * www.somehost.com:public_html/my_gallery/

How does it look like?

Click here for a demo image gallery.

Download

Version 1.0.0
Requires Ruby and RMagick.

Comments