Articles tagged “ruby”
Binding 80/TCP as non-root on your development server

neo-tux by sagarkshetri.com.np
So you have a Linux VM you use for development, because you want to mirror the production environment as closely as possible. You have many applications to deal with, they have to be running at the same time because they are nifty REST JSON web services.
You are very tired to remember which one you put on port 8081
, and your configuration files slowly become a real mess. So you set up IP address aliases in for the network interface and decide to assign even host names – /etc/hosts
is just fine – for each app.
Then, in such a setup, why would you still need to run them on ports higher than 1024
? Wouldn’t be just great to type the application name in the browser address bar? Indeed it is, but it’s better to not run them as root
, anyway.
The solution are Linux capabilities (see also here). The one that interests us is cap_net_bind_service
: it gives a process the right to bind well-known ports (< 1024
). If you use an interpreted language, of course you’ll have to add the capability to the interpreter itself. That’s why there’s development in the title of this article – you should not set this up on a production server, if you don’t know what you are doing.
One final quirk: if you happen to dlopen()
shared objects that dynamically link towards libraries outside the canonical paths, you cannot load them via LD_LIBRARY_PATH
(e.g. the SYBASE.sh
) as it is ignored for setcap
-ped processes. You should better move the library paths into an /etc/ld.so.conf.d
snippet.
tl;dr
Assuming you are the latest and greatest rails developer, you should become root – or use sudo, as you wish – and
# YOU ARE ON YOUR DEVELOPMENT MACHINE setcap cap_net_bind_service+ep `which ruby`
Profit:
thin start -a yourapp -p 80 >> Using rack adapter >> Thin web server (v1.2.11 codename Bat-Shit Crazy) >> Maximum connections set to 1024 >> Listening on yourapp:80, CTRL+C to stop ...
Rome RSC 2011
Thanks to @jodosha efforts and praising the former Javaday event, now renamed into codemotion that brought in Rome many Ruby developers from Milan, Padua and other parts of Italy – the first official Ruby Social Club in Rome has been a great success. Of course, officialty is measured only in the amount of twitter spam posted about it! :-): earlier RSCs in Rome go back in time to 2006 organized by current mikamai members and more meetups promoted by @jeko in 2007.
What matters is that there's a community, there's a passion, and there's love to share knowledge - no matter who holds the meetings, the important thing is that they're being held :-).
The event was simple and direct - some beers first, then my keynote on RVM and Ruby interpreters, then Luca's one announcing his minege.ms project and after real social networking :-). I met @gravityblast after much time we didn't meet, knew the PIP group and met @svarione, @punkmanit, @leonardoperna, @riggasconi @ogeidix and other smart people. Moreover, we spent quite some nice time together, making up a really lousy and funny week-end.
Of course, huge kudos to @nhaima's car - that tirelessly carried us around Rome for two days :-)
Now, looking forward to the next meetup, thanks everyone who participed, who offered me beers and, last but not least, thanks to @etapeta for bringing me in time at the meeting - you're the real hero :-).
Panmind spin-offs presented at Ruby Social Club Milan
On July 22nd 2010, Mikamai hosted a Ruby Social Club in Milan, where nearly 50 people attended watching five speeches about Ruby, Web development and Startups. I was glad to be one of the speakers, and I presented a set of Rails plugins we spinned off from our latest (and greatest) project: Panmind (read more on the about page) and released as Open Source on GitHub.
The keynote is split in two parts: the first one explains why you should follow the sane software engineering principle of writing modular and interest-separated code and then how you could (and should) extract it from your Rails application by decoupling configuration and then prepare for the Open Source release, by writing documentation AND presenting to a Ruby event so, hopefully, someone else will write unit tests! :-)
We released an SSL helper plugin that implements filters (like Rails' ssl_requirement) but also named route helpers: no more <%= url_for :protocol => 'https' %>
! You'll have something like plain_root_url
and ssl_login_url
- like they were built into the framework.
Then, a Google Analytics ultra-simple plugin, with <noscript>
support, a couple of test helpers and an embryo of a JS Analytics framework - hopefully it'll evolve into a complete jQuery plugin. Then, a ReCaptcha interface, with AJAX validation support and eventually a Zendesk interface for Rails.
We released also more code on Panmind's GitHub account, including the nifty AJAX Navigation Framework that implements all the boilerplate code for the ultra-fast AJAX navigation of panmind contents and projects.
The keynote follows, you can download it in PDF (no exploits, I swear! :-) from this link or view/comment it on slideshare here.
Final words: check out mikamai blog post on the Ruby Social Club to read the other keynotes (I will, hopefully, update this post with sum-ups of them when time permits :-)) and say hello on twitter or on GitHub if you're interested in contributing our open source projects or you want to work with us.
Spent my day on Erlang-Ruby-Marshal today ;-)

In a nutshell, it adds support for unmarshaling 1.9 strings, and implements the last missing type (TYPE_LINK
) that was missing from the code. Tests still lack, can someone help ? :-)
Added TYPE_LINK, needed because of how ruby 1.9 marshals strings.
In 1.9, Ruby marshals the string encoding in the binary output, and
uses an Ivar construct (TYPE_IVAR) to wrap the string and adds an
"encoding" instance variable (notice: without a leading @) whose
value is the encoding itself.
While the Ivar code worked correctly, the values of the encodings
are actually *strings*, that are being reused via the TYPE_LINK
construct, that wasn't implemented.
So, the get() and put() primitives are being used to store not
only tuples {id, sym} for symbols, but now store either
{{symbol, ID}, sym}
OR
{{value, ID}, val}
for the other types that use TYPE_LINK.
By reading the ruby marshal.c source code, it looks like that MANY
data types save their values in the arg->data hashtable, but by
inspecting the binary marshal output of, e.g, an array of floats,
links aren't used.
Thus, in this unmarshaler, links are considered, for now, only for
strings and regexes.
Fork me on GitHub: http://github.com/vjt/erlang-ruby-marshal
Rails3: Better, Faster, Stronger

For those who understand italian, I’ve just published an article on therubymine.com on the upcoming Ruby on Rails framework release, version 3.0: the big news is the merger with another ruby web framework, merb.
Have a nice read! :-)
http://therubymine.com/2009/06/04/rails3-better-faster-stronger/
Implementing an image gallery using facebox and will_paginate
On VisitaCSA we’re using defunkt’s facebox to show places images at large. Facebox is a great general-purpose lightbox, because it is fast, stable, is based on jQuery and has got a really clean API.
But we needed more than a simple display lightbox, because we wanted our users to navigate easily between all images, possibly without modifying facebox at all. The solution turned out to be pretty simple, thanks also to the will_paginate plugin we were already using. It all burns out to have:
- A Photo model, instrumented with the
has_attachment
method - Resource routes for photos (
map.resources :photos, :only => :show
inconfig/routes.rb
) - A
show
controller method in thePhotosController
that calls.paginate
with a:per_page
argument of 1 - An HTML view for the photo resource, that has pagination controls using the
will_paginate
helper - Some jQuery code hooks onto the pagination links and make the browser load via AJAX the next photo directly into the facebox.
Continuous evolution
releases$ du -sch *
7.6M 20081209132347
7.0M 20081209133350
7.6M 20081209144343
7.1M 20081209145133
7.1M 20081209151843
7.1M 20081209163013
7.1M 20081209175506
7.1M 20081209183553
7.1M 20081211122939
8.6M 20081212190026
8.3M 20081212201852
8.3M 20081212203943
8.3M 20081212205430
8.3M 20081213014847
8.3M 20081213020357
8.4M 20081213163428
8.4M 20081213173633
A permalink_fu improvement: allow modification of permalinks and send HTTP redirects on-the-fly
Another spin-off from the www.visitacsa.it website: a permalink_fu improvement that allows dynamic permalinks. I know it is an oximoron, because permalinks should be .. well .. permanent! And because search engines index them, they should never change. But what happens when you publish something, your permalink is generated with permalink_fu using the title of your post, and after a couple of days you want to change the title, and the permalink under which the post is accessible as well?
Following the specification, your app should send out a 301 moved permanently HTTP status when accessing the old permalink and redirect the client to the new Uniform Resource Locator. That’s quite the same thing what my modification to permalink_fu does: whenever your post attributes are changed, the former and new permalinks are saved to the database, and you can enable your controller to generate 302 moved temporarily redirects when needed. In other words, it checks whether the requested URL is an old permalink, and automagically redirects the client to the new one.