Skip to content

Instantly share code, notes, and snippets.

View jackrusher's full-sized avatar

Jack Rusher jackrusher

View GitHub Profile
@jackrusher
jackrusher / count-words.el
Last active July 5, 2019 13:00
I like to know how many words are in my markdown files.
;; this function is included in modern emacs, but here it is in case you haven't upgraded
(defun count-words (start end)
"Count words between START and END.
If called interactively, START and END are normally the start and
end of the buffer; but if the region is active, START and END are
the start and end of the region. Print a message reporting the
number of lines, words, and chars.
If called from Lisp, return the number of words between START and
@jackrusher
jackrusher / triangles.clj
Created September 21, 2013 00:44
Clojure + Quil = Colorful triangle party
(defn hex-to-rgb [hex]
(map (comp #(Integer/parseInt % 16) (partial apply str))
(partition 2 (.replace hex "#" ""))))
(def palette [(hex-to-rgb "#FF1E35")
(hex-to-rgb "#F9F33B")
(hex-to-rgb "#3B3EF9")
(hex-to-rgb "#E54ED8")
(hex-to-rgb "#84E54E")])
(defn setup []
(frame-rate 4)
(no-fill)
(stroke 0 0 0 128)
(smooth))
(def rotor (atom 0))
(defn draw []
(frame-rate 30)
(defn setup []
(smooth)
(no-fill))
(defn superformula-point [m n1 n2 n3 phi]
(let [t1 (pow (abs (cos (/ (* m phi) 4.0))) n2)
t2 (pow (abs (sin (/ (* m phi) 4.0))) n3)
r (pow (+ t1 t2) (/ 1 n1))]
(if (= 0 (abs r))
[0 0]
(def palette [(hex-to-rgb "#e0e0e0")
(hex-to-rgb "#B6B081")
(hex-to-rgb "#CAA13C")
(hex-to-rgb "#AB5008")
(hex-to-rgb "#2E524E")])
(defn setup []
(frame-rate 4)
(no-fill)
(smooth))
@jackrusher
jackrusher / heart-murmur.clj
Last active December 24, 2015 16:09
My first attempt at an aleatoric composition with Overtone. An example of the audio output is here: https://soundcloud.com/jackrusher/heart-murmur
(ns overtone-playground.heart-murmur
(:use overtone.core
overtone.inst.sampled-piano
overtone.samples.piano))
;; (boot-server)
;; (sampled-piano)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Reproducible randomness

Leopards in the Source Code

I've been having some fun recently making visual art with Clojure and Quil, especially animated GIFs. In the course of doing this, I've come into contact with many GIFs made by other artist-programmers, some of which have included source code. I'm republishing one of them, called rainbow kiss,

@jackrusher
jackrusher / cider-eval-sexp-fu.el
Created December 2, 2013 22:13
nrepl-eval-sexp-fu.el modified to work with cider.
;;; cider-eval-sexp-fu.el --- Tiny functionality enhancements for evaluating sexps.
;; Copyright (C) 2009 Takeshi Banse <[email protected]>
;; Author: Takeshi Banse <[email protected]>
;; Modified to add cider support by Sam Aaron <[email protected]>
;; Keywords: lisp, highlight, convenience
;; Package-Requires: ((highlight "0.0.0") (smartparens "0.0.0") (thingatpt "0.0.0")
;; This program is free software; you can redistribute it and/or modify
@jackrusher
jackrusher / rhyming-and-scheming.clj
Created January 26, 2014 22:42
Finding rhymes with clojure and CMU's pronunciation dictionary. Tested with this file, minus comments, as 'cmudict.txt': http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict.0.7a
(def rhyme-txt
(map #(string/split % #"[ ]+") (string/split-lines (slurp "cmudict.txt"))))
(def word-to-rhyme
(reduce (fn [m [word & rhyme]]
(assoc m
(string/lower-case word)
(mapv #(keyword (string/replace %1 #"[0-9]" "")) (reverse rhyme))))
{} rhyme-txt))
@jackrusher
jackrusher / negative-space.clj
Last active October 15, 2024 10:38
Clojure, Haskell and OCaml implementations of the same algorithm, which is a negative space finder for a very constrained situation involving nested rectangles. For those interested in a more comprehensive take on these relationships (using scheme rather than clojure), see: http://lambda.jimpryor.net/translating_between_ocaml_scheme_and_haskell/
(def parent {:x1 0 :y1 0 :x2 600 :y2 400})
(def rs [{:x1 0 :y1 0 :x2 300 :y2 200 }
{:x1 0 :y1 200 :x2 300 :y2 400 }])
(defn negative-space [parent rs]
(let [x (apply max (map :x2 rs))
y (apply min (map :y1 (filter (comp (partial = x) :x2) rs)))]
{:x1 x :y1 y :x2 (parent :x2) :y2 (parent :y2)}))
(negative-space parent rs)