Skip to content

Instantly share code, notes, and snippets.

@hadronzoo
hadronzoo / char_counts.clj
Last active August 29, 2015 14:00
Select low and high character frequencies, choosing the lowest code point in case of a tie
(def input "bbbddddaaacccc")
(defn- lowest-code-point [coll]
(first (into (sorted-map-by #(< (int %1) (int %2))) coll)))
(defn- take-while= [value coll]
(take-while (fn [[_ v]] (== value v)) coll))
(let [counts (frequencies input)
sorted (sorted-map-by
@hadronzoo
hadronzoo / replace-hash-rockets.el
Last active August 29, 2015 13:56
Replace hash rockets with Ruby 1.9 symbol keys
;; Replace hash rockets with Ruby 1.9 symbol keys
(defun replace-hash-rockets ()
(interactive)
(goto-char 1)
(while (search-forward-regexp ":\\(\\(\\w\\|_\\)+\\) =>" nil t)
(replace-match (concat (match-string 1) ":") t nil)))
@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:

(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) #{})
#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;
#include<stdio.h>
#include<stdlib.h>
struct list_node {
int val;
struct list_node *next;
};
int node_size = sizeof(struct list_node);
@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))))))
@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 / 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 / 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/")