Category Archives: Ruby

Semantic Web and JRuby

I got the chance to share my enthusiasm for two of my favorite technologies at JRubyConf by giving a presentation on Semantic Web and JRuby. It was an excellent experience. I was able to connect with other people that shared my interest in the Semantic Web and some that have even worked with the technologies professionally. Most exciting, I had the opportunity to share my knowledge and hopefully inspire others to look farther into using JRuby with the Jena Semantic Web Framework.

Here are some resources from the presentation that I wanted to share with everyone:

On github, https://github.com/gigasquid/jruby_semantic_web_examples, I put together some examples of SPARQL queries against dbpedia as well as translating the examples that they have on the Jena RDF API to use JRuby

Here is the presentation itself:
https://github.com/gigasquid/Presentations/blob/master/SemanticWebJRuby.pdf

 

A special note of thanks to Brian Sletten, the Semantic Web guru, who inspired and exposed me to the Semantic Web, helped me out by answering my questions and pointing me in the right direction and for just being a swell guy.

 

Yellow Belt Katas for Ruby and Clojure

I have put a couple projects out on GitHub to help people get started with Clojure and Ruby.
The Katas are taken more or less from the Coding Kata site http://codingkata.org/katas/. The projects both include the basic project setup for you to get started with TDD beginner katas.

The Ruby project has tests in the form of rspec-given, which is quite fun. The Clojure project has tests in the form of Midje, which has a lovely syntax.

Please give them a try :)

https://github.com/gigasquid/yellow_belt_ruby_katas
https://github.com/gigasquid/yellow_belt_clojure_katas

On Thinking in Ruby and Clojure

Recently, I decided to work on a set of code Katas. I couldn’t decide whether to do them in Ruby or Clojure, so I decided to do them in both. I did the Kata in Ruby first and then immediately followed up with the same one in Clojure. It was an interesting exercise, not only for the learning of the languages, but to highlight how I thought about the problems differently depending on the language.

Ruby is a fantastic language. It would delight and sometimes surprise me with how elegant and natural it was to solve problems. When I approached the Kata, I found myself thinking, “How can I make this more readable?”. Ruby never failed to please.

Clojure is also a wonderful language. One of the things that I really enjoy about it is that it changed that way that I approach problems. This was particularly evident when I turned to solve the same problem in Ruby that I just had in Clojure. First and foremost, I thought about the data. Then about how the data could be transformed. The transformation isn’t like the serial steps that you normally take to hold the data in your hand and bit by bit mold it into the result – like a sculptor with clay. It is the kind of transformation that takes a rolled ball of yarn and transforms into a beautiful lace pattern.

The closest that I had come to this functional way of thinking was when I was doing some heavy SQL and database work. I went to a talk by Jay Pipes on MySQL. I remember him saying that to be really good at SQL, you needed to think in sets. You couldn’t effectively solve the queries with the regular programming for-loop construct. You needed to think of the sets of data joining and intersecting and the transformations needed to be applied to the data elements. The same focus on the data seemed to hold true for Clojure too.

I highly recommend both Ruby and Clojure as programming languages. Each are dynamic, elegant and powerful and a lot of fun. Next time you sit down to do a Kata, and can’t decide what language to use, try them both – and let me know how you think…

Zen and Zombies – Adventures in Ruby

What do Zen and Zombies have in common? You probably got the beginning with the letter “Z”, but did you also guess Ruby? This blog post is to share two awesome and fun filled ways to learn Ruby and Ruby and Rails.

Zen
First, let’s start with the Zen. Edgecase created a great way of learning Ruby. It is through Ruby Koans . Koans are a way of teaching Zen through questions. The master asks the student a question. The student then meditates on it until they come to the answer , eventually leading to enlightenment. The Ruby Koans are cleverly designed to teach bite size tidbits of the Ruby language through the completion of unfinished test cases. Each test case is a Koan. Every time you fix the test case by filling in the blanks, you are gaining a deeper understanding of the language. The main path_to_enlightment.rb file leads you through test cases that explore many areas of the languages such as Strings, Classes, Methods, and Exceptions. Enlightenment has never been so much fun.

Zombie
Moving from enlightenment to tasty brains for Zombies, we have Rails for Zombies http://railsforzombies.org. Envy Labs has raised the bar in online tutorials. The traditional way to learn Ruby on Rails is to download the programs, struggle a bit as you figure out how to install it and then work through exercises locally through a book, website guide or podcast. Rails for Zombies takes out all the pain of the traditional way and replaces it with enjoyment. Everything is done in the browser, including code. The format is to watch a video with Zombies and Rails code and then take what you learned by completing a lab exercise in the browser. After you complete the lab, you unlock the next video. Over the course of five labs, you create a Twitter web app for the Zombie hoard. It’s a win for you and the Zombies.

So if you are curious about Ruby, these are two great ways to try it out. I promise you that will have fun learning. Although, some people may also experience occasional uncontrollable desire to eat brains….

Photo Credits

Zen: http://www.flickr.com/photos/shebalso/121744939/

Zombie: http://www.flickr.com/photos/70109407@N00/5188908499/

Openssl fix for Rails 3.0 on Ubuntu

If you are trying to run ruby rvm and rails 3.0 on Ubuntu you might run into this problem when you start up you server.

LoadError: no such file to load
-- openssl

After much googling and researching – just installing the openssl library on your system won’t fix the problem. You need to recompile and install your rvm ruby version with the openssl. I found this fixed it for me.

rvm install 1.9.2-p0 -C --with-openssl-dir=$rvm_path/usr

There is also another solution
here so you don’t have to recompile every time

Fox In Socks Blocks

In honor of the Ruby Why Day, I was inspired to dabble in Ruby Blocks after being reading “Fox In Socks” multiple times to my children before bed. For all of you parents out there that have read the book many, many times while your children are giggling at your pronunciation difficulties, I am sure this bit will be familiar:

def fox_in_socks_blocks
  chicks_bricks = ["Chicks","bricks","blocks","clocks"]
  yield chicks_bricks[0..1]
  yield [chicks_bricks[0],chicks_bricks[2]]
  yield chicks_bricks
end

fox_in_socks_blocks do |sillywords|
  puts "#{sillywords[0]} with #{sillywords[1]} come." if sillywords.size < 3
  puts "#{sillywords[0]} with #{sillywords[1]} and #{sillywords[2]} and #{sillywords[3]} come." if sillywords.size >= 3
end

That’s right – the output is:

Chicks with bricks come.
Chicks with blocks come.
Chicks with bricks and blocks and clocks come.

Is your tongue numb?

Happy Why Day!