Skip to content

Instantly share code, notes, and snippets.

% Run a Monty Hall problem simulation with the following parameters:
%
% changeDoors: boolean determining whether the contestant should change
% doors
%
% doors: the number of doors in the problem, with a minimum of 2
%
% N: the number of problem simulations to perform, with a minimum
% of 1
%
@hadronzoo
hadronzoo / test.rb
Created November 13, 2011 06:29
Simplified test case with associations fixed
require 'dm-core'
DataMapper.setup(:default, 'sqlite::memory:')
class Project
include DataMapper::Resource
property :id, Serial
has n, :members
has n, :users, :through => :members
@hadronzoo
hadronzoo / imaxima.diff
Created December 18, 2011 19:38
imaxima.el patch for OS X
diff --git a/interfaces/emacs/imaxima/imaxima.el b/interfaces/emacs/imaxima/imaxima.el
index e3feaa6..3a52a0b 100644
--- a/interfaces/emacs/imaxima/imaxima.el
+++ b/interfaces/emacs/imaxima/imaxima.el
@@ -296,6 +296,8 @@ nil means no scaling at all, t allows any scaling."
(temp-directory))
((eql system-type 'cygwin)
"/tmp/")
+ ((eql system-type 'darwin)
+ "/tmp/")
@hadronzoo
hadronzoo / load_hook.rb
Created July 6, 2012 04:05
Hook DataMapper::Model#load
module DataMapper
module Model
alias _load load
def load(records, query)
p "here"
r = _load(records, query)
end
end
@hadronzoo
hadronzoo / ihash.cljs
Created July 13, 2013 04:06
Hashing for custom types such that they are properly detected as duplicates within ClojureScript's PersistentHashSets.
(deftype TestType [key]
IHash
(-hash [this]
(hash key)))
(def a (TestType. [1 2 3]))
(def b (TestType. [1 2 3]))
;; the resulting PersistentHashSet should have one item, but has two:
(.log js/console (pr-str (conj #{} a b)))
@hadronzoo
hadronzoo / gaps.clj
Last active December 28, 2015 15:39
Find gaps in a collection containing a sequence of monotonic integers
(defn gaps [coll]
"Find gaps in collection coll, containing a sequence of monotonic integers"
(letfn [(intervals [[cur & rst] prev]
(when cur
(cons [(inc prev) (dec cur)]
(lazy-seq (intervals rst cur)))))]
(lazy-seq
(when-let [[cur & rst] (seq coll)]
(remove (fn [[x y]] (> x y))
(intervals rst cur))))))
#include<stdio.h>
#include<stdlib.h>
struct list_node {
int val;
struct list_node *next;
};
int node_size = sizeof(struct list_node);
#include<stdio.h>
#include<stdlib.h>
int *add_counts(char *corpus, int *counts) {
int i = 0;
while (corpus[i]) {
counts[corpus[i]]++;
i++;
}
return counts;
(def data
[["Community" "community.png" "Community"]
["News" "news.png" "Community"]
["Messages" "messages.png" "Community"]
["Inbox" "inbox.png" "Messages"]
["Sent" "sent.png" "Messages"]])
(defn map-menu [menu]
(reduce (fn [m [child image parent]]
(let [children (-> (:children (get m parent) #{})
@hadronzoo
hadronzoo / keybase.md
Created February 28, 2014 02:58
keybase

Keybase proof

I hereby claim:

  • I am hadronzoo on github.
  • I am joshua (https://keybase.io/joshua) on keybase.
  • I have a public key whose fingerprint is 23CE 2108 CFCE 83A5 B09C B4CE ADF9 100C 2284 C5DB

To claim this, I am signing this object: