Skip to content

Instantly share code, notes, and snippets.

View timmc's full-sized avatar

Tim McCormack timmc

View GitHub Profile
@timmc
timmc / gist:899696
Created April 2, 2011 17:44
When compiled: "java.lang.ClassCastException: test.core.Person cannot be cast to test.core.Person"
(ns test.core)
(defrecord Person [name])
(def fred (Person. :fred))
(def test-direct ; fine
(.name ^Person fred))
(def test-no-hint ; fine
@timmc
timmc / gist:928528
Created April 19, 2011 15:44
Alternative to clojure.test/are
(defmacro are
"Same as clojure.test/are, except returns true if all tests pass."
[syms test & vals]
(let [c (count syms)
points (partition-all c vals)]
(list `every?
`identity
(into []
(for [pt points]
`(let [~@(interleave syms pt)]
#!/bin/bash
set -o errexit
set -o nounset
i=0
echo "i is $i"
let "n = i * 2"
echo "n is $n"
@timmc
timmc / gist:980934
Created May 19, 2011 14:56
.emacs for Clojure
;;;; Provided by Alec
;; add el-get to the load-path
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
;; install it if we don't already have it
(require 'el-get)
;;(unless (require 'el-get "" t)
;; (message "Couldn't require el-get, installing it now...")
;; (let* ((installer-buffer (url-retrieve-synchronously
;; (concat "https://github.com/dimitri/"
expected = {
0:{
0:set([]),
1:set([0,5]),
2:set([0,1,5]),
3:set([0,1,2,5]),
4:set([0,1,2,3,5]),
5:set([])
},
1:{
@timmc
timmc / gist:1138805
Created August 11, 2011 02:43
Playing around with name composition
(defmacro kf [& args]
(let [is-key #(= \_ (last (str %)))
ks (filter is-key args)
as (filter (complement is-key) args)]
(let [n (symbol (apply str (map name ks)))]
`(~n ~@as))))
(defn do_not_ [a b] a)
(kf do_ 2 not_ (+ 3 4)) ;; (do_not_ 2 (+ 3 4))
529 gkatsev
198 mheld
195 lauren
190 TimMc
71 cmccoy
35 kerrg
23 bahsiek
17 asm
15 thang
@timmc
timmc / gist:1503998
Created December 21, 2011 00:47
Multimethod example
(ns clj.core)
(defmulti foo type)
(defmethod foo ::common [_] "common")
(defmethod foo :default [_] "default")
(derive String ::common)
(derive Math ::common)
(defn -main [& args]
#!/usr/bin/env python
"""Read from stdin and print chunks with checksums."""
from __future__ import print_function
import sys
import md5
chunk_size = 40
def part_str(s, l):
@timmc
timmc / inline.clj
Created January 2, 2012 18:41 — forked from sritchie/inline.clj
;; This evaluates properly...
(defn barr=
([x] true)
([^bytes x ^bytes y]
(java.util.Arrays/equals x y))
([x y & more]
(if (barr= x y)
(if (next more)
(recur y (first more) (next more))
(barr= y (first more)))