View recursive-transient-persistent-transform.clj
This file contains 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
(require '[clojure.walk :as walk]) | |
;; => nil | |
(defn transient? [x] | |
(instance? clojure.lang.ITransientCollection x)) | |
;; => #'user/transient? | |
(let [transients (walk/postwalk (fn [x] | |
(if (map? x) | |
(transient x) |
View quick-pr-str.clj
This file contains 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 quick-pr-str | |
([data] | |
(let [acc (StringBuilder.)] | |
(quick-pr-str acc data) | |
(.toString acc))) | |
([^StringBuilder acc data] | |
(cond | |
(string? data) | |
(do | |
(.append acc \") |
View harlem-shake.js
This file contains 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: (function () { | |
function c() { | |
var e = document.createElement("link"); | |
e.setAttribute("type", "text/css"); | |
e.setAttribute("rel", "stylesheet"); | |
e.setAttribute("href", f); | |
e.setAttribute("class", l); | |
document.body.appendChild(e) | |
} | |
function h() { |
View midijam.clj
This file contains 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
;; http://notahat.com/midi_patchbay/ | |
;; Create a virtual input and virtual output in MIDI patchbay | |
;; input name: "Overtone" | |
;; output name: "yourchoice" | |
;; In Reason, Ableton, etc. select "yourchoice" | |
;; as the midi input for a channel. | |
(ns jam.core | |
(:use [overtone.live])) |
View day05.clj
This file contains 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
(ns day05 | |
(:require [clojure.string :as str] | |
[clojure.set :as set])) | |
(def boarding-passes "...") | |
(defn find-pos [ops size lower-op upper-op] | |
(loop [ops ops | |
xs (range 0 (inc size))] | |
(if (seq ops) |
View autotune.clj
This file contains 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
(defsynth pitch-follow-1 [] | |
(let [in (mix [(sound-in)]) | |
amp (amplitude:kr in 0.05 0.05) | |
[freq has-freq] (pitch:kr in | |
:amp-threshold 0.02 | |
:median 7) | |
out-1 (mix [(var-saw:ar (mul-add:ar 0.5 1 2) | |
0 | |
(lf-noise1:kr (mul-add:kr 0.3 0.1 0.1)))]) | |
out-2 (loop [n 6 |
View cheating.clj
This file contains 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 gen-nonvariadic-invokes [f] | |
(for [arity (range 1 21), | |
:let [args (repeatedly arity gensym)]] | |
`(~'invoke [~@args] (~f ~@args)))) | |
(defn gen-variadic-invoke [f] | |
(let [args (repeatedly 22 gensym)] | |
`(~'invoke [~@args] (apply ~f ~@args)))) | |
(defn gen-apply-to [f] |
View clojure_zippers.clj
This file contains 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
(require '[clojure.zip :as z]) | |
(defn update-in* | |
"Like update-in, but also works with nested sets." | |
[m ks f & args] | |
(let [up (fn up [m ks f args] | |
(let [[k & ks] ks] | |
(if ks | |
(if (set? m) | |
(conj (disj m k) (up (get m k) ks f args)) |
View coinstar.clj
This file contains 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
(ns coinstar | |
(:import [java.time LocalDate])) | |
(def working? (constantly false)) | |
(defn go | |
"Provided a `who` and `when`, returns the state of | |
a coinstar `when` the `who` goes to it. | |
Example: |
View numbers-to-english.clj
This file contains 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
(ns quiz.core | |
(:require [clojure.pprint :as pp])) | |
(defn to-english [n] | |
(pp/cl-format nil "~@(~@[~R~]~^ ~A.~)" n)) | |
(to-english 99999999999999999) | |
;=> "Ninety-nine quadrillion, nine hundred ninety-nine trillion, nine hundred ninety-nine billion, nine hundred ninety-nine million, nine hundred ninety-nine thousand, nine hundred ninety-nine" | |
(map to-english (range 0 101)) |
NewerOlder