Super Easy Clojure Web Apps with Heroku Cedar

Deploying Clojure apps with a single command to the cloud is now possible with Heroku Cedar and let me tell you, it is pure joy. I experimented with this the other day by creating a Compojure web application that compares the followers that two twitter users have in common. Here is the secret sauce you need to push your apps to Heroku: **Procfile: ** You need to create a file in the root of your directory that contains the way to start up your application: ...

June 11, 2011 · 2 min · Carin Meier

Mocking Ajax Calls with Jasmine

I have been happily using Jasmine and Jasmine-JQuery on a project with great success. However, I was still unsure about how to handle mocking the ajax calls back to the server. It turns out the answer is already in Jasmine. Time to call out the spies! There is a wiki page on spies https://github.com/pivotal/jasmine/wiki/Spies, but I always enjoy a nice code sample. In my source file I have an ajax call that I would like to mock that looks like this: [gist id=957387] ...

May 5, 2011 · 1 min · Carin Meier

Hacking JavaScript for the Love of Clojure

Lately, I have been working on the awesome open source project 4Clojure.com. The site helps you to learn Clojure by solving “koan” type problems in an interactive format. One of the enhancements that I was looking at putting in was a way to enter code in a text box and have it color highlight as type. I found the ACE project, which looked like exactly what I wanted. However, sad panda, they didn’t have a Clojure mode. Not deterred, I decided that I would try to take a crack at it. I ported most of the rules from the Clojure brush in Syntax Highlighter over and implemented some basic auto-indent. ...

May 1, 2011 · 1 min · Carin Meier

Yellow Belt Katas for Ruby and Clojure

I have put a couple projects out on GitHub to help people get started with Clojure and Ruby. The Katas are taken more or less from the Coding Kata site http://codingkata.org/katas/. The projects both include the basic project setup for you to get started with TDD beginner katas. The Ruby project has tests in the form of rspec-given, which is quite fun. The Clojure project has tests in the form of Midje, which has a lovely syntax. ...

April 16, 2011 · 1 min · Carin Meier

Knights Who Say Monad

(*Sketch By My Awesome Husband)

April 12, 2011 · 1 min · Carin Meier

On Thinking in Ruby and Clojure

Recently, I decided to work on a set of code Katas. I couldn’t decide whether to do them in Ruby or Clojure, so I decided to do them in both. I did the Kata in Ruby first and then immediately followed up with the same one in Clojure. It was an interesting exercise, not only for the learning of the languages, but to highlight how I thought about the problems differently depending on the language. ...

April 8, 2011 · 2 min · Carin Meier

Bowling Game Kata in Clojure with STM and defrecord

We took our kids bowling for the first time the other day. I have to admit, that I am not a great bowler. I had only been bowling two or three times in my life previous to that event and I was very thankful that those bumpers were up. The computer program malfunctioned in the final frames of our last game. I realized then, that I really had no idea how to score bowling. Later that night, in my surfing, I came across a reference to the Bowling Game Kata. ...

March 1, 2011 · 1 min · Carin Meier

Vampire Slaying in Clojure with STM - Part 2

In Part 1, we used defrecords to create a vampire slayer named “Buffy” and a few vampires for her to kick around. Today we are going to use Buffy and her vampires to explore STM (Software Transactional Memory) in Clojure for managing state. Recap (defrecord Vampire [name, health]) (def vampire1 (Vampire. "Stu" 50)) (def vampire2 (Vampire. "Vance" 100)) (def vampire3 (Vampire. "Izzy" 75)) (defrecord Slayer [name, weapon]) (def kungfu 25) (def buffy (Slayer. "Buffy" kungfu)) (defn hit [vampire, hitpoints] (- (:health vampire) hitpoints)) ;vampires don't fight back but it takes time to kill them (def combat-time 20) (defn hit-vampire [vampire, slayer] (Thread/sleep (* combat-time 10)) (assoc vampire :health (hit vampire (:weapon slayer)))) (defn kill-vampire [vampire, slayer] (if (> (:health vampire) 1) (recur (hit-vampire vampire slayer) slayer) (assoc vampire :health 0))) Let’s take our vampires and stand them up in a line for Buffy to fight. We are also going to create a function that just has Buffy killing a vampire, rather then a generic slayer. ...

January 18, 2011 · 3 min · Carin Meier

Vampire Slaying with Clojure - Part 1 defrecord

It’s time to learn more Clojure. This time, Buffy the Vampire Slayer* is going to help us. First things first, of course we need vampires! Let’s create a vampire data type with defrecord. Our vampires are going to have two attributes, their name and the number of health points that they have. This is of course, how Buffy is going to slay them. If a vampire’s health points goes to zero, then they are dead. Well, they already are undead… so let’s say they are slayed at that point and turn into dust. ...

January 12, 2011 · 4 min · Carin Meier

Mutually Recursive Zombies on a Trampoline

It’s late at night. The kids are all tucked snuggly in their beds and I am ready to explore mutual recursion on my own in Clojure after doing some reading of Programming Clojure. What better subject to explore them with then zombies? In this example we have two zombies – zombie1 and zombie2. Let’s represent each zombie as a sequence: (def zombie1 '("z1_head", "z1_r_arm" "z1_l_arm" "z1_torso" "z1_r_leg" "z1_l_leg")) (def zombie2 '("z2_head", "z2_r_arm" "z2_l_arm" "z2_torso" "z2_r_leg" "z2_l_leg")) zombie1 is ready to take a bite of zombie2’s left leg, since it is nice and tasty there at the end. Once zombie1 takes a bite, the body part will be added to its own sequence – but in the second position, so that the head is always first and ready to take another bite. So, if zombie2 just stood still and let itself be eaten, after one bite, zombie1 would look like this ...

December 8, 2010 · 3 min · Carin Meier