Archives for posts with tag: ruby

I needed to copy a bunch of zone files over to slicehost, and I really hate doing work I can automate. I wrote a quick script that will import a zone file from a BIND definition into slicehost.

You can find it at:

On another note, ActiveResource is REALLY cool.

For the life of me I could not get Jython to recognize my mysql driver using JDBC. I literally spent hours trying to get it to work. Fooling with my classpath, my version of the mysql-connector and my version of Jython. Finally I gave up and wrote a really simple wrapper class.

This is the Error:

#the following line is “print sys.path”
[‘./mysql-connector-java-5.1.6-bin.jar’, ‘/Volumes/UserHome/bcx/work/istuff/iros/jar’, ‘/Volumes/UserHome/bcx/jython2.5a3/Lib’, ‘__classpath__’, ‘/Volumes/UserHome/bcx/jython2.5a3/Lib/site-packages’]
Traceback (most recent call last):
File “”, line 12, in
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: com/mysql/jdbc/Driver

So I dealt with various version of that error for a while. Finally I gave up and wrote a wrapper class, which didn’t work until I downloaded and installed jython 2.5a3, previously I was using the latest stable, 2.2.1.

Here is my quick wrapper class:

import java.sql.*;

public class Connect
public static Connection getConnection(String url, String usr, String pass) throws Exception{
Class.forName (“com.mysql.jdbc.Driver”).newInstance ();
return DriverManager.getConnection(url, usr, pass);

Here is how I used it in my Jython code.

import Connect
import sys

url = “jdbc:mysql://localhost/replay”
con = Connect.getConnection(url,”root”,””) #this line uses my wrapper

stmt = con.createStatement()

In other news I implemented a mDNS enabled mysql-based indexed logger for EventHeap. The next step is to build a simple interface for replaying marked logs. I really wish I could write this interface using a language other than Jython or Java, so the next step will be fooling around with my various options. I am not sure if I am feeling adventurous enough to try out JRuby, but Ruby on Rails would be a nice way to build a really quick web front end. I am leaning towards some sort of Jython based EventHeap RPC server, that has “jobs” which can be started / stopped/ monitored/ and modified over REST or XMLRPC. This shouldn’t be that bad, but I “really” would prefer to do the network code using twisted, although I think the “goal” of this stage, is to pretty much hack this thing together asap.

I wrote a web-crawler today for one of my other projects, and ran into the above problem “OpenSSL::SSL::SSLError: certificate verify failed”, well I was just collecting websites and didn’t really care about the validity of SSL certificates, so I just wanted a quick fix.

Here it is:

require ‘openssl’

Essentially, I just change the constant for VERIFY PEER to the Value of VERIFY NONE, pretty sneaky :-), and no real work required.

[edit] David made RESTful requests instead of using the XMLRPC, and it works nicely

here’s the test code:

1 require 'net/http'
2 require 'pp' # pretty print
3 require 'rubygems'
4 require 'json' # need to gem install this
6 url = 'http://.com:60091/get_context?data=%7B%22x%22:20,%22y%22:20,% 22z%22:20%7D'
7 response = Net::HTTP.get_response(URI.parse(url))
8 case response
9 when Net::HTTPSuccess then data = response.body
10 when Net::HTTPRedirection then fetch(response['location'], limit - 1)
11 else
12 data.error!
13 end
15 result = JSON.parse(data) # the magic!
17 pp result

Read the rest of this entry »