2008/12/27

Links on Google Application Engine

I found a few interesting posts and projects that I'd like to share here.

AppMecha is a nice tutorialized blog on starting and developing your projects based on AppEngine. Good tips, thanks.

There are dozens of tools and accessories for AppEngine but I found GAEUtilities one very useful.

And an other good one. This could help you set up the (missing feature!) cron-like scheduling to your app.

2008/12/14

JRuby on Ubuntu

Let me share you a few steps (considered to be a non-standard way) of building a good little dev environment on Ubuntu Linux.

Precautions:
1. Again, this is not the way you should build your environment, I just found it useful
2. Do not rush and copy paste everything to your console, get used to your terminal

To get Jruby on your box you will need Java JDK. I recommend to use SUN Java but JRuby should run on other FLOSS version of Java as well. If fails, use the SUN one.
sudo apt-get install sun-java6-jdk

It will take a while :) To check the Java version type:
java -version

Mine says it is
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)


OK. Let's create some space for the sources and the dev environment. I assume you are in your home directory. If not, change to that directory.
mkdir dev dev-sources
cd dev-sources


To get Jruby standard dsitribution, I recommend to get the binary version of 1.1.5. When wget finished, unpack the tarball.
wget http://dist.codehaus.org/jruby/jruby-bin-1.1.5.tar.gz
tar -xf jruby-bin-1.1.5.tar.gz


To move Jruby to the dev environment, let's move it :) You won't need the distrib file so its safe to remove it from the disk.
mv jruby-1.1.5 ../dev/jruby
rm -f jruby-bin-1.1.5.tar.gz


To lazy and easy access to JRuby executables you have (at least) two options. Either add a symbolic link to jruby/bin/jruby, or add the complete bin directory to your path variable. To add a symbolic link do the following - replace $yourusername with your real username (if you don't know your username, ask Linux with the whoami command):
sudo ln -s /home/$yourusername/dev/jruby/bin/jruby /usr/local/bin/jruby

Or if you want to add JRuby executables to your path, open up your .bashrc file with a text editor and set at the end of the file:
export PATH=${PATH}:${HOME}/dev/jruby/bin

Save and reload the rc file
source .bashrc

Now you can check the version from anywhere:
jruby -v

Check the local gems installed too. I think it is worth while to add GitHub to your rubygem source - it is a nice place to store and share your code (free for open source projects).
jruby -S gem list -l
jruby -S gem sources --add http://gems.github.com

Cool, we have JRuby installed! Now we need some kind of a database. I won't use sqlite anymore (if possible) but found a great engine that is faster and knows a lots more.

To get h2 database engine get back to your terminal
cd dev-sources
wget http://www.h2database.com/h2-2008-09-26.zip


Unpack the archive
unzip h2-2008-09-26.zip

Move the entire engine to dev, then remove the source archive.
mv h2 ../dev/h2
rm -f h2-2008-09-26.zip


Change to h2 application directory and fire up the database server.
cd ../dev/h2/bin
java -cp h2.jar org.h2.tools.Server


Create a database of your taste. I recommend to set the jdbc url to jdbc:h2:~/dev/db/test

It will create a few files under /home/$yourusername/dev/db/test and generate dynamically more when running. Play around with the db admin interface a bit to get familiar with it. Have you recognized that you get a built in admin interface? Nice huh?

OK. Let's adds some more gems to JRuby. Cool kids use Rails but if you prefer other frameworks its up to you.
jruby -S gem install jruby-openssl activerecord-jdbch2-adapter rails mongrel

You can test the database via JRuby irb if you prefer.
jruby -S irb
irb(main):001:0> require 'rubygems'
irb(main):002:0> require 'jdbc/h2'
=> true
irb(main):003:0>


If you see this that means the connector working properly.

Nice, let's do something with Rails!
mkdir ~/dev/ruby_apps
cd ruby_apps
rails myapp


Edit your database config file under config/database.yml


To generate some code to your app let's do the scaffolding.
jruby script/generate scaffold post title:string body:text

Don't forget do create the databases and migrate the structure.
rake db:create:all
rake db:migrate


Fire up the server.
mongrel_rails start

And see the result http://localhost:3000/posts

Good job, let's roll :)

2008/12/13

Ideas on a better Ruby stack

This week end I found myself using Ubuntu installed via Wubi. I admit there are weird things (don't care about Linux is a desktop thingie or not) but it seems OK at the moment. Since I started mungling Ruby and Rails, always wanted a stable (hahah) stack for myself so let me share some ideas.

I've chosen JRuby. It is fast enough to work with and/or deploy to production, truly platform independent (needs Java only) and has a great community (SUN in the background of course but that just an other reason in the turn). I tried the MRI implementation (1.8 and 1.9) several times both on Linux and Windows and I found it, erm, just OK, nothing else. Rubinius is great but not a platform independent VM so I dropped it for myself.

The thing is I don't like Java. I mean the style. I'm sure it is great and powerful as a language but uncomfortable in a way I cannot stand. On the other hand, JVM is absolutely amazing. Thanks to SUN (hey its kinda business decision for sure, but who cares) now it is open for scripting languages like Python, Lisp, Scala and Ruby of course (a hell more!). Its even distributable folks!

I'll try some tiny embeddable database engines written in Java, for purity's sake of course :) No, platform independence is the keyword. What I bloody hate around frameworks and Vms is the platform shit. Yes, Windows IS a real platform to develop on even if you wanna play with Open Source stuff. I just admire people like Luis Lavena fighting for a better acceptance of Windows around Ruby. That guy writes better installer/builder than you, *nix boy. A bit of rant :)

First I'll try this H2 database engine that is supposed to be faster than Derby, HSQLDB and SQLite. In fact I'm full with this SQLite engine. Rails (baaad ORM dependent) and Merb (goood ORM independent) frameworks' base choice. I'm dropping it because I have to build it and/or the adapter as well. No thanks. Java wins over any platform issue. Or if you have a better solution, show me, I'll gladly accept.

Java (the JDK) plus JRuby plus H2. So far so good, its working. No worries.

2008/12/01

Enterprise vs Ruby/Rails

Charles Nutter posted an interesting tweet on a fear from the enterprise world in Ruby/Rails "scene". I think I know this fear 'cos I felt the same seeing all the early sidenotes on Ruby from the Java world. But Ruby people, the best of the Java people are now truly open minded, the JVM has a great scripting interface and give us the power of Java, the servlet and application containers offer terrific possibilities - what else do you want?

Ezra Zygmuntowitz writes about monoculture that we do not need. I agree! Hail to the diversity of languages and VMs. Use what you need and love, leave what you don't.

The key is the hacker culture here I guess. Rubyisms considered hacketies and metaphors. And being free from rigid standards. My opinion on this issue is quite simple: you still (and will) have the choice. Free choice on dev environment, language, framework, operating system and all.

Isn't it great?