Archive for the ‘Coding’ Category

Clojure’s REPL and Readline

Friday, July 4th, 2008

The standard advice for getting a practical REPL for Clojure is to use jLine, but that’s not really necessary if you’re not on Windows. rlwrap does the job admirably, and was only an

apt-get install rlwrap

away for me.

Updating Metadata for 722 gems! AARGH!

Thursday, June 26th, 2008

Seriously. Is this really necessary?

alex@21:~/Documents/Projects/VPNGen$ gem search scp --remote

*** REMOTE GEMS ***

Updating metadata for 722 gems from http://gems.rubyforge.org/
..............................................................................................
..............................................................................................
..............................................................................................
...............................ERROR:  Interrupted

Clojure, Slime, Documentation?

Thursday, June 26th, 2008

Update: It turns out that the Gutsy-included version of slime is rather out-of-date, and the clojure scripts are based on the CVS version. If you’re having the problem below, get thee hence and cvs thyself.

There seems to be a general theme in the emacs world. If I could give it a voice, it might say “I’m great. No, I’m not going to tell you how to use me. You mean you don’t already know?”

Let me put this in context. You might be able to tell from my previous posts that I’ve got a long-standing, from-a-distance interest in all things lispy. Naturally, my attention fell on Clojure (fairly recently, admittedly). My next thought was that I should get slime set up to use it so that I could use a natural environment to try it out, and this is where things started to get dicey.

Almost everything works; here’s the relevant section from my .emacs:

(defun set-clojure-inferior-lisp ()
  (setq inferior-lisp-program
        (let* ((java-path "java")
               (java-options "")
               (clojure-path "~/Documents/Projects/clojure/bin/")
               (class-path-delimiter ";")
               (class-path (mapconcat (lambda (s) s)
                                      (list (concat
																						 clojure-path "clojure.jar"))
                                      class-path-delimiter)))
          (concat java-path
                  " " java-options
                  " -cp " class-path
                  " clojure.lang.Repl"))))

(defun clojure-boot ()
  (interactive)
  (require 'slime)
  (setq slime-net-coding-system 'utf-8-unix)
  (slime-setup)
  (add-to-list 'load-path "~/emacs/clojure-mode")
  (require 'clojure-auto)
  (set-clojure-inferior-lisp)
  (setq slime-lisp-implementations
        '((clojure ("~/emacs/clojure-extra/sh-script/clojure")
                   :init clojure-init)))
  (add-to-list 'load-path "~/emacs/swank-clojure")
  (require 'swank-clojure)
  (cua-mode t)
  (slime))

The annoying thing is what doesn’t work: exceptions are getting lost, and the error message that comes back for each and every one is distinctly unhelpful:

error in process filter: Wrong number of arguments: nil, 3

Where do I go from here? Google knows nothing of this error. I’ve emailed the author of the swank-clojure code for assistance; I’ll update here if I get anywhere with this. It’s really frustrating to be this close to what looks like a brilliant development environment, just to hit a brick wall like this.

VirtualBox, KVM, Windows and Linux

Thursday, June 12th, 2008

Today I’ve been mostly bringing a new subcontractor up to speed on a project I’ve been working on for a while. It’s quite a fun project that I’ll probably post about at some later date (think _why’s mousehole on steroids), but what I’ve spent most of my time on is wrangling virtual machine images.

For me, kvm is the first (free) virtual machine host system that makes everything Just Work. I always had problems with UML and Xen, qemu was too slow, and I always shied away from VMware. Not entirely sure why, but there you go.

Now, back to this contractor: he’s on Windows, I’m on Ubuntu Gutsy. I know that my code won’t work on Windows, because I’m daemonising and fork()ing all over the place. VMs to the rescue! It looks to me like the best combination is kvm on my side, and VirtualBox on his. There’s a very simple conversion that lets me convert my qcow image to a vmdk that VirtualBox can read:

qemu-img convert etch-rodents-i386.img -O vmdk etch-rodents-i386.vmdk

I’ve not seen this documented anywhere; most google hits mention the obsolete vditool, which I couldn’t get to run on my 64-bit host anyway.

Added bonus: the vmdk image is slightly smaller than the qcow. Win.

ERB quine fun

Sunday, April 8th, 2007

Quoth Ken Bloom on the ruby-lang mailing list:

If you really want to be evil and twisted, what’s the smallest self-
reproducing erb program you can write that doesn’t read its own file.

And who could ignore a challenge like that on an Easter Sunday? This is the best I could do:

<%=s=">%"}esrever.s{#}tcepsni.s{#=s=%<";";"<%=s=#{s.inspect}#{s.reverse}"%>

77 characters of fun.

Ruby Docstrings

Friday, March 23rd, 2007

I can’t be the first person to come up with this, but since Google doesn’t show anything, I figured I’d share it.

Take the following code:

class Rect
  d"Calculates the area of the rectangle." do
    def area
      length * height
    end
  end

  d"The height of the rectangle." do
    attr_accessor :height
  end

  d"The length of the rectangle." do
    attr_accessor :length
  end
end

This lets us do:

irb(main):035:0> Rect.__doc__(:length)
=> "The length of the rectangle."
irb(main):036:0> Rect.__doc__(:area)
=> "Calculates the area of the rectangle."

Yay! Docstrings! So, how does this work?

(more…)

Ruby on Sarge…

Tuesday, March 6th, 2007

…is broken. Well, not really, but it does feel that way sometimes. Not only is the version of Ruby rather out of date (1.8.2), it’s split into separate packages so that you’re never sure if you’ve got everything you need, or if, when something’s not working, it’s because you just forgot to apt-get install something.

As an example, I was trying to get the wonderful Mechanize library working the other day. No matter what I tried, it just wouldn’t fly with the native Ruby – it complained about the Net::HTTP#use_ssl? method not being available. I couldn’t find any combination of packages that would do it. My usual port of call would be checkinstall, or possibly hacking the gem itself, but for one reason and another that wasn’t a viable option this time, and I didn’t have the time to get the editor out and get my hands dirty.

Enter Backports. I’d not had cause to use it before, but it really saved my bacon this time. Ruby 1.8.5 installed cleanly, Mechanise works, and the client and I are happy bunnies. Yay. Check there for instructions – it’s dead simple, and if you’re using a Sarge box, I reckon it’s too good not to know about.

You Don’t Need A Meaningful API If You’ve Got Meaningful Error Messages

Wednesday, February 14th, 2007

Woo, long time no update.

Anyhoo, in my WPF explorations today, I managed to trigger this little gem:

System.ArgumentOutOfRangeException : '100' is not a valid
Percent value for a KeyTime. The Percent value must be a number
from 0.0 to 1.0.

What the hell were they thinking?

Django Vs Rails

Monday, December 4th, 2006

I’ve just kicked off a new project, and because I’ve been looking for an excuse for a while, I thought I’d give Django a try.

Python was an interim language which I toyed with a while ago, but I discovered Ruby before I got that comfortable with it. Nevertheless, I did enjoy it, and I am familiar enough with it that the language barrier wasn’t an issue. After a couple of days, it became clear that Django just wasn’t cutting it – I’ve reverted to Rails as a result. There were two main problems I had which made me shift, and I don’t think it’s just me being stuck in my ways.

The first of these was that Django doesn’t have anything like Rails’ migrations. These are an absolute godsend, to the extent that on the past couple of PHP projects I’ve been shanghaied into, I’ve duplicated their functionality as much as possible. They save me so much time and hassle.

The second is the half-hearted nature of Django’s testing framework. Admittedly, I was using 0.95 rather than the development version, but it’s really quite paltry compared to what you get out of the box with Rails. I just couldn’t get comfortable in the same way as I found I did quite quickly when I first started learning Rails.

It’s quite possible that these problems will go away by the time Django hits 1.0, or even that they’re addressed well enough in the development version that I’d be happy with that. I have serious reservations about learning a framework with a development version, though – it’s too easy to stumble on a dev bug and not know if it’s a fault in your own code.

I’ll probably come back to Django at some point – it’s got a lot to recommend it – but for me it’s just not quite there yet.

Updated the Lexicon

Monday, September 11th, 2006

Just made a quick update to the Lexicon page. In a nutshell, it turns out that you can animate PerspectiveCameras in exactly the same way as Model3Ds, because they support a Transform property. I haven’t had a chance to play with it properly yet, but it means no more fiddling with Vector3DAnimations to change LookDirection any more. Woohoo!

Oh, and it looks like the same applies to Lights. More Woohoo!

Entries (RSS)