Skip to content

Instantly share code, notes, and snippets.

@graue
graue / foo.js
Created March 4, 2014 19:18
Browserify source map test case
var _ = require('underscore');
function foo() {
_(['foo','bar','baz']).each(function(s) {
console.log(s);
});
}
module.exports = foo;
(defn val-map
"Map f over hashmap m's values. Should be in the dang core."
[f m]
(into {} (for [[k v] m] [k (f v)])))
@graue
graue / vectors.clj
Last active December 29, 2015 16:49
(ns vectors
(:require [clojure.test :refer [deftest is run-tests]]))
(defprotocol VectorMath2D
(-vplus [v1 v2] "Adds two vectors"))
(defrecord Vec2D [x y]
VectorMath2D
(-vplus [v1 v2]
(Vec2D. (+ (:x v1)
@graue
graue / primes.clj
Created July 20, 2013 03:54
Lazy list of primes, as implemented in 15 minutes on the subway on my phone
(defn divides [m n]
(= 0
(mod n m)))
(defn my-and [x y]
(and x y))
(defn all? [pred xs]
(reduce my-and true
(map pred xs)))
@graue
graue / gist:5945184
Created July 7, 2013 22:18
Clojure error message
Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: ring_intro.core$wrap_uri_check$fn__205, compiling:(core.clj:27:3)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3463)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:408)
at clojure.lang.Compiler.eval(Compiler.java:6624)
at clojure.lang.Compiler.load(Compiler.java:7064)
at clojure.lang.RT.loadResourceScript(RT.java:370)
at clojure.lang.RT.loadResourceScript(RT.java:361)
at clojure.lang.RT.load(RT.java:440)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5028.invoke(core.clj:5530)
@graue
graue / userContent.css
Created May 27, 2013 00:52
My userContent.css for Firefox (makes Hacker News comments and Humbug messages more readable)
@-moz-document url-prefix(https://news.ycombinator.com) {
.comment {
font-family: Alegreya, serif !important;
font-size: 15pt !important;
}
.comment code {
font-family: Inconsolata-g, fixed !important;
font-size: 10pt !important;
}
@graue
graue / soon.rs
Created May 26, 2013 17:22
Code using `map` that worked in Rust 0.5, but broke in 0.6
fn main() {
let s = [1, 2, 3, 4].map(|&x| (x * x).to_str());
for s.each |&item| {
io::println(item);
}
}
@graue
graue / MergeSort.hs
Created May 10, 2013 23:10
Merge sort in Haskell
mergeSort :: Ord a => [a] -> [a]
mergeSort [] = []
mergeSort [x] = [x]
mergeSort xs = combineSortedLists
(mergeSort firstHalf)
(mergeSort secondHalf)
where (firstHalf, secondHalf) = splitInHalf xs
splitInHalf :: [a] -> ([a], [a])
splitInHalf xs = splitAt halfLength xs
@graue
graue / userContent.css
Created May 1, 2013 20:23
Firefox userContent.css to make Hacker News comments prettier
@-moz-document url-prefix(https://news.ycombinator.com) {
.comment {
font-family: Alegreya, serif !important;
font-size: 15pt !important;
}
.comment code {
font-family: Inconsolata-g, fixed !important;
font-size: 10pt !important;
}
@graue
graue / minikanren notes.txt
Created April 15, 2013 15:15
Notes from @swannodette's MiniKanren seminar (very rough / unedited)
four primitives: run*, ==, conde, fresh
(run* (q)
(== q #t))
; for what values of q is q equal to true?
answer: q must also be #t, so
'(#t) ; answer comes back in a list