Skip to content

Instantly share code, notes, and snippets.

@bodil
bodil / extremestartup.coffee
Created August 19, 2011 08:05
A CoffeeScript solution for @jhannes's evil Extreme Startup question set
# To install dependencies:
# $ npm install express mongoose connect-mongoose
fs = require "fs"
express = require 'express'
mongoose = require 'mongoose'
sessionStore = require("connect-mongoose")(express)
Schema = mongoose.Schema
mongo_uri = "mongodb://localhost/bodilpwnz"
(ns lol
(:use clojure.test))
(def board [nil :bomb nil nil
:bomb nil nil nil
nil nil :bomb nil
:bomb nil nil :bomb])
(with-test
(defn bomb?
(ns lol
(:use clojure.test))
(def board [[nil :mine nil nil ]
[:mine nil nil nil ]
[nil nil :mine nil ]
[:mine nil nil :mine]])
(defn y [c] (c 0))
(defn x [c] (c 1))
@bodil
bodil / anagram.clj
Created March 5, 2012 16:03
Anagram-kata
(ns ohai
(:use clojure.test))
(def words
'("foo"
"rab"
"rba"))
(with-test
(defn anagram? [a b]
@bodil
bodil / addagram.clj
Created April 1, 2012 00:19
Clojure solution for http://addagram.mytestbench.com/ with ~1s execution time.
(ns addagram.core
(:use [clojure.test]
[clojure.java.io :only [reader]]))
(with-test
(defn sort-largest [l]
(sort-by #(- (count %)) l))
(is (= ["blerk" "quux" "foo" "bar"]
(sort-largest ["foo" "quux" "bar" "blerk"]))))
@bodil
bodil / hindley-milner.clj
Last active August 12, 2019 18:08
Port of http://dysphoria.net/code/hindley-milner/HindleyMilner.scala to 100% pure Clojure code, complete with state monad hell. Originally based on Luca Cardelli's paper "Basic Polymorphic Typechecking" http://lucacardelli.name/Papers/BasicTypechecking.A4.pdf
;;; Clojure port of http://dysphoria.net/code/hindley-milner/HindleyMilner.scala
(ns hindley-milner
(:require [clojure.string :as str]))
(declare occurs-in? occurs-in-type?)
(defn map-state
"Evaluate a list of state monad values in sequence, producing
a list of the results of each evaluation."
@bodil
bodil / README.md
Last active December 20, 2015 11:08
The core.async exercise from the July 30th London Clojure Dojo

core.async example thing

To run:

  • checkout https://github.com/clojure/core.async and install it using lein install
  • make a project directory for this code
  • put omgcoreasync.cljs in a src subdirectory, project.clj and index.html in the root
  • go lein cljsbuild once to build
  • load index.html in a browser and watch it go
@bodil
bodil / webbit.clj
Created September 26, 2013 17:21
Basic Webbit adapter for Ring.
(ns ring.adapter.webbit
(:require [clojure.string :as s]
[clojure.java.io :as io])
(:import [org.webbitserver WebServer WebServers HttpHandler]
[java.io File InputStream]))
(defn- transform-headers [headers]
(apply hash-map (mapcat (fn [e] [(s/lower-case (.getKey e))
(.getValue e)]) headers)))
@bodil
bodil / wat.ts
Created January 16, 2014 22:36
Don't.
/**
* Magic version of Rx.Observable.sync() that allows for adding more
* Observables to the input feed while processing.
*
* Needs a more descriptive name maybe.
*/
function wat<T,U>(initialState: T, initialFeeds: Rx.IObservable<U>[], iterator: (state: T, e: U) => StateChange<T,U>): any {
var sub = new Rx.BehaviorSubject(initialState);
var state = initialState;
@bodil
bodil / tween.ts
Created May 27, 2014 16:29
Tween.js + Bacon.js === <3
///<reference path="dts/tween.js.d.ts" />
///<amd-dependency path="tween" />
import b = require("./bacon");
import graph = require("./graph");
import ev = require("./events");
module TweenEffects {
var Tween = require("tween.js").Tween;