ruby

recent posts related to the ruby programming language

How to run JRuby from a Ruby script on a Windows PC

I'm doing some crazy things at the moment, basically calling JRuby from a Ruby script on a Windows 2000 system. I'm doing this because there are a bunch of JRuby scripts that I want to run sequentially, and I also want to check for errors after each run, so what better way to invoke them and look for resulting errors than with Ruby, especially on a Windows system? :)

JRuby Toolkit Robot example - how take a screenshot of your desktop

Here's some sample JRuby code that I just used to take a screenshot of my desktop. It uses the Toolkit and Robot classes from Java to make it all happen. It could probably be a little shorter, but I don't know much about JRuby yet. I also had a problem getting the Java File class to work properly, and referencing it as shown was the only way I could get it to work.

Installing JRuby on a Windows XP system

Earlier tonight I installed JRuby on a Windows XP system, and it was about as easy as anything I've installed. Here were the steps on my computer:

A JRuby program that runs the Java Robot class

This is just my second JRuby program, but I thought I might as well go for the gusto. This Ruby/JRuby program creates an instance of a Java Robot class (java.awt.Robot), then moves the mouse to a position where it clicks the Minimize button on a full-screen window (assuming a display resolution of 1024x768). Warning: if you have something else in that location it will click that instead!

Here's the Ruby/JRuby code:

A Ruby program to count the number of times words appear in a text file

After a fairly large number of emails I've started working on my type-ahead, predictive text editor project. In support of this effort I'm looking at different algorithms to best predict the word the user next wants to type. The first part of this is looking at documents I've written in the past, and analyzing the frequency of word occurrences within those documents.

How to print a Ruby hash sorted by value

I recently needed to print the information in a Ruby hash, with the results sorted by value. Here's a general recipe on how to print the hash results sorted by value. I've created a sample hash, and populated the hash with sample data, to show how this works.

First, here's the sample code, using the first name of each person as the key, and the last name as the value of the key/value pair:

Ruby natural logarithm example

Still reading Calculus Made Easy, they note that 'e' (the natural logarithm, or natural log) is the limit of the following series:

1 + 1/1! + 1/2! + 1/3! ...

To test this I created the following Ruby natural log program.

Ruby IMAP error: "get_tagged_response: Error in IMAP command received by server"

If you ever see the following error message when running a Ruby mail script that uses the IMAP library it may not be as bad as it seems:

Ruby mail program - how to find all email messages I have read but not replied to

Here is the source code for a Ruby mail program I wrote that looks through my INBOX and finds all the email messages I have a) read but b) have not replied to.

This Ruby script comes in very handy on a project I'm working on now where we exchange 50-75 email messages per day. After a little while there are so many messages I can't remember if I replied to the important messages, so this program helps whittle down the list and just shows the ones I have read, but have not replied to. (The ones I haven't read are a lot easier to spot.)

Ruby mail example program - how to move IMAP email messages I've already read

Here's a Ruby mail program that I use to read my inbox, and move mail messages from a group of people that I have read to an IMAP folder that I have setup specifically for those people. The beauty of this is that I don't move the email messages I haven't read yet -- I just move the messages I have read.

Syndicate content