Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack Rusher jackrusher

View GitHub Profile
@jackrusher
jackrusher / seq-primer.clj
Created Jun 1, 2021
Condensed visual tutorial in #Bauhaus style for a subset of the #Clojure seq API (inspired by similar JS tweets)
View seq-primer.clj
(def ■ '■)
(def ▲ '▲)
(def ● '●)
(first [● ■ ▲]) ;
(second [● ■ ▲]) ;
(nth [● ■ ▲] 2) ;
(rest [● ■ ▲]) ; (■ ▲)
(last [● ■ ▲]) ;
(butlast [● ■ ▲]) ; (● ■)
View twitter-gifs.md

Twitter abuses all media file uploads, each type in its own way. If we want to upload a good looking animation loop from some low-color, high-detail generative art, we have to game their system's mechanisms.

  • don't upload a video file, they will re-encode it into absolute 💩

  • create a GIF, which they will auto-convert into a video file 😱

  • The frames of the GIF will be resized to an even-sized width using an extremely naive algorithm. Your GIF should be an even size (1000, 2000,

View AAA-README.md

Meld

A minimal example of creating a (mostly) working FUSE filesystem using Clojure. NOTE: I have only tested this with OSX, and it assumes you have already installed libfuse.

Trying it out

Create an empty directory at /tmp/meld to serve as your mount point, put these files in a directory called meld, then:

@jackrusher
jackrusher / json->edn.el
Created Apr 16, 2020
Convert the current region in emacs from JSON to EDN using Bork's Jet.
View json->edn.el
;; Uses https://github.com/borkdude/jet
;; On OSX, install jet with:
;; brew install borkdude/brew/jet
;; I invoke this with M-x, you might want to bind it to a key
(defun json->edn ()
(interactive)
(shell-command-on-region (region-beginning)
View extract-tables.clj
(ns appliedsciencestudio.covid19-clj-viz.repl
(:require [clojure.string :as string]
[hickory.core :as hick]
[hickory.select :as s]))
;;;; Scraping data
(def wiki-page
"We want this data, but it's only published as HTML."
(slurp "https://en.wikipedia.org/wiki/List_of_countries_by_hospital_beds"))
View scrape-worldometer.clj
(ns appliedsciencestudio.covid19-clj-viz.repl
(:require [clojure.string :as string]
[hickory.core :as hick]
[hickory.select :as s]))
;;;; Scraping data
(def worldometers-page
"We want this data, but it's only published as HTML."
(-> (slurp "https://www.worldometers.info/coronavirus/")
hick/parse
@jackrusher
jackrusher / emacs-related.sh
Created Mar 4, 2020
A few shell things to make working with emacs nicer (OSX focus)...
View emacs-related.sh
View wikidata-geo.clj
;; Where are all the -ow -itz place names in Germany? (Limit to 10 for printability)
(query
'[:select *
:where [[?ort (wdt :instance-of) / (wdt :subclass-of) * (entity "human settlement")
_ (wdt :country) (entity "Germany")
_ rdfs:label ?name
_ (wdt :coordinate-location) ?wo]
:filter ((lang ?name) = "de")
:filter ((regex ?name "(ow|itz)$"))]
:limit 10])
@jackrusher
jackrusher / negative-harmony.clj
Created Jun 25, 2019
Some example code for calculating triad transformations using Ernst Levy's concept of Negative Harmony, as recently popularized by Jacob Collier.
View negative-harmony.clj
(def the-notes
(cycle [:c :db :d :eb :e :f :gb :g :ab :a :bb :b]))
(def key-offset
(zipmap (take 12 the-notes) (range)))
(defn triads [the-key]
(let [offset (key-offset the-key)
scale (cycle [0 2 4 5 7 9 11])]
(map
@jackrusher
jackrusher / gcloud-tramp.el
Created Jun 19, 2019
Tramping into GCloud instances from within emacs
View gcloud-tramp.el
;; make sure you've set your default project with:
;; gcloud config set project <project-name>
(require 'tramp)
(add-to-list 'tramp-methods
'("gcssh"
(tramp-login-program "gcloud compute ssh")
(tramp-login-args (("%h")))
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")