This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# module is awesome! | |
module Enumerable; | |
def histogram; | |
groups = group_by {|i| i}; | |
(0..max).map {|bin| (groups[bin] || []).count} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(dolist (i (number-sequence 1 9)) | |
(dolist (j (number-sequence 1 9)) | |
(insert (format "%2d " (* i j)))) | |
(insert "\n")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
OlderNewer