Archive image

Posts Tagged ‘ruby’

How to install rbenv on Linux Mint 17.1

Last year I wrote about installing rbenv on Linux Mint 16. Back then the installation process as described on the project’s Github page didn’t work for me and, after much frustration,  I ended up installing an older version of rbenv from the repositories.

Recently, I had to reinstall my operating system (upgrading to Mint 17.1) and decided to give the rbenv installation process another try. I’m happy to say that it worked entirely as expected and within a matter of minutes I had two Ruby versions installed on my system and could switch between them at will.

Read more…

Ignore “Invalid Byte Sequence in UTF-8” error in Ruby

I wrote a simple Ruby script to parse text files and manipulate their content.

This is useful, for example, if you want to replace all occurrences of the phrase “Dr Jones” with “Prof. Jones” across a set of HTML files.

This was working great on Windows, but when I ran it under Linux, I started getting a “invalid byte sequence in UTF-8” error. This is how I solved it.
Read more…

FXRuby – How to capture close on the main window

I wrote a small FXRuby program which allows the user to do some simple file manipulation, then upload the altered files via FTP to a web server.

I ran into a small problem in that when the user clicked the “Close” button (the X in the upper right-hand corner) of the main window, the application closed straight away.

Normally, this would be the desired behaviour, but in this case I wanted to intercept this message and do some application cleanup first (delete temporary files, make sure the user had saved their work etc).

Here’s how I did it.

Read more…

How to install rbenv on Linux Mint 16

Last year I switched from Windows to Linux Mint as my main operating system and wanted to install a Ruby version manager.

I weighed up the pros and cons of what was available and eventually opted for rbenv as it seemed more lightweight, would let me compile my Rubies myself and (in contrast to RVM) didn’t come with any way of managing gems.

I searched Google and came up with a couple of tutorials to follow, such as this one and this one which described how to install rbenv, but unfortunately they didn’t work for me.

Read more…

Setting a fallback font in Prawn

At work, one of the applicants to our programme submitted parts of her application in Russian (despite it being an English speaking programme).

The database could handle this fine, as it stores entries using the UTF-8 character set, but the PDF generation part of our application refused to cooperate (just displaying a bunch of underscores). 

We use the Prawn library to generate our PDFs, so I set about finding a way to make Prawn play nice with the Cyrillic characters.

Read more…

Trouble installing mysql2 gem on Windows 8 with Ruby2

I recently installed the 64 bit version of Ruby 2.0 on my Windows 8 machine.

All of my old projects I tested with it ran just fine and the world was a happy place.

Then I had to install Rails, so that I could make some minor changes to an existing app … and the pain began.

Read more…

Inline error messages with Rails 3

I was recently tasked with converting a Rails app from Rails 2.3.x to 3.2.x.

“Shouldn’t be too difficult” I thought, but one of the first things that came out and bit me is that the error_message_on helper method, which was previously used to display error messages next to the form fields that had caused them, has been deprecated.

It took me a little while to figure out how to reinstate this functionality. Here’s how I did it.

Read more…

How to manage multiple versions of Ruby on Windows

I had recently started work on a Rails project and was setting up my local dev environment which I wanted to make it as similar as possible to the environment on the server I will deploy to.

The remote server currently runs Ruby 1.9.2 and Rails 3.x, so this is what I installed on my local machine.

Read more…

An introduction to FXRuby

I recently got an article published on entitled “An introduction to FXRuby”. In this article I show you how to get up and running with FXRuby, introduce you to some of the more commonly used widgets, and demonstrate how to build a simple application with some real world value (a password generator).

Read the complete article on Rubysource

Inspect object in PHP

To display the contents of an object in ruby is really simple.
All you do is store the object in a variable, then pass the variable as an argument to the Kernel method p(), which in turn writes obj.inspect to the standard output.

Read more…