pdf thingy

I’ve spent a couple of hours tinkering with pdf export from wave. I put the result here :
pdf-thingy@appspot.com . You can invite the bot to your wave, when you do it will present a link to a pdf version of the root blip. No fancy colors yet ;)

Somebody pointed me to PDF Wave Exporter, but I could not find the source code for it to tinker with. (I admit that I did not look that hard).

I implemented pdf thingy to learn more about python,wave and google appengine.

I based pdf-thingy on exporty by Pamela Fox , available from google code . This tutorial helped me learn about reportlab on google app engine.

You can find the code here: http://github.com/jacobandresen/pdf-thingy

There are some obvious points of improvement:
- handle text overflow
- supporting annotations
- fancy color templating

icanhas javascript OOP?

In javascript we can express objects using the prototype notation:

  var Cat = function () {
     this.furry = true;
  }
 Cat.prototype.greet = function () {
   return "meeow";
 }

using class mimicking from prototype-js it would be :

 var Cat = new Class({
  initialize: function (){
    this.furry = true;
    },
  ask: function (item) {
   return "icanhas "+item+" ?";
 });

This example should be pretty clear. But when we get into real-life application scenarios we need to interact with users and databases.

Let’s say we had a panel and a button for interacting with lolcats:

var CatInformationPanel = Class.create({
   initialize: function (container) {
     $(container.id+'_furry').checked = true;
     $('petButton').observe('click',  this.ask.bindAsEventListener(this));
  },
  ask:  function (item) {
    $(container.id+'_text').value ="icanhas "+item+" ?";
  }
});

Note that we need to bind “this” to the the function scope for “ask”. this is one of the intricacies of object oriented javascript. Here are some badass ninja examples to explain why.

Now, after interacting with user , you probably want to save the result to a database. let’s assume that you have a resource /lol/cat/questions you can issue a HTTP post to (you can create this using rubyonrails or something similar).

var CatInformationPanel = Class.create({
   initialize: function (container,name) {
     this.name = name;
     $(container.id+'_furry').checked = true;
     $('petButton').observe('click',  this.ask.bindAsEventListener(this));
  },
  ask:  function (item) {
    var question = "icanhas "+item+" ?"
    $(container.id+'_text').value =question;
   var request = new Ajax.Request ({
      "/lol/cat/question", {
        method:'post',
        params:{ name:name, question:question },
        onSuccess: function (json) {
           alert("saved question");
           }
     }
    });
  }
});

gemcutter: the missing manual

Thanks to Jakob Kruse I now know how to operate RubyGems and gemcutter on windows. Here’s what I did:

1:I downloaded the 1.8.6 ruby installer here

2: I installed gemcutter like this:

gem update --system
gem install gemcutter
gem tumble
gem install jspec

this let me use gemcutter on windows using the current one-click installer ;)

adventures with mingw , ruby,java, rhino and jspec

update 2009-10-21: This post is a writeup of my early experiences with gemcutter and rubygems. The strange runtime error I did not understand was probably related to that I needed to update rubygems to 1.3.5. I now know how to use gemcutter from ruby1.8.6 using the oneclick installer .

I have been using jspec on macosx for a while and decided to give it a try on windows vista today. Installing jspec on macosx and linux can be done using the instructions here .

I want to run the automated jspec tests available via rhino at a client site. Sadly , I am forced to use windows there, so I have given some thought on how to make jspec run on windows.

First of all you need to install ruby. I used the automated 1.8.6 One-Click Installer available here . After installing i ran


gem update

the instructions in the README file for jspec currently states that I should install gemcutter and install jspec via that . I was not able to do that on windows ( my system decided to report an obscure runtime error that I did not understand). So i decided to do this instead:


gem sources -a http://gems.github.com
gem install visionmedia-jspec

I let gem install the required dependencies visionmedia-commander and visionmedia-bind. After this I had the jspec script available. Sadly this gave me version 2.7.2 (I noticed \ruby\lib\ruby\gems\1.8\gems\visionmedia-jspec-2.7.2 ) The listing on gemcutter told me that a version 2.11.10 is a avaiable , so I decided to dig deeper. Maybe I could make gemcutter work anyway?

After a little browsing on github.com I found the oneclick installer

I cloned this repo using git

using the following command:

git clone git://github.com/oneclick/rubyinstaller.git

and pressed


rake ruby19

This project creates a sandbox that compiles a working ruby environment using mingw.

After contemplating the insanity of what I was doing for a couple of minutes (remember : installing a working ruby on linux is a single shell command) I grabbed some coca cola and started browsing through the source code for ruby distro while the rubyinstall was compiling. I looked a bit at ruby.c and vm_exec.c and had grim flashbacks to my c days. Luckily the compile finished and I copied ruby19_mingw to my c:\ drive and set it up on my PATH variable. Then I could check which version I was using:


C:\>ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]

Now I was able to do:

gem install gemcutter
gem tumble
gem install jspec

(Note that there is information sent to the terminal during these steps)

Now for the interesting part(!) jspec was working , so I could do this:


jspec init SolitaireCipher --freeze

This created a directory where I can train doing the SolitaireCipher using javascript. I renamed lib/yourlib.core.js to lib/SolitaireCipher.js and spec/spec.core.js to spec/spec.SolitaireCipher.js and spec/spec.dom.html accordingly.

After 20 mins of fiddling I managed to get some running tests in a browser by opening spec.dom.html. Then I decided I want to automate the tests using mozilla rhino. After installing rhino , I could run automated tests like this


cd c:\projects\SolitaireCipher
jspec --rhino

This opens up a proces that listens to file changes in the lib and spec folders. All very well – untill I discovered that jspec currently uses ANSI codes to render colors to the terminal screens. ANSI codes are not supported on windows vista (something with ANSI.SYS being obsoleted), so if I want the nice colors then I need an alternative terminal than my command prompt in vista.

I found rxvt available from PortableGit on google code. This renders the colors just nicely – but has some other drawbacks. If I just use rxvt for rendering feedback from the jspec tests, then it seems to work though.

One thing to note is that rhino needs the java sdk to be installed and js.jar needs to be on your CLASSPATH. when starting jspec from rxvt on the msys from PortableGit, then CLASSPATH could be set like this (assuming rhino is installed in c:\tools ):


export CLASSPATH=/c/tools/rhino1_7R2/js.jar

I probably want to avoid using rxvt on PortableGit too much . There are some major flaws listed here .

Maybe I should look into doing a adobe air frontend for jspec?

unclebob does the prime factor kata

update 2009-11-12: There is an updated version here

unclebob doing the prime factor kata: