Padrino Routes Accept Regex URL Map

As Sinatra, Padrino route definitions accept regex when used as the :map option’s value in named aliases.

A standard named alias (‘thisroute’) mapped to some url with a code parameter embedded in the URL:

# For URLs like /someslug/anytext
get :thisroute, :map => '/someslug/:code' do
  # code param available as params[:code]
end

Accessing it as a block parameter, like in Sinatra, is also possible:

# For URLs like /someslug/anytext
get :thisroute, :map => '/someslug/:code' do |code|
  # code param available as request scope variable named code
end

And the killer one, if we want to enforce a pattern to the parameter, we capture it in a regex (suppose we only want to allow digits for that parameter, one or more), like this:

# For URLs with digits in param., only e.g. /someslug/123
get :thisroute, :map => %r|/someslug/([\d]+)| do |code|
  # code made of digits captured by regex available as code var.
end

Behold! And YES!! The first capture (text matched by the regex portion inside the parenthesis – the regex syntax element which delimits a capturing group) is available as the first block parameter, super conviniently! Now go enjoy it, and boost up your Padrino application routing!

GNU Screen Howtos and Tutorials

Check these good links out. They are about the extremely powerful GNU Screen tool (the screen command):

To install it on Ubuntu execute the following commands:

$ sudo apt-get update
$ sudo apt-get install screen

Simple Spell Check on Linux

The file /usr/share/dict/words contains an english dictionary so search for your term like this:

$ grep tige /usr/share/dict/words

Output example:

antigen
antigen's
antigens
prestige
prestige's
tiger
tiger's
tigers
vestige
vestige's
vestiges

This file is very comprehensive as you can see from this example:

$ wc -l /usr/share/dict/words

Output example:

98569 /usr/share/dict/words

Ruby Numbers

Numbers in Ruby can be of 3 types (classes). Integers are represented by the classes Fixnum and Bignum. Values between -2^30 and (2^30) – 1 are of type Fixnum and numbers not in that range are Bignum objects. Ruby assigns the type automatically. The remaining class is Float. When using scientific notation you must place the zero after the dot otherwise in e.g. 1.e3 Ruby will try to call the method e3 on the Fixnum object with the value of 1.

You can represent binary numbers, octal, and hexadecimal by respectively starting the literal with 0b, 0, and 0x. Decimal numbers can receive the optional prefix 0d.

Integer (Fixnum and Bignum) numbers have methods, as they are objects. You can call methods such as abs (absolute value), zero? (returns true if the object has the zero value) etc. as available in the Ruby API Documentation.