Installing JRuby in a Windows Environment

Education, Programming No Comments

I just installed JRuby on my Windoze XP box and thought I would share my experience for anyone interested in doing the same. It’s pretty straight forward, unless you know nothing of setting path variables in Windoze.

First, you’ve got to download JRuby (I got it from the jruby codehaus repository) and uncompress it into your choice of location. I grabbed the 1.1.2 binary tarball.

Next, you need to make sure you have a compatible Java runtime environment (JRE) or Java development kit (JDK) installed. If you don’t have one already, you can get these from the Sun Java site. You’ll notice the ‘Popular Downloads’ menu on the right has what you need. I already had this installed for my NetBeans installation.

Now comes the fun part. Make a note of the path to the JRE or JDK directory, as well as the path to your JRuby directory. I chose to install these as follows:

  • JDK: D:\programs\Java\jdk1.6.0_06
  • JRuby: D:\jruby-1.1.2

We’re nearly there! Next, just follow along:

  1. Right click on “My Computer” and select ‘Properties’.
  2. Choose the ‘Advanced’ tab at the top.
  3. Click on the ‘Environment Variables’ button near the bottom.
  4. Click the ‘New’ button under the ‘User variables’ section.
  5. For ‘Variable name’, put JAVA_HOME and for Variable value, put the path to your java install directory. Click the ‘OK’ button.
  6. Again, click on the ‘Environment Variables’ button near the bottom.
  7. For Variable name, put JRUBY_HOME and for Environment variable, put the path to your JRuby install directory. Click the ‘OK’ button.
  8. Select your PATH variable and click on the ‘Edit’ button.
  9. If the ‘Variable value’ field is empty, put your JRuby install directory’s path followed by \bin (mine: D:\jruby-1.1.2\bin)
  10. If the ‘Variable value’ field is not empty, put a semi-colon followed by your JRuby install directory’s path followed by \bin (mine: D:\jruby-1.1.2\bin)
  11. Click on the ‘OK’ button then click on the ‘OK’ button then click on the ‘OK’ button to get out of all this mess. tongueout

Finally, open a command prompt, type ‘jruby -v’ and hit return!

I tried to be as verbose and explicit as I thought possibly necessary in these directions. If I missed something or messed something up, please post to let me know and I will change or add to it right away.

Modulus as Handled by Ruby

Education, Programming No Comments

This is an explanation I gave to a student in class today of how the modulus operator behaves in Ruby. As I was writing the explanation down, it all became quite clear to me. I only had a tentative grasp on this concept until trying to explain it. That’s a good feeling when your helping another to understand something gives you clarity on the subject.

Given (-n % x) or (n % -x), the RHS (right hand side) of the modulus operation must be multiplied by the negative integer closest to 0 that will get it past the number on the LHS (left hand side). Then, the result is the difference between this number and the LHS. e.g.:

-7 % 3   # result is 2
# climbing (positive) from -9 (3 * -3) to -7

7 % -3   # result is -2
# dropping (negative) from 9 (-3 * -3) to 7

Of course, when the polarity is the same on both sides, such as (n % x) or (-n % -x), you just multiply the RHS times the positive integer that gets you the closest to the RHS without going past it then the result is the difference between the remainder and the LHS. e.g.:

7 % 3    # result is 1
# climbing (positive) from 6 (3 * 2) to 7

-7 % -3  # result is -1
# dropping (negative) from -6 (-3 * 2) to -7

It might help to note that in Ruby, the RHS always dictates the polarity of the result.

SyntaxHighlighter

Education, Programming, Web Development No Comments

I finally got a syntax highlighter installed. I figure that since I’m taking the free Ruby course at RubyLearning.org, I should make my code look nice (and be more usable) when I decide to put some here on my blog. Just to get things rolling, here is a bit of code from one of the exercises I’ve done during the first few weeks of the course.

class Dog
  def initialize(name)
    @name = name.capitalize
    @what = self.class.to_s.downcase
    puts "Hi! I'm #{@name}, your new #{@what}!"
  end

  def teach(new_trick)
    @tricks = Array.new unless @tricks
    @tricks += [new_trick]
    puts "#{@name} now knows how to #{new_trick}!"
  end

  def show_tricks
    list_of_tricks = [@tricks[0]]
    1.upto(@tricks.length-1) do |modify|
      list_of_tricks += [" and #{@tricks[modify]}"]
    end
    @name + ' knows how to ' + list_of_tricks.to_s
  end

  def bark
  end

  def eat
  end

  def chase_cat
  end

  def to_s
    @name + " (your #{@what})"
  end

  def capable_of?(capability)
    self.respond_to?(capability) ?
    puts("I can #{capability} or my name's not #{@name}!") :
    @tricks.include?(capability) ?
    puts("I have recently been taught to #{capability}!") :
    puts("This is something I have not heard of before... \
    #{capability} you said?")
  end

  def method_missing(method, *more_arguments)
    "#{@name} cocks it's head to the side as if to say \n\t\
    \"I don't understand what #{method} means.\""
  end
end

# a few examples of usage:
rex = Dog.new 'rex'
max = Dog.new 'Max'
rex.teach 'jump through hoops'
ObjectSpace.each_object(Dog) {|dog| dog.teach('chase cars') }
puts rex.show_tricks
rex.capable_of? 'bark'
rex.capable_of? 'chase cars'
rex.capable_of? 'fetch'
puts "#{max} is feeling a bit left out..."

Sadly, I had misinterpreted the challenge guidelines. The instructor wanted the learned tricks to be methods and not properties. Anyhoot, this post is just so I can see what the highlighter will do on my blog. :-P

RubyLearning.org

Education, Programming, Web Development No Comments

Well, I signed up for a free online Ruby course at rubylearning.org some time last week. Classes start tomorrow and I’m pumped.

I’ve been seeing the popularity of Ruby, decidedly due to the Rails framework, skyrocket in the past few years. It seems that lately, you can hardly go to a web design or web development centric site without seeing a bright red gem or a red locomotive on the home page.

I read somewhere that Ruby is entirely Oo, which really piqued my interest. I’ve been wanting to get my noodle wrapped around OOP for years while dealing with PHP and javascript; not to mention (though I am) my very short lived foray into the seemingly mind-numbing world of C++ that I embarked upon.

Once I realized that Ruby might hold the key to my eternal salvation, I decided not to take my usual tack when trying to learn a programming or scripting language. That process would be best described as: buy a few $50 tomes, crack them open enough to get a feel for the writers’ personalities and then let them sit on my bookshelf while knowing that I am free at any time to pick them up and soak it all in.

It’s The End Of The World…

Education, Random Thought No Comments

…as we know it. I’m not so sure I feel fine, though. I just saw ‘An Inconvenient Truth‘ a couple of days ago. It stars Al Gore (he used to be the next president of the US). It’s actually a documentary style flick following his campaign against global warming. The facts he presents in his presentation are easily followed and show a dismal future for anyone living through and beyond the next 10 to 20 years.

The correlation between atmospheric CO2 and temperatures are somewhat (slight understatement?) disheartening. Through natural processes, the CO2 in the atmosphere has gone up in the past to the same approximate levels as we are seeing now, with the atmospheric temperatures following suit. However, this time it is our polluting of the atmosphere (primarily due to our dependence on fossil fuels) and deforestation of the land that is causing this escalation of atmospheric CO2. While the amount of fossil fuel being used by the population will have to fall in the near future, we don’t seem to have that much time before the projected increase in our atmospheric CO2 causes the temperatures to rise to levels never seen before in the history of life on Earth.

Oddly, and somewhat confusingly to the layman (me), this will actually cause another ice age (along with other weather related catastrophes). This is due to the way that the oceanic currents keep the temperatures moderated in the gaseous atmosphere. It is proven that temperatures rising in the past (at the end of the last ice age) caused the glacial ice on the north american continent to melt and rush into the North Atlantic. The desalinization caused the temperature regulating oceanic currents to change, which, in turn, caused a continuation of the ice age.

I know the Mesoamerican people’s calendar ends on December 21st 2012 on the Winter Solstice. Maybe this destruction of the atmosphere, and thus our ability to survive in it, is the reason. I have heard other theories as to why their calendar ends at this time (alien contact, comet impact, etc.), but this seems to be a highly plausible explanation. Of course, ‘explanation’ doesn’t really work here, as there is so much that is currently unexplainable about future predictions by ourselves and our predecessors. I suppose only time will tell. While your waiting for this time to pass, I highly suggest that you go see ‘An Inconvenient Truth’ at a theater near you as soon as you get a chance. It just might change the way you live.

Ohayo!

Education, Personal No Comments

I have finally got all the hiragana down. I can run through the online flash cards for 104 characters in random order with 100 percent recognition and I can write the hiragana in a,i,u,…ka,ki,ku… order or a,ka,sa,…i,ki,shi… order with only a couple of short mental farts.

I’ve even gone as far as learning about half of the katakana already. They are much easier once you learn the hiragana. I’ve also stumbled upon some really nice sites for learning elementary kanji. I’m now hoping to be familiar enough with the entire kana to start reading Japanese texts later today. I may not know what I’m reading, but at least I’ll be on my way to building my vocabulary… hehe.

This is an extremely stimulating mental workout. YOU should try it! Seriously though, if you only know one language, you should start now down the road to communication.

Hiragana, Wainscoting, The Usual…

Education, Personal, Random Thought No Comments

I think I just had a bit too much on my plate, so I decided to do something about it. I set the plate on the ground for the dog and decided to learn a foreign language. The main countries I want to visit some day are Belize, Australia and Japan. Belize is an English speaking country and I think I could fake my way through Australia… hehe. That leaves Japanese to learn.

Well, I’m a few days into my studies now, and I think I’m coming along nicely. I’ve got 30 of the basic 46 hiragana down pat. I’m using computer flash cards I built with html and writing the kana as far as I know it by hand constantly. Of course, I’m learning words like neko (cat), aka (red), and such as I learn the kana. I’ve also got a pretty good grasp of sentence structure, though I’m still a bit lost with particles. Give me a few more days and I’ll have hiragana and katakana down. I’ll keep studying vocabulary while learning the kana and be ready for 1st grade kanji within a week. Of course, in order to be considered literate, I’ll need to learn about 2000 kanji. That is the degree of literacy required of an elementary school graduate in Japan. I suppose I’m on my way, as I already know about 10… hehe.

Along side my lessons, I’m remodeling my kitchen. I’ve redone the cabinets in a glossy white and gave the doors a distressed white eggshell finish. I’ll be putting glossy black hardware on these soon. I put a white tile back-splash behind the stove, and I’m now putting white tile between the upper cabinets and countertops. I’ll continue the white tile around the room between upper chair rail and lower chair rail. I’m putting white wainscoting below the lower chair rail. The walls are now yellow (above the upper chair rail). I’ve installed new lighting in the ceiling, two sconces and a few under-cabinet lights. Soon, I will be installing the copper pot rack I’ve had for over a year. I’m installing a light natural stone tile on the floor. It should lead nicely to the hardwood floors I uncovered and refinished in the rest of the house.

Now, tell me. You think I’m not loosing my frig’nipplin’ mind?!? LOL! Actually, I did finish most of my projects before jumping into this past weekend with a change of pace. I’m down to just one studio project that isn’t wrapped up, though another will be starting in about a week. I’ve got most of my web design projects pretty much wrapped up except a little bit of pro bono work (I’m on it, Shannon!) and some of my personal sites. I don’t foresee anything keeping me from finishing my kitchen within a week or so and learning Japanese enough to speak with a bit of fluency within a month or so. OK, so maybe I’ll still sound like a struggling gaijin, but I should be able to at least carry on a conversation about the weather, music and web design by then.

Until next time… this is Marvin Zindler with EEEeeeeeyewitness News. I don’t think we’re in Houston anymore, Tico.