Skip to content

Instantly share code, notes, and snippets.

View jackrusher's full-sized avatar

Jack Rusher jackrusher

View GitHub Profile
(require '[maria.eval :as e]
'[goog.object :as gobj]
'[clojure.string :as string])
(defn resolve-to-val [sym]
(let [{the-name :name} (e/resolve-var sym)]
(->> (string/split (str the-name) #"[\./]")
(map munge)
(to-array)
(apply gobj/getValueByKeys js/window))))
@jackrusher
jackrusher / giraffe.el
Created April 28, 2017 14:25
An example elisp function presented at Emacs Berlin
(defun giraffe ()
"Passes a the active region (highlighted text in non-emacs
speak) to an external command that produces an SVG graph of the
data, which is then placed in a buffer called *giraffe* and
viewed as an image."
;; Declare that this is an interactive command. Whenever a function
;; starts this way emacs will make it available to be called with
;; M-x or bound to a key.
(interactive)
(defn lorenz-points [p sigma beta dt]
(loop [n 6000
x 0.01
y 0
z 0
out []]
(if (= 0 n)
out
(recur (dec n)
(+ x (* p (- y x) dt))
@jackrusher
jackrusher / blur.glsl
Created February 14, 2017 10:13
A quick but pleasing loop make with clojure, thing_clj and a tiny shader.
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 texOffset;
varying vec4 vertTexCoord;
(def points
(atom
(let [radius 150 points 28]
(mapv #(vec2 (* radius (Math/cos (* 2 Math/PI (/ % points))))
(* radius (Math/sin (* 2 Math/PI (/ % points)))))
(range (inc points))))))
(defn mid-point [[x1 y1] [x2 y2]]
(vec2 (/ (+ x1 x2) 2) (/ (+ y1 y2) 2)))
;; owned by bertelsmann directly
(query '[:select ?item ?itemLabel
:where [[?item (prop :owned-by) (entity "Bertelsmann")]]])
;;=>
#{{:item "Q2908540", :itemLabel "Penguin Random House"}
{:item "Q7679725", :itemLabel "Talkback Thames"}
{:item "Q744182", :itemLabel "Random House"}
{:item "Q3621644", :itemLabel "Archivio Storico Ricordi"}
{:item "Q796316", :itemLabel "BMG Rights Management"}
{:item "Q22080314", :itemLabel "Boundless productions"}
@jackrusher
jackrusher / pdftoedn.clj
Created August 10, 2016 13:08
A couple of quick examples using clojure to inspect the output from https://github.com/edporras/pdftoedn
;; convert a PDF to EDN, then:
(def test
(clojure.edn/read-string (slurp "to_2007_prius_brake_control.edn")))
(map :text (:text_spans (first (:pages test))))
;;=>
;; N.B. all spans are re-sorted from the (often random) PDF file order
;; to the top down/left-right order suggested by how they're displayed
;; when the PDF is rendered.
("BC–24"
@jackrusher
jackrusher / wikidata-test.clj
Last active January 8, 2022 10:47
Quick example of using clojure with the Wikidata API to grab some facts about the world.
;;assumes that this package is available:
;;[org.wikidata.wdtk/wdtk-wikibaseapi "0.7.0"]
(import org.wikidata.wdtk.datamodel.interfaces.EntityDocument)
(import org.wikidata.wdtk.datamodel.interfaces.ItemDocument)
(import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)
(import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher)
(import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException)
;; Trying to automatically build a list of the presidents of the US
@jackrusher
jackrusher / prism.clj
Last active April 25, 2016 13:56
A function to produce prisms using clojure/quil.
(defn make-prism [sides radius segments]
(let [points (->> (for [i (range (inc sides))]
[(* radius (cos (* TWO-PI (/ i sides))))
(* radius (sin (* TWO-PI (/ i sides))))])
(partition 2 1 ))]
(begin-shape :triangles)
(doseq [[z1 z2] (partition 2 1 (map (partial * radius) (range (inc segments))))]
(doseq [[[x1 y1] [x2 y2]] points] ; segments
(vertex x1 y1 z1) ; tri A
(vertex x2 y2 z1)
@jackrusher
jackrusher / luna.clj
Created March 24, 2016 13:29
A rotating 3D moon in <70 lines of clojurescript using thing_clj.
(def shader-spec
{:vs "void main() {
vUV = uv;
gl_Position = proj * view * model * vec4(position, 1.0);
}"
:fs "void main() { gl_FragColor = texture2D(tex, vUV); }"
:uniforms {:model [:mat4 M44]
:view :mat4
:proj :mat4
:displace :sampler2D