Skip to content

Instantly share code, notes, and snippets.

View arthuredelstein's full-sized avatar

Arthur Edelstein arthuredelstein

View GitHub Profile
(defn data-object-to-map [obj]
(into {}
(for [f (.getFields (type obj))
:when (zero? (bit-and (.getModifiers f) Modifier/STATIC))]
[(.getName f) (.get f obj)])))
@arthuredelstein
arthuredelstein / src-dir.clj
Created August 19, 2011 06:23
clojure function for getting the src directory
(defn src-dir
"Returns the absolute file path of the src directory
enclosing the current .clj file's package dirs."
[]
(let [rel *file*]
(loop [cl (.. Thread currentThread getContextClassLoader)]
(when cl
(if-let [url (.findResource cl rel)]
(.replace (.getFile url) rel "")
(recur (.getParent cl)))))))
@arthuredelstein
arthuredelstein / gist:1172646
Created August 26, 2011 03:50
user.dir/slurp weirdness
clooj.help=>
(import java.io.File)
java.io.File
clooj.help=>
(System/getProperty "user.dir")
"/projects/clooj"
clooj.help=>
@arthuredelstein
arthuredelstein / hailstone.clj
Created February 17, 2013 04:08
Exploring the Hailstone Sequence in Clojure. See https://en.wikipedia.org/wiki/HOTPO
(defn hotpo
"One iteration of the hailstone sequence."
[n]
(if (even? n)
(/ n 2)
(inc (* 3 n))))
(defn hotpot [x]
"Finds a hailstone sequence starting with integer x."
(take-while #(> % 1)
@arthuredelstein
arthuredelstein / stuff.clj
Created February 17, 2013 04:21
useful stuff
(defn clj->js
"Recursively transforms ClojureScript maps into Javascript objects,
other ClojureScript colls into JavaScript arrays, and ClojureScript
keywords into JavaScript strings."
[x]
(cond
(string? x) x
(keyword? x) (name x)
(map? x) (.-strobj (reduce (fn [m [k v]]
(assoc m (clj->js k) (clj->js v))) {} x))
@arthuredelstein
arthuredelstein / github_jsonp.cljs
Last active September 27, 2016 05:05
Reading a file on github via jsonp (no authentication needed) with clojurescript in the web browser. Requires JQuery.
(ns github-jsonp)
(defn store-callback [reference address-vec]
(fn [val]
(swap! reference assoc-in address-vec val)))
(defn base64-decode [x]
(js/atob (clojure.string/replace x #"\s" "")))
(defn jsonp [url callback]
@arthuredelstein
arthuredelstein / cljs-multiple-file-reader.cljs
Last active December 14, 2015 12:28
User choosers a folder; browser reads files (in cljs)
;; uses hiccups/render-html
(defn new-window-document []
(.. js/window open -document))
(defn folder-chooser [id]
[:input {:id id
:type "file"
:webkitdirectory ""
#!/usr/bin/env python
# Expects paths to two files: Prints the code points in the first file but not in the second,
# and vice versa.
# Based on https://stackoverflow.com/questions/4458696/finding-out-what-characters-a-font-supports
from itertools import chain
import sys
@arthuredelstein
arthuredelstein / diff debian vs ubuntu
Created August 3, 2015 20:59
diff/diff --styles default webapp/submissions/0eee0d93db8a9e66bad37ce8acb54ffd-20150803160656-1afafbb8 webapp/submissions/3dfa829a829a698f81525d9d459b9e45-20150803160639-3c493199
U+0900 default 510×1477 510×1478 (+0,+1)
U+0901 default 510×1477 510×1478 (+0,+1)
U+0902 default 510×1477 510×1478 (+0,+1)
U+0903 default 782×1477 782×1478 (+0,+1)
U+0904 default 764×1477 764×1478 (+0,+1)
U+0905 default 764×1477 764×1478 (+0,+1)
U+0906 default 1023×1477 1023×1478 (+0,+1)
U+0907 default 474×1477 474×1478 (+0,+1)
U+0908 default 474×1477 474×1478 (+0,+1)
U+0909 default 548×1477 548×1478 (+0,+1)