Strange Loops

No Matter Where You Go, There You Are

Happy New Year!

| Comments

Happy New Year! I know it's 10 days into the new year but I have not gotten around to posting on my blog yet. One of my resolutions for the new year is to post more consistently. Hopefully I hit that goal this year.

2010 is going to be the year of awesomeness! I can feel it.

New Project: CCTV

| Comments

One little project I’m undertaking is to build a CCTV system for the house. A little background, last Christmas our place got broken into. Among other measures, a CCTV/camera system was something we wanted to install. The requirements are basically to be relatively cheap and preferably with motion detection so the cameras don’t need to be turned on constantly.

The biggest cost to the system is likely to be the cameras. For prototyping, I will use an old Ubuntu box and getting one camera to start with. ZoneMinder is the software that will be running on the Ubuntu box.

After doing some research, the D-Link DCS-920 will be the initial camera for prototyping with. It seems to be the best compromise between cost and features. It’s wireless and appears to have fairly decent image quality.

Building ØMQ on My Mac

| Comments

In my plans for world domination, I need messaging software. I wanted to try out ZeroMQ (trying out RabbitMQ is for another weekend). I’m skipping ActiveMQ since we use it at work and I mostly understand what it provides.

Downloaded the tarball and it compiled right out of the box. However when I tried to get it to run with a simple java program I’ve written, I kept getting this error (this is on Leopard).

dc@feynman:dist$ java -Djava.library.path=/opt/personal/pkg/zmq/lib -classpath lib/Zmq.jar -jar ZmqTest.jar 
Creating ZMQ
Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: no suitable image found. Did find: /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: mach-o, but wrong architecture /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: mach-o, but wrong architecture
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1881)
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1805)
 at java.lang.Runtime.loadLibrary0(Runtime.java:823)
 at java.lang.System.loadLibrary(System.java:1045)
 at org.zmq.Zmq.(Zmq.java:25)
 at zmqtest.Main.main(Main.java:15)

As far as I can guess, the JVM I’m using is 64bit so the libraries it loads also need to be compiled as 64bits. To fix this, I had to set the CXXFLAGS environment variable to build 64 bits. This set of steps worked for me.

export CXXFLAGS="-arch x86_64" 
./configure --prefix=/opt/personal/pkg/zmq -with-java
make clean
make
make install

Here’s my small java program

package zmqtest;
import org.zmq.Zmq;

public class Main {
 public static void main(String[] args) {
  System.out.println("Creating ZMQ");
  Zmq zmq = new Zmq("localhost");
  System.out.println("Done creating ZMQ");
 }
}

Great Quote

| Comments

On the eve of the race, I found this great quote at cafe ladro. Great quote
Happiness is a by-product of function. Those who seek
happiness for itself seek victory without of war.
- Willam S Burroughs

Mapping “Caps Lock” to Control on My Mac

| Comments

Since I've been hacking Clojure with Slime on Emacs, I've found myself wanting the Caps Lock key to work as the Control key. This makes some of the key combinations with Emacs easier to hit. Leopard makes this easy (almost too easy!).

First open "System Preferences", and select the "Keyboard And Mouse" preference pane.

SystemPreferences

Then click on the "Modifier Keys" button.

KeyboardAndMouse

Finally pick Control for the Caps Lock key. Note that I made Caps Locks and the Control keys work as Control. Initially I swapped the functionality of the keys and found that years of using Control in the old location made me hit it too often. Since I rarely used Caps Lock, I decided to just make both of them Control.

Control

QED!

Setting Up Clojure, Emacs and SLIME

| Comments

[Update: I redid these instructions when I moved to clojure 1.1 . Take a look if you're interested]

For the last couple of days, I've been enjoying the combination of Clojure + Emacs + SLIME . Getting it working on my Mac was relatively straightforward (although I hit one minor bump). 

To get started, git and Java 6 need to be installed on your Mac. I used the Java 6 SDK supplied by Apple (Java 5 might also work but I'm not using that). git was installed through MacPorts .

1. Get clojure-mode

> mkdir ~/src
> cd ~/src
> git clone git://github.com/jochu/clojure-mode.git

2. Add these lines to your .emacs

(add-to-list 'load-path "~/src/clojure-mode") 

(require 'clojure-mode)

Restart emacs (or evaluate the 2 lines above)

3. M-x clojure-install (inside emacs)

Voila_Capture12

You'll be prompted with a default installation directory of ~/src. Note the M(eta) key here is mapped to my Alt and Esc key. YMMV.

Voila_Capture13

I used the default.

4. When done, you'll see something like this.

Voila_Capture14

5. If you do as the instruction suggest, you'll get an error about missing a file or directory.

Voila_Capture15

6. Add the following lines to your .emacs

(setq swank-clojure-classpath '())
(add-to-list 'swank-clojure-classpath "~/src/clojure-contrib/clojure-contrib.jar")
(add-to-list 'swank-clojure-classpath "~/src/clojure/clojure-1.0.0-SNAPSHOT.jar")
(clojure-slime-config)

Restart emacs (or evaluate these lines). Note: you can use the swank-clojure-classpath variable to add jar files or directories to your classpath to work with in SLIME.

7. M-x slime

Voila_Capture17

You're done! Have fun. To get started with clojure, I recommend this book:

P.S Some weirdness with the formatting. I was having trouble with the blog editor. 

Vimperator

| Comments

Went old school this weekend setting up the old T41. old school = maximise keyboard usage, minimize mouse usage.  I've been a vim person for a long time and vimperator has been on my todo for awhile. Vimperator is a firefox plugin to use vim key bindings. With my vim background, the experience of navigating the web has been pleasantly surprising. It's amazing how fast I was able to navigate the web with just the keyboard. I didn't run any tests with a stopwatch but it felt faster than just the mouse and keyboard. 

There were some annoyances which I fixed by putting some config into my ~/.vimperatorrc

" disable the annoying audible beeping
set visualbell

" make a disable vimperator for gmail and google reader, activate by doing :disable and :enable. tip was from here
js function disable() { liberator.execute(':set guioptions=Tnbrm showtabline=1'); modes.passAllKeys = true; }
command disable javascript disable()
command enable set guioptions= showtabline=0

Preloaded Cruft

| Comments

Went through the exercise of removing unwanted stuff on a PC notebook today. Replaced crappy proprietary software with better open source alternatives. I can't help but wonder if the low cost of notebooks is forcing PC manufacturers to pursue other revenue streams to cover cost.

I was tempted to go the Ubuntu route then decided against it since the notebook was not for me.

Weekend

| Comments

Trying out the new TypePad. The differences are there but I'm not noticing anything major. This was the first weekend for the last couple of months where no running was done. Between recovering from the marathon(a month ago), the cougar mountain trail run, Ragnar and the twisted ankle, I was taking it really easy this weekend. It was a nice change of pace not to wake up early on Saturday or Sunday. That gave me sometime to play with technologies and write down some ideas.

Been meaning to try out Aptana Studio and Jaxer. Finally got a chance to do that this weekend. Like the concept for Jaxer bur was really impressed with Aptana Studio. It has a whole bunch of auto complete stuff I didn't expect. I've not been in the IDE world for too long (still preferring a good old text editor) but for new technology an IDE really helps with the learning curve. Might be hacking some rails code with Michael and looking to give Studio a try.

Didn't get too deeply into it but also mucked about with Hadoop, Cappuccino and picked up where I left off with Clojure from a couple of weeks back. Finally settling on Aquamacs + Swank to work with Clojure. Could not get textmate working with the REPL. Also downloaded the MPS language workbench but didn't install it. Also reminded me about the whole language workbench I want to look at and the little pyparsing project I have with Riley.

The two things I didn't get too was the Leksah Haskell IDE and the algorithms class form MIT OCW. Also still looking to build a website with Django, Drupal and SInatra.

Played with a couple of new apps from MacHeist and MacUpdate promo package. Checked out the Project Natal stuff from Microsoft, looks cool but I'll need to try it to be convinced.

Too much stuff. Not enough time.

Oracle to Mysql Gotcha

| Comments

At the new job, we use MySQL. I’ve mostly worked with Oracle before this and while not expecting everything to be the same, the transition has been smooth.

The one gotcha that threw me for a loop is MySQL’s default transaction isolation level for. With Oracle, once data is committed, it’s available to be read by all other connections. With MySQL, your view of data is determined by the first query made after the connection is open.

One rationale (I was given) is MySQL has fast connection setups and connections are setup and torn down between queries. I’m not sure I believe that though….

The solution was to change the isolation level for my session via the following incantation:

SET TRANSACTION ISOLATION LEVEL READ COMMITTED


(Taken from the mysql reference manual page)