This file contains hidden or 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
// Shameless yak-shaving. I don't even remotely need this for | |
// anything right now, but wrote it due to a lament that keys | |
// in JavaScript {options: 'objects'} aren't checked for | |
// correctness and typos/misspelling can easily go unnoticed. | |
var _ = require('underscore'); | |
// Expect all keys in the object to be from the list in "allowed". | |
// Emit a warning if they don't. | |
// TODO: Should compile down to nothing in production as this is |
This file contains hidden or 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
var _ = require('underscore'); | |
function foo() { | |
_(['foo','bar','baz']).each(function(s) { | |
console.log(s); | |
}); | |
} | |
module.exports = foo; |
This file contains hidden or 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
(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)]))) |
This file contains hidden or 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
(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) |
This file contains hidden or 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
(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))) |
This file contains hidden or 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
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) |
This file contains hidden or 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
@-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; | |
} |
This file contains hidden or 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
fn main() { | |
let s = [1, 2, 3, 4].map(|&x| (x * x).to_str()); | |
for s.each |&item| { | |
io::println(item); | |
} | |
} |
This file contains hidden or 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
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 |
This file contains hidden or 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
@-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; | |
} |