Dimitar Kostov ramblings

Explain Ruby - Ruby syntax explained

Paste Ruby code or a URL to get Ruby syntax explained.

Explain Ruby will not be able to explain what the code in question does, i.e. the original author’s intent, but it will help newcomers to Ruby to learn how to read code by teaching them programming constructs of the Ruby programming language.

Introduction to ZeroMQ

Intro

Last week I was looking at ZeroMQ mostly because of Mongrel2. Reading the documentation, turoials and examples I decided to write series about ZeroMQ only because I want to clear out some things for me. I always said that I write crappy blog posts, because I want to remember stuff I’ve used/found interesting. Another reason is that I have to dig in the object of the post. The series will include different things about ZeroMQ: transport, infrastructural and messaging pattern choices. But before we start …

A few things about the series:

  • I’m not professional programmer
  • I really like UNIX stuff, but I haven’t had time to dig in
  • I’ll be using Ruby for the examples, because I’m familiar with it and the code can be read and understood by anyone (hopefully)
  • This series are shallow and I want to show the basic usage of ZeroMQ
  • Any suggestions are welcomed :)

So here we go

When I try to write some network application code, I have to choose between low-level API ( Berkeley Sockets ) or some kind of high-level messaging protocol like AMQP(and implementation of that protocol like RabbitMQ messaging system). Being low-level sockets are hard to use and there is a lot of stuff I have to handle by myself(buffering, error handling, etc.). On the other hand AMQP gives me great power, but I lose some scalability and flexibility. And in the middle is ZeroMQ.

The best explanation of ZeroMQ I found comes from Zed Shaw:

What ZeroMQ ends up being is “sockets the way programmers think sockets work”. 

ZeroMQ is minimalistic, powerful, scalable, fast and transport agnostic networking library which gives me the ease of using “human-face” sockets. There are bindings for 20+ languages including C, C++, Java, .NET, Ruby, Python etc. It’s transport agnosticism enables me to use TCP, IPC, INPROC and PGM very easy. Being message-oriented ZeroMQ handles all the work for me (like load balancing messages) and leaves to me the choice of message pattern (REQUEST/REPLY, PUBLISH/SUBSCRIBE, Pipeline, PAIR).

The series

I know there are a l1ot of buzzwords, but I’ll try to explain them in the series:

Installing ZeroMQ and zmq gem

The instructions how to get and compile ZeroMQ are on their web site.

In the examples I’m using zmq gem:

[sudo] gem install zmq

Feedback

Feel free to smack me in the face at mitko.kostov[at]gmail.com if you find some rubbish statement.

IRB tools

If you’re playing with IRB often like me, you should try awesome_print and interactive_editor. The first one gives you pp on steroids - a beautiful coloured printing in IRB.The second one gives you the power to invoke your favourite editor (vim, emacs, TextMate), write code and when you exit, your code is evaluated and ready to be used in IRB.

Ruby VM Shootout

After releasing version 1.0 of Rubinius and JRuby hitting 1.5, I decided to test these great VMs against ruby 1.8.7 and the latest 1.9.2 to see how they perform. This benchmark uses Antonio Cangiano’s ruby-benchmark-suite. I’ve posted part of the results as image, you can find all results as pdf. Tested versions of ruby, using RVM

are:

  • Rubinius 1.0.0 (1.8.7 release 2010-05-14 JI) [i686-pc-linux-gnu]
  • jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) [i386-java]
  • ruby 1.9.2dev (2010-05-20 revision 27928) [i686-linux]
  • ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]

My software:

  • Ubuntu 10.04 ( linux kernel 2.6.32-22 on i686)
  • Java VM - OpenJDK Client VM 1.6.9 18
  • File System - ext4

My hardware:

  • Intel Dual-Core T2080 @ 1.73GHz
  • RAM - 2x512MB

My comment: I don’t understand how VM works and how they are implemented, but looking at the results I can say that Rubinius and future 1.9.2 show real progress and great perspective. 

As a disclaimer I will quote Antonio Cangiano :
“Synthetic benchmarks cannot predict how fast your programs will be with one implementation or another. They provide an (entertaining) educated guess, but you shouldn’t draw overly definitive conclusions from them. Furthermore, the Ruby Benchmark Suite has many tests that don’t provide much insight when it comes to comparing implementations. They are there for legacy reasons and will probably be removed in the future. For the time being, take them with a grain of salt.”

Oh my zsh !

If your’re looking for a framework for managing zsh configuration, oh-my-zsh is your thing. It supports auto update, auto completion, git integration, very cool themes and more. You can install it with cloning the repo or via simple command:

wget http://github.com/robbyrussell/oh-my-zsh/raw/master/tools /install.sh -O - | sh

This is how it looks while playing with git:

Express - Sinatra for Node.js

Almost from the first release Sinatra has inspired lots of mini web frameworks in many programming languages with its simplicity. And if you’re in the hype for Node.js like me, Express may be the choice for creating simple service oriented web apps using JavaScript. Here is the “Hello World” example using Express:

Ring - Rack for Clojure

If you’re looking for something similar to Ruby’s Rack or Python’s WSGI, but for Clojure, take a look at Ring. The simple unified API allows easily constructing web applications with modular architecture. At this moment two adapaters are supported: Jetty and Apache HttpCore webserver.