History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com

Tuesday, 10 March 2009

Generate a random string in Clojure

In my quest to learn Lisp, I discovered Clojure, a List inspired language on the JVM. I really like it and hope to be able to use it more and more.
Here's a code snippet to generate a random string in Clojure. This is something I end up using a many projects. This is a version that is not made to be the shortest, but the most readable. And as you can see, access to Java's classes and libraries is very easy:


:use java's random generator
(def random (java.util.Random.))
;define characters list to use to generate string
(def chars
(map char (concat (range 48 58) (range 66 92) (range 97 123))))
;generates 1 random character
(defn random-char []
(nth chars (.nextInt random (count chars))))
; generates random string of length characters
(defn random-string [length]
(apply str (take length (repeatedly random-char))))


Suggestions to improve the code are welcome, I'm still a newbie in Lisp-style programming and Clojure!

Monday, 9 March 2009

Linkedin problems

The last weeks I've had serious problems to access linkedin: I can't accept group memberships, send invitations, accept invitations, etc: when attempting this, the browser waits and waits and doesn't get any answer from the server. And today I can't even access their homepage:



Very annoying...

Wednesday, 18 February 2009

UploadForMe open to all

I just lifted the need of an invitation to register for an UploadForMe account at http://www.uploadforme.com/a/signup.
With such an account, you can discover how the platform works, as you can upload files (one at a time currently) and then send them to Picasa, Flickr or Youtube.
Importing large number of files by sending a DVD is still limited to users contacting me about it.

Wednesday, 28 January 2009

Uploadforme open to beta testers with 4Gb of free transfer

Finally, Uploadforme.com is opening the gates!

The idea of the service is simple: help you bring your digital content online. You send it on DVD, we put it online on our server from where you can then import it in the online service you want (currently supported: flickr, picasa, youtube).

Let me know if you want to be part of the beta phase, we propose to put online 4Gb of data from our beta test users for free.

Friday, 23 January 2009

Using the clipboard in vim

How many vim users know that you can copy from and paste to the clipboard?
It's even very easy: use the register +
To use a register with a copy or paste command, you specify it by typing " followed by the register name.
So, to copy to the x register and the clipboard:
"+y
and to paste from the x register:
"+p

I think this would be best illustrated by a screencast. Anyone interested in vim screencasts? Should I take the time to do some vim screencasts? Let me know.

Sunday, 11 January 2009

BDO darts world championship over

The 2009 BDO Lakeside World Professional Championship, a one week darts competition, ended today, with the title going to Ted Hankey after a great and dramatic final, decided in the final set.
Tony O'Shea lost his 4th final of the year, sad for him :(

Before you laugh that I'm looking darts competition on television, did you ever watch a match? Everyone I've talked about it laughed at me first, but got caught when watching. I've started looking at it during my exams as univ, and try to follow the championship every year. I dont watch other competitions, so I can't comment on them, but the BDO world championship at the Lakeside is something you should give a try, usually on BBC2 around this time of the year. That will be for 2010 though!

Sunday, 14 December 2008

Capistrano deployment for Jetty-Rails

As I have developed the (soon to be available) UploadForMe application with Jruby on Rails, I have had to look at the best way to deploy it in production. In development mode, I was just running the script/server with Jruby, but I needed something better for production.

I had first tested the Glassfish approach of running an Java application server. And although it isn't hard at all, as illustrated by Charles Nutter in his post correctly titled "Zero to Production in 15 Minutes", it wasn't practical for me: just running Glasfish consumed 300MB of RAM and impossible to run on my development machine. So I had to look somewhere else.

That's how I found Jetty-Rails.The way to run your JRuby on rails apps is so simple I thought their documentation was lacking! But it is really as simple as installing the jetty_rails gem!

The only missing piece were recipes and scripts to start, stop and restart the application when deploying with Capistrano. It was a simple matter of writing 2 scripts and the Capistrano recipe, with some experimentation in between I must admit :-)

Anyway, here are the scripts. The pid of the running jerry_rails process is stored in the file shared/tmp/pids/jetty_rails.pid.

script/spin




script/stop_jetty


There's a config file shared by these 2 scripts, put in script/jetty_config:


Put this in config/deploy.rb:


Notes


The start recipe is overwritten to add the option :pty => true. Without that option the nohup command isn't effective.
Using the nohup command is needed because there's currently no way to send the process to the background as a daemon, nor to store the PID in a specific file. These scripts do both.