ruby
Sending emails using Google Mail with Ruby
It’s no secret that Google Mail has become, over the last years, the most widely used email server and client on the world. Not only it’s basically free, but with the use of Google Apps you can even use it on your own domains. Because so many people use it, even system administrators, it may [...]
A Ruby implementation of the FizzBuzz test using the Enumerator class
Some days ago I learnt about The FizzBuzz Test and did a simple implementation in Ruby. The FizzBuzz test is a simple algorithm that is supposed to do the following: For each number from 1 to 100: If the number is divisible by 3, print “Fizz” If the number is divisible by 5, print “Buzz” [...]
Give your Ruby console a dash of colour
When you’re developing an application in Rails (or Ruby), you spend lots of time in the IRB, the Interactive Ruby Shell. Usually just to test some Ruby code, start an application console or debug something going on inside the project. Yesterday, looking at a coworker screen, I saw he had his console with lots of [...]
Fix Java GUI applications in xmonad
If you ever try to run a GUI Java application when using xmonad as the Window Manager, you’ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the RubyMine Ruby on Rails [...]
Ruby on Rails Many To Many associations with multiple databases
Sometimes you need to use multiple databases in your Rails projects. Usually when some data must be shared between different applications. When this happens you usually have some models in a shared database, and some other models in the specific application database. This can be easily done using the establish_connection method in the shared models [...]
Iterate over a collection in groups, and other things
One thing I find fascinating about Ruby is the fact that most common tasks are already programmed for you in its library. The Enumerable module is a clear example of that, providing you with lots of functionality to manipulate collections of objects. One of those useful methods I discovered the other day was each_slice. This [...]
Easily select random records in rails
If you ever wondered how to easily retrieve a random record in an ActiveRecord model, here’s en easy way to do that: use the sample method. sample is a class method from the Array class that retrieves one or more random items from an array instance. It conveniently returns nil or an array lesser than [...]
Fixtures and serialized attributes in Ruby on Rails
If you’ve ever used the serialize method in an ActiveRecord model, you may have faced the problem of writing a fixture for that particular serialized field. The serialize method is quite handy if you need to store a complex object (like a Hash or an Array) in a database field, without having to create additional [...]
Create your own JSONP Proxy using Ruby on Rails
Today I was working on a web site that needs to retrieve some RSS feed over the internet. Since the web page has no server (HTML + javascript only) I couldn’t access the feed from the server side. Also, because of the Cross Domain limitation of Ajax requests, I couldn’t access the RSS in the [...]
Using IronPython to extend your .NET applications
One of the interesting new things on the .NET platform is the recent addition of Python and Ruby to the CLR. Both versions for .NET are called IronPython and IronRuby respectively, and they provide some new and good things to the platform. Python and Ruby lovers will see now that they can use all the [...]