Skip to content

Instantly share code, notes, and snippets.

View mrc's full-sized avatar

Matt Curtis mrc

  • Melbourne
View GitHub Profile
(defmacro are (test &rest tests)
"Evaluate a list of tests with (is)"
`(progn
(is ,test)
(unless (null ',tests)
(are ,@tests))))
(deftest test-mult ()
(is (= 1 (multiply 1 1)))
(is (= 6 (multiply:multiply 2 3)))
@mrc
mrc / xxx
Created November 13, 2010 01:48
(defproject com.wombat.web/gaeproject "1.0.0-SNAPSHOT"
:description "gaeproject information retrieval"
:gae-app com.wombat.web.gaeproject.core/app
:dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]
[uk.org.alienscience/leiningen-war "0.0.2"]]
:dependencies [[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.1.0"]
[ring/ring "0.2.0"]
[com.google/appengine-api-1.0-sdk "1.3.3.1"]
[com.google/appengine-api-labs "1.3.3.1"]
@mrc
mrc / histogram.rb
Created May 7, 2011 22:39
Histogram (tweeted by mfeathers)
# module is awesome!
module Enumerable;
def histogram;
groups = group_by {|i| i};
(0..max).map {|bin| (groups[bin] || []).count}
end
end
@mrc
mrc / tree1.rb
Created May 9, 2011 12:55
ruby tree ("seven languages")
class Tree
attr_accessor :children, :name
def initialize(tree, name='root')
@name = name
@children = tree.map do |k,v|
Tree.new(v, k)
end
end
@mrc
mrc / git-histogram.rb
Created May 13, 2011 02:51
git histogram of commits over hours
# http://twitter.com/#!/mfeathers/status/61229026034978817
`git log | grep "^Date"`.split($/).map { |line| line.split(' ')[4].split(':')[0] }.group_by { |x| x }.map {|k,v| [k,v.length] }
@mrc
mrc / ert-are.el
Created September 17, 2011 01:45
ert "are" macro
(defmacro are (form &rest forms)
"Evaluate FORM, then a list of FORMS with should. If any return
nil, abort the current test as failed.
Returns the value of the last form evaluated."
(let ((result (make-symbol "result")))
`(progn
(setq ,result (should ,form))
(unless (null ',forms)
(setq ,result (are ,@forms)))
@mrc
mrc / git_grep.vim
Created November 9, 2011 00:46
git-grep from vim
" Vim global plug-in for running git grep.
" Last Change: Wed 2 Dec 2009 16:46:13 AEST
" Maintainer: Matt Curtis <matt.r.curtis@gmail.com>
" License: This file is placed in the public domain.
" Notes: stolen from http://vim.wikia.com/wiki/Git_grep
if exists('g:git_grep')
finish
endif
(dolist (i (number-sequence 1 9))
(dolist (j (number-sequence 1 9))
(insert (format "%2d " (* i j))))
(insert "\n"))
@mrc
mrc / code_5_6.lisp
Created November 16, 2011 10:05
Dinky probability helpers for ai-class
(defun bayes-transform-form (PB!A PA PB)
"Return a form to compute P(A|B)
given P(B|A), P(A) and P(B)."
`(/ (* ,(or PB!A 'PB!A) ,(or PA 'PA))
,(or PB 'PB)))
(defun total-probability-complementary (PA!B PA!notB PB)
"Return a form to compute the total probability of
complementary events P(B) = P(A|B)P(B) + P(A|!B)P(!B)."
`(+ (* ,(or PA!B 'PA!B)
@mrc
mrc / uptime.zsh
Created April 30, 2013 07:34
Poor uptime for zsh and Windows
zmodload zsh/datetime
function uptime() {
reboot_time=$(net statistics server | awk '/Statistics since/{print $3, $4, $5}')
strftime -r -s reboot_secs '%d/%m/%Y %H:%M:%S %p' "$reboot_time"
(( uptime = $EPOCHSECONDS - $reboot_secs ))
(( up_days = uptime / 86400 ))
(( up_hours = (uptime % 86400) / 3600 ))
(( up_minutes = ((uptime % 86400) % 3600 ) / 60))
(( up_seconds = ((uptime % 86400) % 3600 ) % 60))