24.12.08

Christmas: relief, salvation and commercialism

Christmas eve has finally arrived! To some, Christmas brings emotions of relief or salvation. To others, it's just one of those days filled with obligatory social calls and commercialism.

The days that precede Christmas have been as hectic as they possibly can. One one side I had to make some preparations for the social necessities. And on the other side there was the commercial aspect, in Christmas times known as 'desperately trying to find something to give to someone while moving to endless black crowds carrying baby buggies with loss of orientation and decency'.

If only had nothing else to do, I could fully indulge myself and study the strange mental state people get in while on a Christmas shopping spree...But, I had to attend also to more enlightened things such as coding my Shoes course assignments. The course is great and lots of fun. This is not just getting some exercises done. There is a great social aspect where you can interact with other coders and see solutions from other people, things you would have never thought of yourself. Also, having a skilled teacher who carries a contagious enthusiasm providing some excellent exercises helps to decrease the learning curve and keeps it fun! Unfortunately, the better must sometimes give way to the good...
But, if you are interested in learning some GUI programming, there is good news for you! The 3rd batch of the shoes programming course at Rubylearning has been announced, and it starts on 14 February. That's no holidays to bother you!

Throwing myself at the Christmas shopping crowd did pay off at the very end. The right presents were obtained, and to further add to the joy, I finally got hold of my own very ASUS EEE PC! After a disastrous adventure on eBay, countless disappointments in the shops, and a somewhat obsessive compulsive venture to the ugliest city of my country, I am pleased to announce: ladies and gentlemen: I got em. Apparently the very last, ASUS EEE PC 1000HD, and specially for Christmas: the white version! Unfortunately, _no_ shop in .nl sells the Linux version. Apparently consumers prefer to pay for a Windows license and the dreadful OEM CD instead of a nice 40GB SSD. Well, if the noise will start to bother, I guess I'll visit jkk mobile and put the SSD in myself. It's a relieve to find that ubuntu eee runs flawlessly and everything works like a charm. All adjustments have been made to resume my ruby coding and blogging as well.

The holiday's have not arrived for me yet though. Starting tomorrow I have the social calls to make and right after that I'll travel to Berlin for the 25C3. But there is one thing that's different in this busy week as opposed to the previous: an EEE with a full sized keyboard! I get to do some work while I'm wasting my time, finally salvation!

Marry Christmas!

11.12.08

GUI toolkit extravaganza part III: WxRuby

In the previous part of the GUI toolkit extravaganza we looked at the FXRuby toolkit. This time we will spend some time to look at the Yin of FXRuby's Yang, the wxRuby toolkit.

wxRuby
wxRuby is a library that enables Ruby code to use the wxWidgets library. wxWidgets is a cross-platform GUI library written in C++. wxRuby has arrived at version 2 so we will look at that one. Not only the name sounds like FXRuby but also it's features seem alike. Let's find out if there are any differences!

ease of installation
xwruby2 is available as a Ruby gem. This makes the installation process very easy. According to the documentation, all you have to do is: sudo gem install wxruby2. There are also binary and source packages are available. On my Ubuntu Hardy Heron system, this did not do the trick however. Apperently there is something else you need to to apart from installing the gem, and this is poorly documented. You can read more about the problems installing wxruby2 in my previous post.

documentation
There seems to be quite a decent ammount of documentation for wxruby2. The project website provides the complete API reference and a Tutorial. As far as I'm aware there are no books about wxruby2, nor have I seen it featured in a book. The project's website hosts two mailinglists.

supported platforms
Wxruby has been created to provide a cross platform GUI toolkit, so it runs on multiple platforms. Systems running Linux, UNIX, Windows or Os/X are all supported by wxruby.

complexity
Take a look at the following code sample. We create a main window and place a button on it. We use PLACEMENT_SCREEN to center it. Piece of cake!

#!/usr/bin/env ruby
#!/usr/bin/env ruby
require 'wx'
Wx::App.run do
frame = Wx::Frame.new(nil, :title => "wxRuby window")
button = Wx::Button.new(frame, :label => 'Button')
evt_button(button) { puts 'WXRuby' }
frame.show
end

functionality
wxruby2 provides a standard set of graphical functions. The focus lies on cross-platform availability and the usage of native window designs. So on a GNOME system, you get GTK look and feel, on and on Mac OS/X you get aqua and on Windows you get the well known theme from Redmond. I am curious though as how much of windows, aqua and gtk functionality is supported...Unfortunately, finding that out would take more time then I have at the moment.

performance
There was some flickering going on at the top of the window sometimes. But I have noticed that on Fxruby windows as well since I upgraded my system to Ubuntu Intrepid. It does not seem like it's a problem caused by any of these two kits. Otherwise this performs just good.

looks
There's not much difference to be seen in the example provided here and the one previously provided in parts I of the GUI toolkit extravaganza. There are some minimal details around the buttons and edges. Reason is that it uses native graphics, so on my system it uses GTK in the end. Instead of adding yet another picture of a window with one button with only miniscule differences. Here's a picture from one of the sample programs, in this case,



You can find the wxruby2 toolkit at:
http://wxruby.rubyforge.org

Next up for the GUI toolkit extravaganza part IV is Shoes!

9.12.08

wxruby: reading error messages about libraries

As you might have noticed, some time has passed since I wrote about fxruby. Wxruby was to follow a few days after it. However I had been experiencing problems getting it to work. With only a few days to go before the Shoes class starts I wanted to put an end to this misery.

First thing people do nowadays when problem solving is to Google for solutions, so did I. Searching for the errors I got did return some mailing list postings from people with the same problem, but no useful answers. As you might have experienced yourself, searching for these kinds of things can quickly take hours without you realizing it. It is not only time consuming, but in the spirit of despair you might just actually try some really stupid recommendation from a person who's most likely just be guessing himself. Actually trying some of their suggestions can add even more problems and make the whole so complex you'll eventually just give up...but then that's not very Ninja, is it?

After installing the wx package I thought I'd only need to install the wxruby gem and be done with it.

sudo gem install wxruby

Unfortunately not so...
ruby -rubygems ./wxtest.rb
/var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so: libwx_gtk2u_stc-2.8.so.0: cannot open shared object file: No such file or directory - /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so (LoadError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wx.rb:12
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:32:in `require'
from ./wxtest.rb:3
Obviously it had some problems loading the wxruby2.so binary library. This file exists in the specified directory along with wx.rb. The permissions to wxruby2.so were set to readonly, this did not seem right for a binary. Adding execute permissions did not help however.

The problem might have been caused by one of the other errors. One of them seemed to originate from wx.rb. Wx.rb can be found in the same directory as wxruby2.so. This is the file you should require in your ruby code. Basically it loads both the wxruby2.so and ruby extensions to core wx classes. There was something about line 12. Using vim's :set nu command, the apparent culprit was displayed on my screen:
11 # load the binary library
12 require 'wxruby2'
13
14 # alias the module
15 Wx = Wxruby2
There could not be anything wrong about that.

There were however three errors in custom_require.rb. The first impression was, judging from the directory, that this was a generic function used by or for rubygems. Obviously I was not very convinced that this might be the cause of the problem. But it would not hurt to take a look.

First look was at the code near line number 27:
26 def require(path) # :nodoc:
27 gem_original_require path
28 rescue LoadError => load_error
29 if load_error.message =~ /\A[Nn]o such file to load -- #{Regexp.escape path}\z/
Hmm, this code wants a path to some gem thingy, else it throws an error. Not the error I got however. While this seemed illogical at that moment, sometimes one must keep problems simple and not add other problems along the way. The main point was this code wanted some path.

Two other errors were caused at something near line 32.
32 gem_original_require path
33 else
34 raise load_error
No more clues were necessary. The suspect was some unknown path variable. Since wxruby was installed as a gem. My code needed to load rubygems itself. According to the installation manual there's three ways to do this:

* Run ruby with the -rubygems argument: eg ruby -rubygems my_wxruby_script.rb
* Set the RUBYOPT environment variable to -rubygems
* Add require 'rubygems' at the top of your wxruby program.

I had tried running my code with the -rubygems argument allready. And I did use the require 'rubygems' in my code. I did not set the RUBYOPT however, so I removed the require line and set this variable with RUBYOPT="-rubygems".

The same errors lit the screen after I ran my code again. A sense of defeat and disillusion filled my mind, what could be the problem? I had tried countless solutions, analyzed code, read documentation and yet I was no step further. Having no more ideas, I stared blankly at the screen, looking at the errors...

/var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so: libwx_gtk2u_stc-2.8.so.0: cannot open shared object file: No such file or directory - /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so (LoadError)

Staring back was a half lit reflection of myself. I saw a person who was about to give up as I started to think about skipping this chapter of the GUI Toolkit extravaganza. At least I had Ruby-GTK2 and FXruby...GTK?...What's that gtk doing in my error message!

A quick query in my package management tool found that I did not have any libwx_gtk* libraries installed, why would I. The documentation certainly did not write about needing this library! I did encounter it while searching for ruby & wx libraries, but never made the connection...

Anyway, there were some dependencies and here's what was installed:

libwxgtk2.6-0
libwxgtk2.6-dev
libwxbase2.6-0
libwxbase2.6-dev
libwxgtk2.8-0
libwxgtk2.8-dev
libwxbase2.8-0
libwxbase2.8-dev

After this I could run the examples that come with wxruby. Looking back at the errors I wonder, did you overlook this one in the error messages as well?

Comming up: Part III of the GUI toolkit extravaganza, featuring wxruby!

3.12.08

Book preview: Wicked Cool Ruby Scripts

Good things come to those who wait. And wait I did. Somewhere back in June when I could still just walk around in a T-shirt, I decided to buy a book. After getting scared from looking at my Amazon wish list'o-saurus I quickly found myself searching for completely other books. O'Reilly always was a good string to start the search. I mean the search after doing the meta search to get the damn name right. It seemed only more quick to order directly from O'Reilly, you know, cut out the middle online-book-giant. After deciding to go for a more advanced Ruby book this time, the Ruby Cookbook found it's way to my shopping basket. Clearly this was not a book to read from beginning-to-end, but more of a handy help in desperate times. So, why not try to find something else as well? Something to really read from beginning to end. This time I found a book from NoStarch, Ruby by example. I remembered two other books from this publisher which I really valued for it's size, content and readability. So it seemed like a good choice. Time to check out. While experiencing the online-shopping rush at it's peak moment, some promo drew attention. Three for two, 3:2, 3-2=1, I have two, get three, one for free! Finding the last book was a daunting task. Only a few days later I found a book that was just added to the book announcements: Wicked cool ruby scripts from NoStarch. Interresting. It featured a robot on it's cover holding some kind of gem. Good, robots are cool. The announcement mentioned something about system administration, web scripting, utilities and security.

That last one just did it, BANG, the collision of two of my favorite subjects! So I pre-ordered the book, which was to be published in September. No hurries, I had the other two books to read (on top of the to-read-stack I amassed already). But you can guess this one met with the most anticipation. After a while, having started on some other books just to get by, I received both the cookbook and ruby by example. So I started reading (reviews coming soon). Summer passed. September passed. No book. No word. Rescheduled release date. No word. Rescheduled release date. Still no word about my delayed order. So I sent mail to O'Reilly and after getting the most rude, dumb and hostile response. That's quite something coming from somebody who wants my money. To further add to the bad taste, even another release date slipped by. Was it ever going to be finished and sent? A few day's ago finally salvation in the mailbox: my book had been shipped!

After having to wait a few more days, due to a UPS guy being an idiot, I finally had it in my hands! I just took the book from it's cardboard prison.

First impression: this book is thin like it has been starving all those months I've been waiting. 189 is the number of the last page. If you have read my review on Learning Ruby you know I truly value short books. I feel an urge to tell you what I have against big, fat, long books...must..not...rant.

Second impression: the author writes he will skip explaining Ruby. this is not a 101 Ruby book. Ok, good, there are plenty of those already!

Next, I looked at the index, which read as follows:
Chapter 1: General Purpose Utilities...could be handy...Chapter 2: Website Scripting...nice, too many Ruby books fail to give it the attention it deserves, probably due to Rails......Chapter 3: Li(U)nix System Administration...*nix stuff, always nice!...Chapter 4: Picture Utilities...Chapter 5: Games and Learning Tools...Chapter 6: String Utilities...Chapter 7: Servers and Scrapers...what the hell is a scraper?...Chapter 8: Arguments and Documentation...
Chapter 9: Sorting Algorithms...some memories about my study years started to float around in my mind...quit sort...bubble sort in JAVA...beer...youth......Chapter 10: Writing a Metasploit 3.1 Module with Ruby...oh those sweet years, where have the times gone...wait: read again...Chapter 10: Writing a Metasploit 3.1 Module with Ruby......Metasploit...Oreally? OMFG that just ROCKS!

Starting from chapter 10, off course, I read a little, flipped some pages to get some impressions. Well it sure looks promising, short scripts that look really useful, not too long explanations and a clear look and readable format look that is so typical for NoStarch books. Well this can't go wrong can it?

There just remains one question: how the hell will I manage to read 7 books in the same time?

28.11.08

Analyze this

"The independent and problem-solving type. They are especially attuned to the demands of the moment are masters of responding to challenges that arise spontaneously. They generally prefer to think things out for themselves and often avoid inter-personal conflicts.
The Mechanics enjoy working together with other independent and highly skilled people and often like seek fun and action both in their work and personal life. They enjoy adventure and risk such as in driving race cars or working as policemen and firefighters."

Hmm that sounds about right, except they should have called them The Ninjas instead of mechanics!

Test your own at typealyzer.

Shoes course at Ruby learning

No post for the GUI toolkit extravaganza this time since I've been having some problems getting wxRuby to run properly. But this posting is related since we will deal with Shoes in one of the upcoming posts in the GUI toolkit extravaganza. So I just wanted to let you know I rolled in to the Shoes online course at rubylearning.org. It's a paid course, the cost is 5$ which is not much money. Why, the author of Shoes, seems to be happy about this course so I thought I'd give it a try. Anyway, the POIRPWSC101 course starts at 13 December and ends at 26 Dec 2008. This is a nice short time, so I should be able to keep focus :)

Some while back I tried to follow the Free Online Core Ruby Programming Course (FORPC101), it was good but I did not manage to keep up due to poor planning on my side. It seems that since this time they are providing a few more interesting courses including the following:

POIRPWSC101 - Paid Online Ruby with Shoes Programming Course
POIRPWDC101 - Paid Online FXRuby and MySQL Programming Course

If the Shoes fit, I think I'll sign up for the FXRuby and MySQL course as well. But it depends a little on my private and professional schedules. Oh and offcourse I'll write about my experiences on this Ruby class on this blog as well. If you are interested in taking a free, or almost free course on Ruby take a look at Rubylearning.

24.11.08

GUI toolkit extravaganza part II: FXRuby

The FXRuby toolkit is the subject of the GUI toolkit extravaganza, part deux. In this 7 part series, we will take a look at the various GUI toolkits in existence to find the ultimate GUI toolkit. One of the best known GUI toolkits is FXRuby, wich we will look at in this post.

FXRuby
FXRuby is a library that enables Ruby code to use the Fox toolkit. Fox is a graphics toolkit which was written in C++ and known for it's speed. FXRuby was created way back in 2001 and one of it's aims is to provide a cross-platform Ruby GUI toolkit. Let's take a closer look!

ease of installation
FXRuby has an interactive installer for Windows systems. Macintosh systems can use the Mac ports. The sources are available so you can compile from source in any case. I had a bit of trouble installing it on my Ubuntu Hardy Heron system. But eventually I got it working. Here's what you need to do:
apt-get install libfox-1.6-0 libfox-1.6-dev libfox-1.6-doc
gem install fxruby

documentation
FXRuby has been nicely documented. The project website provides the complete API reference and a users guide.

There is also a book written solely about FXRuby. The project's website hosts two mailinglists as well.

supported platforms
FXRuby has been created to provide a cross platform GUI toolkit, so it runs on multiple platforms. Systems running Linux, UNIX, Windows or Os/X are all supported by FXRuby.

complexity
Take a look at the following code sample. We create a main window and place a button on it. We use PLACEMENT_SCREEN to center it. Piece of cake!

#!/usr/bin/env ruby
require 'fox16'
include Fox
app = FXApp.new
MainWindow = FXMainWindow.new(app, "FXwindow" ,
:width => 200, :height => 100)
FXButton.new(MainWindow,"Button",nil,nil,0,BUTTON_NORMAL|LAYOUT_CENTER_Y|LAYOUT_CENTER_X)
app.create
MainWindow.show(PLACEMENT_SCREEN)
app.run

functionality
FXRuby provides a standard set of graphical functions. But one feature that makes it stand out on the feature front is the support for OpenGL, providing the posibility to render cool 3-D graphics from your Ruby code.

performance
The Fox toolkit is known for it's speed and limited use of system recourses. From what I have seen, the same goes for FXRuby, it is light and it is fast.

looks
There's not much difference to be seen in the example provided here and the one previously provided in parts I of the GUI toolkit extravaganza. There are some minimal details around the buttons and edges.



Update: ok, this does not help a lot. Here's an impression of one of the sample programs that come with Fxruby:
As you can see, it looks a bit like some apps did in the windows98 days...

You can find the FXRuby toolkit at:


Stay tuned for the GUI toolkit extravaganza part III: WxRuby