119 Labs LLC

Ideas on Technology

Reasonable JRuby Env With IDEA

I’m all for using TextMate (or hopefully soon Ultraedit for osx) for straight rails dev. I’m starting on a project that uses both clojure and rails so I wanted something that would play nicer for cross-language development. My favorite IDE from the Java side of things is by far IntelliJ IDEA. They have a relatively new version out with ruby support so I thought I’d give it a go setting up a jruby based rails project. It ended up being a little more complicated than just download and install so here you go: First head over to the jetbrain’s website and download a demo copy of IDEA 9. Make sure to get the ultimate edition since ruby dev is disabled in their community edition. After that snag the most recent version of jruby which as of this writing was 1.4.0. In order to follow along exactly you’ll want the straight bin version, but with a little modification to paths any version should do. I keep all of my (non-maven) java libraries in /Library/JavaDev just swap that out for whatever directory you use. Place the downloaded jruby-bin in /Library/JavaDev/

cd /Library/JavaDev/ curl http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz > jruby-bin-1.4.0.tar.gz tar xzvf jruby-bin-1.4.0.tar.gz

make sure your user has permissions to execute files in the bin directory. As a matter of good house keeping, I also like to setup a symlink

ln -s jruby-1.4.0 jruby

next lets see where ruby is currently running from type

which gem

It most likely is running under /usr/bin/gem. We want to change that temporarily so we can update the gem system. Lets change our path and update the gem system

export JRUBY_HOME=/Library/JavaDev/jruby export PATH=$JRUBY_HOME/bin:$PATH which gem

the last command should now read /Library/JavaDev/jruby/bin/gem. If at any point you now close your terminal window you’ll need to run the last three commands again to make sure you’re working with the right gem base. Time to update the gems on your system: gem install rails gem update system gem install activerecord-jdbcsqlite3-adapter gem install jdbc-sqlite3 gem install activerecord-jdbcmysql-adapter You will probably see a message “JRuby limited openssl loaded. gem install jruby-openssl for full support.” As long as this is just a development station don’t worry about it. Now on to IDEA. Open the dmg and copy IDEA to your application folder. Run the app and create a new Ruby project. Once you get to the point that you need a project SDK click configure and add. The file IDEA is looking for is $JRUBY_HOME/bin/jruby. It will detect the lib folders from there. Last step make sure you’re using the appropriate sql adapter in your database.yml file. For sqlite your dev should look something like:

development: adapter: jdbcsqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

Notice the adapter is jdbcsqlite3 rather than the standard sqlite3 That’s it. If you want to use a db other than sqllite, you’ll need to install the appropriate gem. IDEA will warn you & let you fix it if you forget to do this so no big deal. For reference:
  • OSX 10.6.2
  • Jruby 1.4.0
  • Rails 2.3.5
  • Idea Ultimate 9.0.1

Pbpaste & Pbcopy

I love pbpaste and pbcopy. They are utilities on osx that allow you to write to and read from the copy buffer. They really have unlimited use in productivity scripts for transforming information. My most frequent use though is when I want to open a new tab in Terminal and stay in the same directory. In order to do this in Terminal I:
  1. type “pwd | pbcopy”
  2. Apple-T
  3. cd <paste>
This is even snazzier with a touchstream. I used to run in to the problem all the time where some one would send me a unc style path and I needed to open it up on my mac. To get around this I wrote the following script:
### unc2smb.sh ###
#!/bin/sh

pbpaste|sed -e "s,[\\][\\],smb://," -e  "s,[\\],/,g" -e "s,\(.*\)/\([^/]*\),\1/,"|pbcopy
Now just copy your unc style (\server\folder) path and run unc2smb.sh. Now when you use a standard paste, you’ll instead paste the osx friendly smb style (smb://). One last step, I added unc2smb.sh to quciksilver. Now when I get a unc style path in an email I:
  1. Select & copy the path
  2. run unc2smb.sh from the quicksilver command menu (or you could bind it to a key)
  3. Connect to server
  4. <Paste>
Still not a great process, but better than I had before. Anyways combining pbpaste, pbcopy, & sed can really give you a huge amount of control

Installing Auth Openid on Trac With Dreamhost

It turns out installing plugins, and particularly the openid plugin, on a shared dreamhost environment is arduous at best. �After a bit of work and research I managed to get it to work so here you go:

I. Perform a one-click install of trac from the web panel

if you don’t know how to do this you shouldn’t even try to proceed.

II. Setup a virtual python environment

Having a shared account with no sudo access you need to setup a local python environment to do all of the building. I found a reference here on how to do that. Here are the steps
cd ~ wget�virtual-python.py python virtual-python.py wget http://peak.telecommunity.com/dist/ez_setup.py bin/python ez_setup.py export PYTHONPATH=~/lib/python2.4/:~/lib/python2.4/site-packages/

III. Build the plugin

mkdir install_dir cd install_dir  
hg clone http://bitbucket.org/Dalius/authopenid-plugin/
cd authopenid-plugin python setup.py install –prefix=$HOME cp ~/lib/python2.4/site-packages/*.egg <your_trac>/plugins
For more info see this article.

IV. Configure openid

edit <your_trac>/conf/trac.ini
add the following lines:  
[components]
trac.web.auth.* = disabled
authopenid.* = enabled
see the above article for more config options.

V. Install Element Tree

As of this writing, element tree was not installed in the dream host system python cache. �In order to get around this do the following:
cd ~/install_dir wget�http://effbot.org/media/downloads/elementtree-1.2.6-20050316.tar.gz tar xzvf�elementtree-1.2.6-20050316.tar.gz cd�elementtree-1.2.6-20050316 setup.py install
In order to get our trac instance to pick up this library, we need to package it as an egg edit its setup.py change
from distutils.core import setup, Extension
to:
from setuptools import setup, Extension
then run
python setup.py bdist_egg cp dist/*.egg <your_trac>/plugins
you now have all of the files installed you need to run openid on trac

VI. Creating the plugin schema

If you go to you project home page and you see the message:
TracError: The Trac Environment needs to be upgraded.
Then like me you need to initialize the SQL tables used by the python-openid plugin. If that is the case then do the following:
cd <your_trac>/db sqlite3 trac.db CREATE TABLE oid_nonces(server_url VARCHAR); <hit enter> CREATE TABLE oid_associations(server_url VARCHAR(2047),handle VARCHAR(255),secret BLOB(128),issued INTEGER,lifetime INTEGER,assoc_type VARCHAR(64),PRIMARY KEY (server_url, handle)); <hit enter> .exit
See the�source code for more info. Now we need to “upgrade” the schema
cd ~/install-dir wget http://openidenabled.com/files/python-openid/packages/python-openid-2.2.4.tar.gz tar xzvf python-openid-2.2.4.tar.gz
cd �python-openid-2.2.4
cd �contrib ./upgrade-store-1.1-to-2.0 –sqlite=<your_trac>/db/trac.db
on the above line you must use the absolute path to your trac instance. No using ~ as a home dir shortcut. This should run successfully.If the output of that command is �”no such table oid…” Then something was messed up with using sqllite. Go back in and use the command .tables and make sure the two tables are there. If not, re-run the create table commands and look for error messages. DONE! You should now be able to log in to your trac instance.

VII. Setting OpenId permissions in trac

Setup your account with permissions.ant more? log in and check trac.log edit <your_trac>/conf/trac.ini change the logging section so it looks like this:
[logging] log_file = trac.log log_level = DEBUG log_type = file
save and exit. Now:
tail -n 200 -F <your_trac>/log/trac.log
Next log in to your trac instance (using a web browser) using a openid account. You’ll see something like�Retrieving session for ID u’http://xxxxxxxxxxxxxxxxxxxxxxxxx’ Everything between the single quotes is your account name. Now we can use trac-admin to give our openid account some permissions:
trac-admin <trac_instance> permission add <account_name> <PERMISSION>
where permission is something �like TRAC_ADMIN. �Use the command permission list to see currently assigned permissions

VIII. Cleanup

One thing I dislike about the one click install is it messes up the logo area. �Here’s a simple fix edit <your_trac>/.htaccess after the line RewriteCond $1 !^htdocs(.*).png$ add the line RewriteCond $1 !^chrome(.*).png$ save and the logo should now show up. Good luck. let me know if you run into other stumbling blocks and I’ll update the instructions.