Happyprog runs on Amazon S3
A couple of days ago, I launched a tiny site called happyprog. My current idea with the site is to write small fun utilities to help programmers visualize some core eXtreme Programming practices like test driven development and refactoring. That sounds very grandiose and I might seem that I know what I am doing but I am just experimenting with a few ideas that rounded my mind for a while.
Right now, these ideas are coming out as plugins for Eclipse.
As I was getting closer to release my first experiment: Pulse, Amazon S3 announces support for hosting static websites. I am usually a big fan of Google App Engine, it’s easy and magic to quickly build and deploy a website with python and web.py.
However, for this project, the installation of an Eclipse plugin usually requires a static website to host a bunch of configuration files and jars files. So, I decided to follow the Amazon S3 route all the way and host everything on S3.
Their documentation is a good start and here are a few tricks that I learned along the way.
Your S3 bucket name needs to match your website name. In my case my bucket name is “www.happyprog.com”.
To redirect your domain directly to your S3 bucket, you need to remap the “www” CNAME to point to your bucket end-point. My bucket end-point is http://www.happyprog.com.s3-website-us-east-1.amazonaws.com/ so the value for the “www” CNAME should be “happyprog.com.s3-website-us-east-1.amazonaws.com”.
This change can take up to 24 hours, so it’s just a matter of patience
So far, one of the advantages to use the app engine over an S3 bucket is that I can push code without to worry about deleting old files. Right now, I am uploading and maintaining the site with Cyberduck. So the process is manual.
One of the advantages to use S3, is that I hope I don’t run out of cycles like it happened on the app engine a couple of times. I am also using the free account of the app engine, so I can’t complain.
…We’ll see what happens when I receive my bill from S3 next month.
First Impressions with the TypeMatrix 2030 keyboard

I got my new keyboard this weekend and here are my first impressions.
Since I started learning Dvorak early this year, I have been lucky to pair almost exclusively with a Dvorak user. This has been great because changing keyboard layouts in Windows is really annoying. The keyboard configuration only affects the current window in focus, so we need to use the mouse to change the layout in the language bar. On OSX, it’s a little easier, we can bind a shortcut to change the keyboard layout across all the windows.
I had a few qwerty sessions lately and I was surprised to find myself at a lost with qwerty. I had to look down and pick the keys with my index finger resulting in me not typing a whole lot on those sessions. The opposite was happening when we were using my machine for pairing. I ended up doing all the typing.
All the back and forth changes in configurations can ruin a pairing session. So I decided to look for a hardware switchable dvorak keyboard. These type of keyboard allows to plug into any machine and start typing in the Dvorak layout without having to do any software configuration.
There are not many keyboards on the market that can do this so the choices are limited.
I went for the TypeMatrix 2030 after reading a few blog posts about it. And so far, I am fairly happy with my choice.
Things that are great about this keyboard:
The keyboard feels very sturdy and the size is around 13 inches so it’s easy to pack it for my commute.
The Home row bumps (the little things that help you know that your middle fingers are on the right position on the home row) feel great. Better than any keyboard I had in the past.
The separation between the two hands feels comfortable
It took me no effort to get used to the “boxed” layout that is unique to the TypeMatrix.
Since I always remap the caps lock key to control on all my computers, the TypeMatrix has a separate caps lock THAT SOMETIMES IS USEFUL TO HAVE.
The backspace and the enter keys in the middle of the keyboard are weird at first but after a few paragraph, it grows on you.
The look of it makes you part of a Sci-fi movie right away.
The parts that could be better:
The control key is no longer my caps lock key, so I need to stretch to reach it. It’s not too bad because the keys on the end of the keyboard also have a bump make it easier to find.
The hardest key for me to get is the ‘k’. I always end up getting to the ‘x’ instead. It’s getting better as I finish this post.
The arrow keys don’t stand out for the layout so reaching them is harder, I have to look down to find them. There is another bump on them, so I might just need some more practice there.
I wish TypeMatrix would offer a bluetooth version.
Overall, this is a very cool looking and sturdy keyboard. I am very satisfied with it and hope to get a lot out of it at work and at home.
I am learning Dvorak
I have to confess that I never learn to touch type correctly. That has been bothering me for years. It’s not that I am slow, I almost use all my ten fingers, but I lack of precision. My accuracy could be better.
Two years ago, over the break of a long weekend, I decided to give Dvorak a try. I even reconfigured the keys on an old keyboard to match the Dvorak layout to ease my switch.
That didn’t last long. On the first afternoon back at work, I went back to type in QWERTY. Simple emails would take me a hundred times longer. I could not work. The week after that, I spent some time improving my QWERTY typing and felt a little more satisfied with my performance.
Fast forward two years, last summer, Corey Haines launches learn to type week. I related a lot with Corey’s message and decided to participate and improve my typing again.
I was getting better but at the same time, it was hard to kick out old habits. I went a little further than Corey’s week and regularly completed a few exercises a week until the Christmas holidays.
I established a goal during the holidays to focus on my QWERTY accuracy. I also reviewed Steve Yegge’s essay on programming’s little dirty secret to get me pumped out about my goal. While typing QWERTY, I was also reading about other layouts like colemack and Dvorak. I was curious if something had changed in the last two years.
And then it happened. I ran into Tim Visher. It was Tim’s first morning at work with us. We were about to start pairing on a pomodoro when he asked me if we could configure my machine to switch between Dvorak and QWERTY since he was a Dvorak typist. We did and paired all day alternating between the two layouts. That afternoon, I fired gtypist on the train home and practiced on Dvorak again.
Those were the most painful 50 minutes of my life. My brain was going to explode! My fingers did not respond to my commands! I arrived home with a big headache and a big question..
I have a week off. Do I want to improve my QWERTY or give Dvorak another try? Should I spare a couple of days on Dvorak? Is it worth it? Was I really getting better at QWERTY?
So I took the Dvorak road. It was a total disaster. I wanted to kill myself. But I didn’t, so I kept on going.
During that week off, I was practicing at least two hours everyday. I felt like my brain was getting rewired inside. It was painful but somehow it felt rewarding. Not letting my head bob around from the monitor to the keyboard and letting each finger take care of his corresponding part of the keyboard. This is something I wanted to do for a while.
I was slowly completing more lessons in gtypist and gaining confidence that I could adopt Dvorak this time. Also working with someone that had done the switch helps since they can advice you. So thanks Tim!
I am into my 4th week since I made the adoption. It’s getting smoother, I have the same speed that I use to have on QWERTY last summer. Typing in Dvorak is very comfortable. The alternation between each hand is really noticeable. Try typing “stewardess” on QWERTY and watch your left hand cry in pain.
However, sometimes, my finger still reaches for the QWERTY key if I am not paying attention. I still freakout when I have to pair. Some shortcuts still feel weird: copy/paste; opening files in emacs; browser shortcuts; illustrator. Others feel really awesome: quitting applications in OSX, some emacs navigation like “go to line” or to the top of the document.
At this point, I think the hardest part is done. I am not a stellar typist yet. It still not pretty to watch me type. I don’t have unicorns flying from my keyboard with each keystroke. But give me more time. I’ll get to it.
So this is all good…But typing is not the bottleneck, right?
Yes, for me the message still holds true. I prefer to pair. I prefer to write tests. I would love to see the word “resources” only apply to printers, faxes and phones.
I think I am going to be programming for a long time. So why not make it easy on me and learn the most effective way to do my job?
Typing effectively is just another tool in my toolbox.
Checking and correcting spelling in Emacs

As I am starting to use Emacs for things beyond coding, I found myself missing a way to check and correct my spellings.
Technomancy’s Emacs Starter kit already ships with Flyspell enabled. But what is Flyspell? From the documentation:
“Flyspell enables on-the-fly spell checking in Emacs by the means of a minor mode. […] Flyspell highlights incorrect words as soon as they are completed or as soon as the cursor hits a new word.”
Great! Exactly what I need!
However, Flyspell needs some kind dictionary to know how to spell check. Let’s install aspell, an open source spell checker and configure it in Emacs.
- On OSX, the easiest way to get aspell is via homebrew.
$ brew install aspell --lang=enIf you want to grab more dictionaries, just add them to thelangoption$ brew install aspell --lang=en,es,fr - Update your Emacs configuration with
;; flyspell (setq-default ispell-program-name "/usr/local/bin/aspell")
That’s it! Without extra configuration, we are be able to see Flyspell in action in plain text files or HTML documents. To correct a word, just press M-$ when the cursor is on the misspelling and pick your fix. For more commands, here is the documentation page.
We can also configure Flyspell to spell check comments in our code. Here is an example on how to enable it for Clojure.
;; flyspell in clojure mode. Only in comments
(add-hook 'clojure-mode-hook
(lambda ()
(flyspell-prog-mode)))
Ah! No more mistakes :)
Autocomplete in Clojure

Maybe this is one of the top five remarks when we move from static typed languages to dynamic ones: “Will I get autocompletion?”
In Clojure, we can get great autocompletion for emacs with 2 packages: auto-completion and ac-slime. Let’s install them in a few steps.
Before we start, I am using the Technomancy starter kit. If you are not, your milleage may vary.
auto-complete
- Clone the git repository to your favorite location.
$ git clone http://cx4a.org/repo/auto-complete.git
- From emacs,
M-x load-fileand locate theetc/install.elfile under the auto-complete repository. The installer will prompt for a input location, by default,~/.emacs.d. It will also let you know when the install is done. - To load auto-complete, add the following code to your emacs config
;; auto-complete (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict") (ac-config-default)
That’s it for auto-complete. It works with other languages too. If you open a python script and type a few characters, it will try to complete the word. Great!
The screenshot above is showing auto-complete and ac-slime in action. Not only we get autocompletion, we also get inline documentation!
ac-slime
- Clone the repository from github
$ git clone https://github.com/purcell/ac-slime.git
- In my case, I keep all my git clones under a
~/repofolder and use symbolic links to make them appear where they need to be. In this case, under~/emacs.d.ln -s ~/repo/ac-slime ~/.emacs.d/ac-slime - Last step, add this code to your emacs config. Restart slime and you are ready to go!
;; ac-slime (setq load-path (cons "~/.emacs.d/ac-slime" load-path)) (require 'ac-slime) (add-hook 'slime-mode-hook 'set-up-slime-ac)
Quickly get Leiningen working under Windows
Leiningen is a build tool for Clojure designed to not set your hair on fire.
So let’s get it working under windows.
-
Download the latest win32 zip and standalone jar from https://github.com/technomancy/leiningen/downloads
-
Unzip the win32.zip to to a folder of your choice (ex: d:\lein) and move the standalone jar to that folder as well.
It should looks like like this:
Directory of D:\lein lein.bat leiningen-1.4.1-standalone.jar wget.exe
-
Add new environment variables to your PATH
LEIN = d:/lein LEIN_JAR = d:/lein/leiningen-1.4.1-standalone.jar PATH = %PATH%;%LEIN%;
-
If you are behind a proxy, maven needs a settings.xml to download dependencies.
Under your user home folder (most of the time C:\Documents and Settings\UserName), create a new folder called
.m2and a new filesettings.xmlwith the following content:<settings> <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>your ip proxy address</host> <port>8080</port> <username>your user</username> <password>your password</password> </proxy> </proxies> </settings>
That’s it! Leiningen working on windows in a few steps :)
Zombies in my workplace! A recording of my talk at Philly Barcamp 2010
Log4j in Grails
By Default
Since Grails 1.1, the log4j configuration resides in grails-app/conf/config.groovy. Specified inside a log4j closure, we can add new categories and tweak the log levels.
This works great in development mode, since any change to the config.groovy file gets picked up and applied without bouncing the application.
However, when the application is running from a war, we cannot change the log4j configuration.
Plugins
Grails has enthusiastic plugin community, so it’s easy to find at least a couple of plugins to deal with this problem.
The Runtime Logging Plugin,works out of the box. You access your log4j configuration from a specific URL and change the log levels at runtime. The drawback is that you cannot add new categories and you have to secure access to that page.
The Log4j XML Plugin lets you extract the configuration out of config.groovy into a log4j.groovy or log4j.xml. But does not support runtime reloading.
Our requirements
For the application that we are building, our logging requirements are:
- Ability to change log levels at runtime.
- Ability to add new categories at runtime
Since our war is exploded, it’s ok for the log4 configuration to be inside the war, but this technique could work for a log4j.properties or xml on a share drive.
How we did it
web.xml
Grails generates the web.xml for your application from a template. In order to override it, run grails install-templates.
In src/termplates/war/web.xml, add 2 new context-param to indicate the location of the log4 file and the refresh interval. We are also changing the listener-class to use Spring’s Log4jConfigListener instead of Grails log4jConfigListener.
Grails’ Log4jConfigListener expects the configuration inside the config.groovy file. Since we are extracting the configuration out of config.groovy, we can switch to the Spring Log4jConfigListener that supports location and interval.
<!-- log4j parameters -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>2000</param-value>
</context-param>
<!-- Use Spring Log4jConfigListener instead of Grails-->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
_Events.groovy
Since we indicated that the log4j.xml will be loaded from the classpath, we will be hooking into the Grails events to make sure that the file is in the classpath. To do that, create a scripts/_Events.groovy. In this case, we care about 2 events, when creating a war or running the application.
eventCreateWarStart = { warName, stagingDir ->
ant.copy(todir: "${stagingDir}/WEB-INF/classes") {
fileset(file: "${basedir}/grails-app/conf/log4j.xml")
}
}
eventRunAppStart = {
ant.copy(todir:"./target/classes") {
fileset(file: "./grails-app/conf/log4j.xml")
}
}
Grails events are explained here.
config.groovy
In grails-app/conf/config.groovy, remove the log4j closure at the end of the file. We will use an external configuration file instead.
A log4j.xml file
We dropped our configuration into grails-app/conf/log4j.xml. Here is a minimal version of ours category/loggers:
<logger name="grails.app">
<level value="INFO"/>
</logger>
<logger name="org.hibernate">
<level value="INFO"/>
</logger>
<logger name="org.springframework">
<level value="WARN"/>
</logger>
Domains, controllers and services get logged as INFO since the parent category is grails.app
If we wanted to log only domain classes, we would use grails.app.domains.
That’s it! Changes in web.xml, config.groovy and _Events.groovy will do the trick!
My clojure setup
I learned a lot of useful tricks last week during the first hack night of the phl-clojure-language-club. With the help of the group I finally completed what I think is a good environment for a newbie like me.
Emacs
This is my emacs. There are many others like it, but this one is mine: http://emacsformacosx.com/
I tried a few others but sometimes I switch platforms and GNU seems the be one that works everywhere for me.
I used to maintain my own emacs configuration but I found out quickly that I suck at it. Technomancy’s emacs-starter-kit does a better job at it. And don’t let the name fool you, it’s a nice prepackage configuration for dynamic languages that you can extend at will.
Clojure and libraries
Homebrew is a great tool for installing and updating existing libraries on Mac OS X. I used it to download all my clojure related libraries. From your terminal, it’s easy as:
$ brew install clojure $ brew install clojure-contrib $ brew install leiningen
Emacs Configuration
The emacs-starter-kit contains an emacs package archive called ELPA. We are going to use it to install all our clojure modes and hooks.
From Emacs
M-x package-list-packages
Mark with “i” the following packages in elpa:
- clojure-mode (syntax highlight, identation) - clojure-test-mode (running clojure tests within emacs) - slime (mode for developing common lisp apps but support other lisps like clojure) - slime-repl (repl for slime) - swank-clojure (slime adapter for clojure) - paredit (parenthesis editing mode for clojure and other lisps)
Press x to install all of them
Testing the install
Let’s create a simple application to make sure everything is wired together.
From your terminal
$ lein new hello $ cd hello $ lein deps
From Emacs
C-x C-f hello/core.clj
;; add this function
(ns hello.core)
(defn hello [name]
(str "Hello " name "!"))
Back to the terminal, we are going to launch in repl mode to be able to execute the code that we just wrote.
$ lein repl
Think of this as a console mode. At this point, clojure has compiled your code and you can interact with this console to call your functions.
user=>
We can now load the hello namespace and execute our function
user=> (use 'hello.core) user=> (hello "Sebastian")
If everything goes well, you should see: “Hello Sebastian!”
Running repl is a great way to play with your code and learn some clojure syntax. But sometimes, this console feels too far away from the real code, and there is no way to “see” what the function is doing inside. Enter: slime and swank.
Running code from within emacs
Using swank and slime, you can inspect and run any expression within emacs
Add the following line to hello-world/project.clj
:dev-dependencies [[swank-clojure "1.2.1"]]
Your project.clj should look something like:
(defproject hello "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dev-dependencies [[swank-clojure "1.2.1"]]
:dependencies [[org.clojure/clojure "1.2.0-beta1"]
[org.clojure/clojure-contrib "1.2.0-beta1"]])
Now back in the terminal, let’s start a swank session
$ lein swank
If everything went okay, you should see this output
user=> Connection opened on local port 4005 #<ServerSocket ServerSocket[addr=localhost/127.0.0.1,port=0,localport=4005]>
Note the host and the port. This is something that we will need to validate once we connect to the swank session
From Emacs
M-x slime-connect
Slime normally connects to localhost with port 4005. Adjust these settings based on the output of “lein swank” above. The cool part about this is that I imagine that you could be able to remote into a production server and use this technique to troubleshoot/debug any production issue (I haven’t tested this yet…)
Let open our file if it’s not open already
C-x C-f hello/core.clj
Type the following code at the end of core.clj. This is the expressions that we will try to evaluate.
;; (hello "Sebastian")
Note that this is a comment. Keep it like that, it will make sense in 5 seconds…
Load the file in slime
C-c C-l
Move your cursor to the end of the expression that your want to evaluate. Note that this expression is in a comment, but we will evaluate to the previous parenthesis.
To evaluate the expression
C-x C-e
Your emacs buffer should display “Hello Sebastian!”
Inspecting values
Slime and swank let you inspect your functions and collections.
Let’s create a map of people
(def people {1 "John" 2 "Bob"})
Let’s evaluate the map. I.e., load the map in slime.
C-x C-e
And now inspect what is inside that map
C-c I
You should see something like
{1 "John", 2 "Bob"}
--------------------
Class: class clojure.lang.PersistentArrayMap
Count: 2
Contents:
1 = John
2 = Bob
The same can be done with functions. Let’s inspect the function “hello”. Move your cursor to the definition of the hello method or any of times we call it
C-c I
You should see something like
hello.core$hello@6774a144
--------------------
Type: class hello.core$hello
Value: hello.core$hello@6774a144
---
Fields:
const__0: #'clojure.core/str
__meta: {:ns #<Namespace hello.core>, :name hello}
So that’s it. So far, this is my environment for clojure hacking. I am fairly new at it, so it might not be the best one for more advanced programmers. Thanks to the people at phl-clojure-language-club for the tips and for a great time! I can’t wait for the next one.

