Skip to content

Subversion, JavaHL, and Eclipse on Linux

I normally use emacs and command line svn when working at home on Linux. Eclipse to me, in principle, is a necessary evil of programming with larger groups. But a recent volunteer project I’ve been working on for the Philippine Scholars of Minnesota is forcing me out of this habit.

And with this change, I’ve suddenly been introduced to the world of JavaHL. So what is JavaHL? Per the previous link, it’s the Java language binding for the Subversion API. On Windows the subclipse project is able to package JavaHL, but not on other operating systems. So that’s why I’ve never had to deal with it before.

Fortunately, after finding out what JavaHL actually is, it’s pretty easy to install on Ubuntu, as you might expect:

sudo apt-get install libsvn-java

This will install JavaHL to /usr/lib/jni as a standard install, and this is where eclipse will look for it by default. If you’ve installed it in a non-standard way, you might want to look at this link regarding overwriting the java.library.path with an eclipserc file.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Syncing IPod in Linux

A colleague recently pointed me to an article about syncing my ipod with a Linux box. The article is good but my experience getting this to work was sufficiently different enough to warrant another post.

My first issue came with Step 1:

sudo add-apt-repository ppa:pmcenery/ppa

This issue I had was that the keyserver was down. This may not always be a problem, but based on a few google searches it’s hardly an uncommon problem.
I found my solution with this article:

sudo sh -c "echo 'deb http://ppa.launchpad.net/PPA_NAME/ppa/ubuntu UBUNTU_VERSION main' >> /etc/apt/sources.list"
sudo apt-key adv --keyserver keys.gnupg.net --recv-keys XXXXXXX

My next issue was with Step 2:

sudo apt-get install gvfs gvfs-backends gvfs-bin gvfs-fuse libgvfscommon0 ifuse libgpod-dev libgpod-common libiphone-utils libiphone0 python-iphone libplist++1 libplist-utils python-plist libusb-1.0-0 libusb-1.0-0-dev libusbmuxd1 usbmuxd

I replaced libiphone-utils with libimobiledevice-utils, and removed python-iphone from the list.

And lastly, Step 5:
I created /mnt/ipod

mkdir -p /mnt/ipod

and made it sufficiently writable. I did not need to do anything else in this step!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Debugging MySQL ERROR1025 – Error on rename of

If you ever executed the following command in mysql:

alter table table drop column;

and got the following error:
1025 – Error on rename of ‘.\\#sql-880_3c’ to ‘.\\ ’ (errno: 150),

Don’t panic.

It’s probably because you’re trying to drop a column that’s a foreign key. Execute this command: SHOW ENGINE INNODB STATUS to debug more. A large text is dumped on the console and if you read carefully, you’re likely to have something similar to: “LATEST FOREIGN KEY ERROR…” The solution is to drop foreign key and any corresponding index before dropping the column.

Here are the steps that you must do

ALTER TABLE <table> DROP FOREIGN KEY <fk>;
ALTER TABLE <table> DROP INDEX <idx>;
ALTER TABLE <table> DROP COLUMN <column>;
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Installing Sup on Ubuntu Server 8.04 LTS

This is not a complete step-by-step set of instructions, but it should be pretty close.

sudo apt-get install ruby-full build-essential

wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
 tar -zxvf rubygems-1.3.6.tgz
 cd rubygems-1.3.6/
 sudo ruby setup.rb
 sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
 sudo gem update --system
sudo gem install rake

sudo apt-get install zlib1g-dev uuid-dev

sudo gem install ncursesw

 # We need this extra package
 sudo apt-get install libncurses5-dev libncursesw5-dev
 sudo gem install sup
 sup

Also had to make one code change, described here

#optional
#installed offlineimap
sudo apt-get install offlineimap

Links
Sup RubyForge Wiki
Use offlineimap with gmail – add some hooks
Setting up offlineimap for gmail backup
handy script examples to add sources

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Migrating from Hibernate 3.3.2, JPA 1 to Hibernate 3.5 CR2 and JPA 2

Starting with version 3.5 (currently CR2), Hibernate Annotations 3.x and Hibernate EntityManager projects have been merged into the Hibernate Core codebase as invidual modules. As a surprising addition, Hibernate Envers subproject is added as well (that’s a great thing as you get Auditing, out of box hereafter). So if you’re stuck with Hibernate 3.3.x and would like to try the almost final release, what do you need to do?

Unfortunately, the JBoss folks won’t tell you since they are very busy rebranding, redesigning their websites for the past couple of years (and it’s still so fragmented, I wonder why they just can’t hire a UI designer and a Content Manager. Talk about narcissist JEE programmers). Anyways, I wanted to try the new distribution since it’s getting close to the final release and it implements JPA 2. In case you’ve missed the boat, this is a good place to find out what’s new in JPA 2.

I tried the brute force method first: replace all 3.3.x jars with 3.5 CR2 jars.

Before: 7 jars
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate3-ast.jar
hibernate3.jar
envers-1.2.1.ga-hibernate-3.3.jar

After: 2 jars
javax.persistence.jar
hibernate3.jar — download from hibernate.org

Now, that’s a good sign. And all other optional and required dependencies (jta, javaassist, swarmcache,c3po, all other cache jars) haven’t changed.

But wait, where can you download javax.persistence.jar? Isn’t that supposed to be ejb3.1-persistence.jar? I’m not sure either. What I’m sure is this: There is no direct download link for the JPA2 api jar anywhere. Try it. Mail me if you find it.

I downloaded an entire GlassFish 3 distribution (JEE 6 reference implementation along with JPA 2) instead. And copied the javax.persistence.jar from its modules folder, instead. So in summary, I replaced the 7 jars with these 2 jars and does it work?

So, far my existing applications haven’t broken. The tests seems fine. And looks like the migration did work. Impressive.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

The Thoughtworks Rover Problem – Groovy Edition

I had some down time at work, and set about working on the Rover problem.

There are three problems, I chose the middle one to start with. I wrote it in groovy and used the very groovy clibuilder M. Laforge recommended in his comment. I mavenized it to make it easier to share.

You can find my solution here if you’re interested. It’s a good practice problem.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Simple Processes: Bash vs. Python – “A No-Brainer”

I haven’t posted in about 5 billion years. Well, it seems like that anyway. As I sit here partying with my laptop on a Friday night, I’ve been wondering how to display the track length of the current track that xmms2 is playing, without having to use the “xmms2 status” command. Yes, I listen to and control all my music via a full-featured music player/manager from the command line (xmms2). The problem with using the “status” command, is that it just prints out a continuous status of what’s playing and it just keeps going, which is exactly what it’s supposed to do. It’s just like “tail -f”, So you have to ctrl-c to get out of it. Yes. That is my sole motivation for doing this, to avoid ctrl-c. Well, and maybe to learn a thing or two, but mostly out of defiance of having to use ctrl-c.

So I figured, hey I know enough bash to at least get something rolling in order to do this. Of course I had to keep looking stuff up in reference guides and on websites, because there’s no way I can remember it all. Basically, it came down to 4 key tools for going the bash route.

1. sed – to strip brackets, slashes, colons, spaces, and other undesired characters in order to make the strings easier to deal with
2. awk – to find the location of decimal points or other characters
3. cut – to get characters to the left or right of decimal points
4. bc – to calculate and convert the milliseconds to human readable form

I finally got it to work reliably tonight.
It was a horrid process that took forever. What a waste of time. But hey, that’s all part of the RTC experience!
So here it is, please excuse the bad variable names and sloppiness. I was too pissed to give a ****.
Note: I renamed this to xmms2tracklensafe and cut out all the curse words and tried to put some sense into the comments.

#!/bin/bash
tmpfileinfo=xtemp14251.tmp
tmpfile=xtemp91839.tmp
#use xmms2 info here
xmms2 info > $tmpfileinfo
vargrep=$(grep "duration" $tmpfileinfo)
echo $vargrep > $tmpfileinfo
#chopping the brackets, slashes, and spaces out of the string
sed -i 's/\[//g' $tmpfileinfo
sed -i 's/\]//g' $tmpfileinfo
sed -i 's/\///g' $tmpfileinfo
sed -i 's/'\ '//g' $tmpfileinfo
#convert the = to an X, easy to find
sed -i 's/\=/X/g' $tmpfileinfo
#for an mp3 - pluginmaddurationX
sed -i 's/\pluginmaddurationX//g' $tmpfileinfo
#for a flac - pluginflacdurationX
sed -i 's/\pluginflacdurationX//g' $tmpfileinfo
#God knows what other codecs there might be
#prints the time in milliseconds
echo "$(cat $tmpfileinfo) ms"
vargrep2=$(cat $tmpfileinfo)
varx=$vargrep2
#convert the time to minutes
var2=$(echo "$varx/1000/60" | bc -l)
echo $var2 > $tmpfile
#we are left with a fraction of a minute, which occurs after the decimal, we need to find the decimal point
var3=$(awk 'BEGIN { print index('$var2', ".") }')
#get the characters after the decimal point, this is our fraction of a minute
var4=$(cut -c $var3- $tmpfile)
#convert that fraction of a minute into seconds
var5=$(echo "scale=1; $var4*60" | bc -l | xargs printf "%1.0f")
#simply subtracting a 1 from the index of the decimal point, to be used in order to retrieve the number left of the decimal
varcut=$(echo "$var3 - 1" | bc -l | xargs printf "%1.0f")
#gets the number to the left of the decimal
var6=$(cut -c -$varcut $tmpfile)
#now we need to deal with the decimal in the number that has been converted to seconds
var7=$(awk 'BEGIN { print index('$var5', ".") }')
varcut2=1
#I honestly don't remember why I did this.  I think I needed it before I started adding | xargs printf "%1.0f"
if [ "0" != $var7 ]
	then
		varcut2=$(echo "$var7 - 1" | bc -l | xargs printf "%1.0f")
fi

echo $var5 > $tmpfile
#now we get the seconds as a whole number, by getting the characters left of the decimal
var8=$(cut -c -$varcut2 $tmpfile)
var8=$(cat $tmpfile)

#need to prepend a 0 to the seconds if they are under 10
if [ $var8 -lt 10 ]
	then
		var8="0$var8"
fi

#print out the time in human readable form, minutes : seconds
echo "$var6:$var8"
#clean up the temp files
rm -f $tmpfile
rm -f $tmpfileinfo

Wow, what a pain in the pee-hole. It took me several hours over two nights and I even lost some sleep over it. So, I decided to try it Jeff’s way, using Python, since he brags about it so much. I had never used it before, and now that I have, I think I’ll be using it a lot! A lot of you are saying, “Well yeah, duh. Idiot.” or something more insulting, and I fully accept that. In fact, I encourage it!

First, we have the simple bash script that is used to execute the entire process from the command line.

#!/bin/bash

tmpfile=assscrambler124524.tmp
xmms2 info > $tmpfile

python ~/scripts/xmms2len.py

rm -f $tmpfile

And now we have the giant, complex, and horrendous python script.

file = open('./assscrambler124524.tmp')
for line in file:
	if(line.find('duration',0) > -1) :
		#print(line)
		s = line
		searchstr = 'duration = ';
		x = s.rindex(searchstr, 0);
		if(x > -1):
			timeMillis = s[x+len(searchstr):len(s)].strip()
			#print(timeMillis)
			timeConverted = float(timeMillis)/1000/60
			#print(timeConverted);
			stime = str(timeConverted)
			decIndex = stime.rindex('.', 0)
			timeFraction = float(stime[decIndex:len(stime)])
			seconds = int(round(timeFraction*60,0))
			strseconds = str(seconds)
			minutes = stime[0:decIndex]
			strminutes = str(minutes)
			if(seconds < 10) :
				strseconds = '0' + str(seconds)
			print(timeMillis + ' ms\n' + str(minutes) + ':' + strseconds)
			break

Wait, that’s it? Just some simple searches, substrings, calculations, easy conversions between types, and that’s all? Not to mention the incredibly easy way to open a file and iterate through its lines.
Now, I commented out some print statements here, and I could have compacted it more, but I wanted it to be reasonably clear. The point of course, and 95% of you know probably know this already, is that python kicks bash’s ass when it comes to things that should be, well, programs. Of course bash scripts will always have their place, and they are necessary for so many things. I still love bash and am very fond of it, but from a programming perspective, it just doesn’t “cut the mustard”, as Jeff would say.

Well, that’s it for my exciting Friday night. Someday I’ll get my crap together and talk more about my xmms2 setup, the xmms2 python equalizer, the xmms2 scrobbler for last.fm, and the other scripts I’ve written for xmms2.

Cya!

My main reference for python: http://www.astro.ufl.edu/~warner/prog/python.html

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Pimp My Emacs Post 1

I’ve been moving back to emacs, the editor of my youth.

I’m not a vehement emacs evangelical, and I don’t really hate eclipse. But I’m moving back for rational reasons. Basically, I just don’t like to wait to write code.

At my current client, I have a slow machine. This isn’t uncommon for consultants. It’s absolutely the dumbest thing in the world for a company to do- give their developers underpowered machines. It’s amazing how often it happens, but it’s a fact of life. My system has 2 GB of RAM. Once I have Eclipse, Hsqldb, the Rest server and web server all running I’m basically out of memory. Add all the utility apps and it’s completely spent.

Of course the number one use of memory on my system is Eclipse.

To really switch from eclipse though, emacs will have to do a lot.

For right now, I just wanted to add a mention of my new favorite mode in emacs- org mode.

I’m still a long way from using this effectively- I don’t have the keys memorized, and I still mostly use my dry erase board and notebook instead of jumping to org-mode right away. In short, it’s not ingrained as a habit yet.

One thing I’ve done with it that I am happy with, is that I save my org files to my DropBox, so I can keep my org files synchronized across computers. DropBox is a really slick app- and has clients for all platforms!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Upgrading to Hsqldb 2rc8, part 1, Maven Integration

At my current client engagement, we make full use of hsqldb both in our unit tests and for local development. It’s a great tool, and the changes made since the last release 4 long years ago will make it an even better tool.

My project has hundreds of tests making use of hsqldb, and getting the new version up and running is no small task. I’ve broken this post into two. The first will be the steps I took to get hsqldb integrated into our maven repository. The second will cover getting hsqldb up and running with our legion of tests.

The first important thing to know when upgrading hsqldb, is that the pre-compiled jar files were built with jdk6. This is probably going to be fine for many, but there are many others, such as myself, who would like to be on jdk6 but work at a client site still using jdk5. It sucks to be me, but oh well.

So the first step for me will be to compile the jars myself with jdk15.

To do this, it’s necessary to have 3 environment variables set, JAVA_HOME, ANT_HOME, and ANT_OPTS. Pretty standard. If you’re on windows, there is a setenv.cmd file in the distributed build directory that you can edit and execute in the cmd shell.

At present, the build.xml contains a small bug for users trying to build the jar with jdk15. The “store” target contains a list of depends attributes:

depends=”switchtojdk11,switchtojdk12,switchtojdk14,switchtojdk16″

To build with jdk15 this must be changed to:

depends=”switchtojdk11,switchtojdk12,switchtojdk14,switchtojdk15″

(I’ve added a bug for this on sf)

Next run the following ant tasks from the hsqldb/build directory:

ant hsqldb;
ant sqltool

This will build the jars to the hsqldb/lib directory.

Next step is to add the jars to my local maven repo.

mvn install:install-file -DgroupId=hsqldb -DartifactId=hsqldb -Dversion=2.0.0 -Dpackaging=jar -Dfile="/Documents and Settings/ujxh744/My Documents/Downloads/hsqldb-2.0.0-rc8/hsqldb/lib/hsqldb.jar"
mvn install:install-file -DgroupId=hsqldb -DartifactId=sqltool -Dversion=2.0.0 -Dpackaging=jar -Dfile="/Documents and Settings/ujxh744/My Documents/Downloads/hsqldb-2.0.0-rc8/hsqldb/lib/sqltool.jar"

and update our main pom.xml with the new version of hsqldb and with a new entry for the sqltool:

<dependency>
<groupId>hsqldb</group>
<artifactId>hsqldb</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>sqltool</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>

And that’s it. You should be off to the races. Next up I’ll write about some of the sql changes.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dreamhost Django Install, Revised Edition

I recently went back to doing some Django development after a long lapse, and decided to start by eating my own dogfood…

I started by upgrading Python for my Dreamhost user. I followed my own post, except that I used Python 2.6 instead of 2.5. I missed one step that was caught by a pingback post:

In addition to the steps I outlined before:

$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
$ tar xvzf Python-2.6.4.tgz
$ cd Python-2.6.4
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install

Next append

export PATH=$HOME/opt/bin/:$PATH

to your .bash_profile. Then test (from your home dir):

$ source .bash_profile
$ python -V
Python 2.6.4

If you don’t see Python 2.6.4 after typing python -V then you’ve already done something wrong.

I had to install the Python setuptools:

$ wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg
$ sh setuptools-0.6c9-py2.6.egg

before installing Mysql-Python as before:

$ wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz
$ tar xvzf MySQL-python-1.2.2.tar.gz
$ cd MySQL-python-1.2.2
$ python setup.py install

So this brought me to the point where I had an updated version of Python on my Dreamhost account.

Next to set up Django.

I looked at setting up Django with the Dreamhost script, which didn’t seem to work for me but I don’t remember why not. In the end I found SOASI’s post the most useful, although I did it a little differently.

First up, configure your domain.

In Dreamhost panel -> Domains -> Manage Domains click on the domain you want to put your app on (in the example we will set domain.com), and activate “Ruby on Rails Passenger (mod_rails)” option.

Create a public directory in that domain.

Next make sure you have your database setup. You don’t have to have a database for Django now, but if you plan to use one now is a good time to get that set up.

Next I downloaded and installed Django.

I liked the directory structure suggested by Dreamhost. This will work well for having one Django directory and use it for multiple projects on multiple domains.

 /home/username/django/
   source (your django svn checkout, or skip it and use Dreamhost's site-package of Django)
   projects
   applications (any reusable applications shared between projects)

Finally, I added the media and admin media, and also the passenger_wsgi.py

import sys, os
if sys.version &lt; &quot;2.6&quot;: os.execl(&quot;/home/user/opt/bin/python2.6&quot;, &quot;python2.6&quot;, *sys.ar
gv)
sys.path.insert(1, &quot;/home/user/django/source&quot;)
sys.path.insert(1, &quot;/home/user/django/applications&quot;)
sys.path.insert(1, &quot;/home/user/django/projects&quot;)
os.environ['DJANGO_SETTINGS_MODULE'] = &quot;project.settings&quot;
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

On /home/user/django/projects/myproject/settings.py file check settings:

MEDIA_ROOT = '/home/user/domain.com/public/media/'
MEDIA_URL = 'http://www.domain.com/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

Create a symbolic link for admin_media:

cd /home/user/domain.com/public/
ln -s home/user/django/source/contrib/admin/media/ admin_media

Django and Python are still new to me, so you get what you pay for with this setup.

Note:
I found this today, and it looks like it could be a good setup too.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]