Archive for the ‘Ruby’ Category

New Gem Released

Tuesday, August 26th, 2008

New ? Ah… not really. Would be fond to say that TLS support for ActionMailer is new. Anyway we packed up the code which is floating around on the web to add TLS support to pre Ruby 1.9 projects. Just for convenience. Find it on github.

The Ruby Language Will Reach 4 Million Programmers by 2013

Wednesday, August 20th, 2008

I missed this when it first came out. Gartner sees Ruby as a mayor player for the next five years. Unfortunately, Gartner sells the content they’re producing so normal people don’t get to see it. I came across a german translation where the main points are

  • 4 Million Ruby programmers by 2013
  • Focus on Convention over Configuration gives impressive functionality to developers
  • Rails-Framework is currently the killer app for ruby, other applications will follow
  • Domain Specific Languages will be the strongest attractor for professional developers
  • Tools will mature over the next year

There’s a graph of it somewhere on the web:

Gartner Ruby

Findings: The Ruby Language Will Reach 4 Million Programmers by 2013

Techworld - Ruby faces off against PHP, Java

Ruby Is on the Rise - Application Development

rwebthumb RubyGem updated

Tuesday, August 5th, 2008

We’ve added support for the Easythumb API to the rwebthumb gem. Just grab the latest version from github (sudo gem update simplificator-rwebthumb) and see the README. rwebthumb is a ruby wrapper for the Webthumb API.   

Resources:

We have two masters

Wednesday, July 30th, 2008

We are slowly moving our projects from our svn repository to github. In that process we had to move a private repository from one github account to another (pulling and pushing again), still maintaining the svn part.Funny situation ocurred today. After I pulled, merged and pushed my local repository back to the new github account I have two masters!I don’t exactly know how I did this. Who knows what I get when I pull the master branch now?Two masters on github Update: After I wrote this post, some background task seems to have tidied up for me. Phew. One master. 

Lighttp and Fileupload on Windows

Monday, July 14th, 2008

A customer of us deploys a Rails app on a Windows platform. We are using

It was a pretty straightforward process to setup and configure this stack, following one the online documentations. How happy we were when everything worked and we could hit our Rails app from the browser. Everything ? Ahhhh… not exactly. File upload did not work properly. Only one out of 10 uploads would succeed, the other would fail after around 60 seconds. The browser should an “Connection Timed Out” error message, the access and error logs of Lighty did not give much information.When we had IIS rewrite to one mongrel directly then the upload worked, so the problem was somewhere with Lighty. Digging around in the Lighttpd forums and documentation brought up following configuration options which could be relevant for fileupload:

  • server.max-request-size (defaults to 2 GB so there should be no problem)
  • server.upload-dirs (Make sure this is a valid Windows directory with write permissions)
  • server.network-backend (Unclear which backends are available for Windows)
  • server.max-read-idle (defaults to 360 seconds)
  • server.max-read-idle (defaults to 360 seconds)

We solved our problem by setting the server.network-backend to ‘writev‘ (a bit obscure but hey… it worked)

RubyGem for webthumb

Thursday, July 10th, 2008

Webthumb is a service to create thumbnails from websites (descriptive name, isn’t it…). It creates different sized thumbnails by default and you can request custom sizes.It offers an API to access it’s services and we wrapped up some code i wrote while on vacation and bundled it as a gem.The code is still a bit clumsy (as i wrote it on vacation :-) ) but it works nice for us. There is already another ruby wrapper for the API but it is not available as a RubyGem and does not expose some of the latest webthumb functionalities so we decided to write our own library. Josh gave us some extra credits so we could develop the API. Thanks. The gem is available on Simplificator’s github repo. To install do following:
sudo gem update --system (in case you are not yet on version 1.2.0 or higher)
sudo gem sources -a http://gems.github.com (only once)
sudo gem install simplificator-rwebthumb

To create thumbnails:
require 'rubygems'
require ‘rwebthumb’
include Simplificator::Webthumb
# main access point for the Webthumb API
wt = Webthumb.new(’YOUR API KEY HERE’)
job = wt.thumbnail(:url => ‘http://simplificator.com’)
job.write_file(job.fetch_when_complete(:large), ‘/tmp/test.jpg’)

For more info check the README file and (currently) the source code. All the features from a the request element are supported but currently not documented. I’ll look into that in some days.If you want to use the Gem you’ll need an account for webthumb. You’ll get 100 free credits every month so it’s easy to try it out.

on the edge

Sunday, June 22nd, 2008

Just a short note to direct you to a great post over at rubyonrails.com (some days old, i know…but i can not in the office right now and can not access the internet everyday. Yes… this exists :-) ). Chuw Yeo June wrote about API changes and performance tests. The API gets some new methods which make your life easier and at the same time are a bit confusing. Sample ? Here you go:

Object.present? method was added which is the same as not Object.blank? which is the same as Enumerable.any?

Three ways to do the same thing (as long as you are working on Enumerable). I think this is confusing and clutters the API.

RESTful In-place form editing

Friday, May 9th, 2008

We have rewritten the rails in-place editor, described in the rails recipes book by Chad Fowler, in RESTful design. You can install it as a plugin (http://source.simplificator.com/svn/plugins/inplace/).

If you use special characters like umlauts, mute vowels or japanese characters patch your prototype.js with prototype-umlaut-patch.patch. The patch is needed because the original version of prototype.js doesn’t decode the mutated vowels correctly.

Patch: prototype-umlaut-patch.patch

Custom Date/Time formats in Ruby (on Rails)

Sunday, April 13th, 2008

In Switzerland we use a different formatting for date/time than in the USA (in fact most of Europe uses different formatting than the USA). Ruby (on Rails) is very centred on US coders and US applications and this can sometimes be a source of confusion and frustration. So let’s add some custom formats to Rails so we can not only to Date.today.to_s(:short) but also Date.today.to_s(:my_custom_date_format)

Rails has a built in set of formats which is stored in ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS and ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS and all you have to do is to add your own formats to this hash.
In config/initializers create a file date_formats.rb. This file we can use to register custom formats withouth messing up our environment.rb. If you need this often you could also extract it to a plugin so you can “install” your custom dateformats everywhere with a single script/install. In this file you can now merge your own formats to the existing ones or change existing formats:

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:my_format => ‘%d. %m. %Y’)

The expressions you can use for formatting can be found in the source of Date.strftime. Or with this little piece of code:

>> (’a’..’z').each do |c|
?> expression = “%#{c}”
>> puts “#{expression} -> #{Date.today.strftime(expression)} / #{expression.upcase} -> #{Date.today.strftime(expression.upcase)}”
>> end
%a -> Sun / %A -> Sunday
%b -> Apr / %B -> April
%c -> Sun Apr 13 00:00:00 2008 / %C -> 20
%d -> 13 / %D -> 04/13/08
%e -> 13 / %E -> E
%f -> f / %F -> 2008-04-13
%g -> 08 / %G -> 2008
%h -> Apr / %H -> 00
%i -> i / %I -> 12
%j -> 104 / %J -> J
%k -> 0 / %K -> K
%l -> 12 / %L -> L
%m -> 04 / %M -> 00
%n ->
/ %N -> N
%o -> o / %O -> O
%p -> AM / %P -> am
%q -> q / %Q -> Q
%r -> 12:00:00 AM / %R -> 00:00
%s -> 1208044800 / %S -> 00
%t -> / %T -> 00:00:00
%u -> 7 / %U -> 15
%v -> 13-Apr-2008 / %V -> 15
%w -> 0 / %W -> 14
%x -> 04/13/08 / %X -> 00:00:00
%y -> 08 / %Y -> 2008
%z -> +0000 / %Z -> Z
=> “a”..”z”

For those who need even more you can register a Proc which will be called with the Date/Time to format as an argument:

>> proc = lambda do |what|
?> what.day - 1
>> end

Don’t forget to register your custom formats with Date and Time if you deal with Date and Time formatting!

Some Netbeans Shortcuts

Wednesday, April 9th, 2008

As written before we are pretty happy with Netbeans and it’s Ruby/Rails support. As a previous Eclipse user it took me a while to get used to the keyboard shortcuts (though some are the same as in Eclipse). Here are some of them i use most:

  • Close Document: Meta + W
  • Close all Documents: Shift + Meta + W
  • List Documents: Shift + F4
  • Next/Previous Document: Meta + PageDown / PageUp
  • Run File: Shift + F6
  • Debug File: Shift + Meta + F5
  • Move Line Up: CTRL + Shift + Arrow Up / Arrow Down
  • Ident/Unident: Tab / Shift Tab or CTRL + Shift + Arrow Right / Arrow Left

Oh and if your Mac started talking to you after experimenting with shortcuts: Apple + F5 will switch it of again :-)