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
;; Sorry about the horrible code. This is my first shot at a core.logic program. | |
;; | |
;; Basically this is a change calculator that returns all possible combinations of change for a given | |
;; total. Instead of being about money its about monsters for tabletop RPGs. | |
(require '[clojure.core.logic :as l] | |
'[clojure.core.logic.fd :as fd]) | |
(defn allocate-monsterso [points monsters out] | |
"This relation finds all the allocations of monsters for the given points. |
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
This code is influenced by https://github.com/hiredman/clojurebot/blob/master/src/hiredman/clojurebot/core.clj |
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 pivot-on | |
"This is about the worst way you could ever write this" | |
[p coll] | |
(first (reduce (fn [[[l r] pivoted] v] | |
(if pivoted | |
[[l (conj r v)] true] | |
(if (p v) | |
[[l r] true] | |
[[(conj l v) r] false]))) | |
[[[] []] 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
(use 'name.choi.joshua.fnparse) | |
(def tokenize (partial re-seq #"\\[\[\](){}]|\"(?:\\.|[^\"])*\"|[\[\](){}]|[^\[\](){}]+")) | |
(def initial-state (comp (partial array-map :remainder) tokenize)) | |
(def brackets {"[" "]" "(" ")" "{" "}"}) | |
(def opening (term (set (keys brackets)))) |
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 {})) |
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
"""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
; 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
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
;; 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)))] |
OlderNewer