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
| """A very simple, and minimal, multimethod implement in python inspired by clojure's multimethods | |
| No support for default arguments, or hierarchies, and it relies on pythons default equality tests. | |
| """ | |
| class Multimethod(object): | |
| def __init__(self, dispatch_fn): | |
| self.dispatch_fn = dispatch_fn | |
| self.handlers = {} | |
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
| ;; original function | |
| (defn assoc-meta [metable & kvs] | |
| (with-meta metable (apply assoc (meta metable) kvs))) | |
| ;; rewritten with an explicit conjugation | |
| (defn conjugate [translate untranslate f] | |
| (comp untranslate f translate)) |
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
| (require '[clojure.string :as str]) | |
| (use '[ring.util.response :only [redirect]]) | |
| (defn remove-utm-params) | |
| [query-string] | |
| (->> (.split query-string "&") | |
| (filter (fn [^String p] (.startsWith p "utm_"))) | |
| (str/join "&"))) | |
| (defn utm-redirect |
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
| ifr = document.createElement("iframe"); | |
| document.body.appendChild(ifr); | |
| ifr.contentDocument.write("<script language='javascript'>window.Object2 = Object;</script>"); | |
| o = new ifr.contentWindow.Object2(); | |
| o instanceof Object; // => false |
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
| ;; hacked out of clojure.repl/apropos and prepending namespaces | |
| (defn apropos-ns | |
| "Given a regular expression or stringable thing, return a seq of | |
| all definitions in all currently-loaded namespaces that match the | |
| str-or-pattern." | |
| [str-or-pattern] | |
| (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern) | |
| #(re-find str-or-pattern (str %)) | |
| #(.contains (str %) (str str-or-pattern)))] |
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
| function l_system (productions, depth, s) { | |
| if (depth === 0) return s; | |
| return $.map(s, function (v) { | |
| return l_system(productions, depth - 1, productions(v) || [v]); | |
| }); | |
| } | |
| function run_turtle (turtle, operations, commands) { | |
| $.each(commands, function (_, c) { | |
| (operations[c] || $.noop)(turtle); |
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
| ; archaic, an alternative to https://gist.github.com/1343842 | |
| (defn temp-gr | |
| [start by end] | |
| (fn [x] | |
| (when (<= start x end) | |
| (let [lower (* (quot x by) by) | |
| upper (+ lower by)] | |
| (keyword (str lower "-" upper)))))) |
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
| """populate.py | |
| This script takes a listing of folders and filenames (as generated by `ls -R > listing`) on standard input | |
| and the pathname for a set of media as the argument to argv. | |
| e.g: | |
| python populate.py _source < test/listing.txt | |
| The files listed in listing are then mocked from the media files using the filenames in the input, and |
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
| /* | |
| javascript:%28function%20%28%29%20%7B%0A%20%20var%20w%20%3D%20window.open%28window.location%2C%20window.title%2C%20false%29%3B%0A%20%20w.resizeTo%28320%2C480%29%3B%0A%20%20w.onload%20%3D%20function%20%28%29%20%7B%0A%20%20%20%20var%20b%20%3D%20w.document.body%3B%0A%20%20%20%20b.style.overflow%20%3D%20%22scroll%22%3B%0A%20%20%20%20w.resizeBy%28320%20-%20b.offsetWidth%2C%200%29%3B%0A%20%20%7D%3B%0A%7D%29%28%29%3B | |
| */ | |
| (function () { | |
| var w = window.open(window.location, window.title, false); | |
| w.resizeTo(320,480); | |
| w.onload = function () { | |
| var b = w.document.body; | |
| b.style.overflow = "scroll"; |
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
| (->> (re-seq #"(?i)(\d+)\.|(yes|no)" "no1. asdf\n\nasdf foo yes2.\n\nfsdf\nno yes no") | |
| (map rest) | |
| (partition-by first) | |
| (drop-while (comp nil? ffirst)) | |
| (partition 2) | |
| (map (fn [s] (let [[i & r] (keep identity (flatten s))] | |
| [(Integer/parseInt i) | |
| (-> (last r) .toLowerCase first (= \y))]))) | |
| (into {})) |