Wednesday, November 28, 2007

Where is the PSI for Ruby?

About every 6 months a Google recruiter will run across my LinkedIn page and try to trick me into starting the grueling 2-3 month interview process. Why anyone with a job already would put themselves through this is beyond me, but it did get me thinking about Python again and to catch up on my Python Package Index Feed (which kicks RubyForge's ass, BTW) and I ran across the Python System Information. I had to write this sort of stuff (and more) in Ruby about 6 months ago. That is the different between Python (and grudgingly Perl, gag) and Ruby. Some sort of mainstream task is probably already done (and relatively)

Not that I'm complaining


>>> import psi

>>> a = psi.arch.arch_type()
>>> a

>>> isinstance(a, psi.arch.ArchMacOSX)
True
>>> isinstance(a, psi.arch.ArchDarwin)
True
>>> a.sysname
'Darwin'
>>> a.nodename
'laptop'
>>> a.release
'8.9.1'
>>> a.version
'Darwin Kernel Version 8.9.1: Thu Feb 22 20:55:00 PST 2007; root:xnu-792.18.15~1/RELEASE_I386'
>>> a.machine
'i386'

>>> psi.loadavg()
(0.705078125, 0.73046875, 0.7626953125)

>>> import os
>>> mypid = os.getpid()
>>> mypid
13903
>>> p = psi.process.Process(mypid)
>>> p.command

Friday, October 12, 2007

Cool Ruby Logfile Visualization Tool

Check out glTail.rb (there is even a movie) that I stumbled across courtesy of Peter Cooper over on Ruby Inside:

glTail is a great little Ruby script by Erlend Simonsen (aka Fudgie) that uses OpenGL and Ruby to visualize the events taking place in log files in real time. An example video on the official site shows requests coming into an HTTP server, each represented by a "ball" which is thrown across the screen. The script uses net-ssh to connect to a server and then libopengl-ruby to output the graphics. Parsers are included for processing Apache, Rails, IIS and Postfix log files. Nice work! The code is merely a couple hundred lines of Ruby, so if you've fancied putting together a basic OpenGL app, it's worth looking at it for that reason too.


I can't wait to try it on a few gigs of firewall logs.

Friday, September 28, 2007

Trying out jrubyc

Following up the good news, I pulled down trunk, and compiled a stupid 2 line script. This obviously is no test of the compiler, but the first time I've used jrubyc. Above and beyond the normal JRUBY environment stuff, to execute classes you have to add jna.jar and jruby.jar to your CLASSPATH.


franz-g4:~/jruby/jruby/trunk/jruby/bin mdfranz$ java bobo
1.1
java
franz-g4:~/jruby/jruby/trunk/jruby/bin mdfranz$ ls -al bobo.class
-rw-r--r-- 1 mdfranz mdfranz 2866 Sep 28 09:43 bobo.class
franz-g4:~/jruby/jruby/trunk/jruby/bin mdfranz$ cat bobo.rb
puts JRUBY_VERSION
puts RUBY_PLATFORM
franz-g4:~/jruby/jruby/trunk/jruby/bin mdfranz$ echo $CLASSPATH
:/Users/mdfranz/java/lib/hsqldb.jar:/Users/mdfranz/java/db-derby-10.3.1.4-bin/lib/derby.jar:/Users/mdfranz/java/db-derby-10.3.1.4-bin/lib/derbytools.jar:.:/Users/mdfranz/jruby/jruby/trunk/jruby/lib/jruby.jar:/Users/mdfranz/jruby/jruby/trunk/jruby/lib/jruby.jar:/Users/mdfranz/jruby/jruby/trunk/jruby/lib/jna.jar
franz-g4:~/jruby/jruby/trunk/jruby/bin mdfranz$ echo $JRUBY_HOME
/Users/mdfranz/jruby/jruby/trunk/jruby

Wednesday, September 26, 2007

If you are angry enough you might get a book!


So I was pleased to learn that I will be receiving a review copy of Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java. Thanks Ola if you had anything to do with it!

No time (and probably not qualified) right now to do a real review, but I will say that Chapter 6 (Java Integration) and the Appendix B (JRuby Reference) are probably worth the 21 bucks for the e-version of the book, even if you don't plan on doing any JRoR work right now.

Tuesday, September 25, 2007

JRuby Enum Constants and my irrational fear of ::'s

So development on PeerTAB is rolling along. Sort of. I am continuing to play with JXTA via JRuby.

So in Java
manager = new NetworkManager(NetworkManager.ConfigMode.EDGE, "HelloWorld");

But of course in JRuby
include_class "net.jxta.platform.NetworkManager"
m = NetworkManager.new(NetworkManager.ConfigMode.EDGE, "HelloWorld")

fails with

irb(main):010:0> NetworkManager.ConfigMode
NoMethodError: undefined method `ConfigMode' for Java::NetJxtaPlatform::NetworkManager:Class
from (irb):10:in `binding'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `loop'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `catch'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `start'
from :1:in `catch'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:69:in `start'
from :1

So the question then I how do I get these enum constants?

So interestingly enough

irb(main):020:0> NetworkManager.constants
=> ["ConfigMode"]
irb(main):021:0>


But that did get me anywhere and it was only until I ran across this blog post that I figured it out.


irb(main):011:0> NetworkManager::ConfigMode
=> Java::NetJxtaPlatform::NetworkManager::ConfigMode
irb(main):012:0> NetworkManager.constants
=> ["ConfigMode"]
irb(main):013:0> NetworkManager.constants.class
=> Array
irb(main):014:0> NetworkManager::ConfigMode::EDGE
=> #
irb(main):015:0>

And I know part of the problem is I refuse to use :: unless I'm forced to because it seems way too Perl-ish and ugly. And yeah, I've heard there is something called C++.

Monday, September 24, 2007

Interesting Bruce Tate Podcast

I listened to Robert Stephenson's interview with Bruce Tate while washing dishes tonight and it was certainly a treat and certainly kept my mind occupied while cleaning up the minestrone remnants:

Among the highlights:

  • How development in Rails (and I would add comparable frameworks such as Django) allows smaller teams to communicate more effectively (and frequently) with clients than would be possible with "traditional" languages such a Java.
  • The high correlation between offshoring/outsourcing and traditional (waterfall) development models (if you outsource something you have to be more rigorous in the your specification, your unit testing, integration, etc.)
  • Lots of talk about JRuby and positing that much of the work we do is essentially scripting. Use of JRuby with Business Rules Engines/DSLs (such as Drools) which is something I've wanted to play around with yet. As well as using a Java scripting languages to access cool APIs.

Check it out...

Tuesday, September 11, 2007

I didn't want indentation to break my code?

I haven't done an "angry" post for a while and since I don't want to close down this blog, so I'll posit there is something unique about the Ruby community which compels folks to write lame defenses of their favorite language the way that doesn't seem to occur for other languages. I never saw this with Python or Perl, but it mostly seems to ooze from converts from Java/C++ or God-forbid PHP.

There, done, filled my quota!

P.S. - for "h3rald" or anyone else, you won't have any problem with Python if you use a decent editor like Vim and have it configured properly.