Skip to content

Instantly share code, notes, and snippets.

(ns typed-play.core
(:require-macros [clojure.core.typed :as ct])
(:require [clojure.core.typed :as ct]))
(ct/ann my-identity (All [x] (Fn [x -> x])))
(defn my-identity [x]
(if (number? x)
(inc x)
x))
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]
@rm-hull
rm-hull / DHT.c
Last active December 18, 2022 15:40
// How to access GPIO registers from C-code on the Raspberry-Pi
// Example program
// 15-January-2012
// Dom and Gert
//
/*
$ wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.8.tar.gz
$ tar -zxvf bcm2835-1.8.tar.gz
$ cd bcm2835-1.8
(ns n01se.externs-for-cljs
(:require [clojure.java.io :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
@rm-hull
rm-hull / autostereogram.cljs
Last active December 18, 2015 05:59
A SIRD (Single Image Random Dot) diagram, a.k.a. 'Magic Eye' or autostereogram is a single-image stereogram (SIS), designed to create the visual illusion of a three-dimensional (3D) scene within the human brain from an external two-dimensional image. In order to perceive 3D shapes in these autostereograms, one must overcome the normally automati…
(ns autostereogram.demo
(:use [monet.canvas :only [draw-image]]
[enchilada :only [canvas ctx proxy-request]]
[jayq.core :only [show]]
[jayq.util :only [log]]))
(def greens
(map #(vector 0x30 % 0x30 0xFF) (range 0xCF)))
(defn random-data [w h colors]
@rm-hull
rm-hull / penrose-tiling.cljs
Last active July 5, 2016 19:48
A Penrose tiling is a non-periodic tiling generated by an aperiodic set of prototiles. Penrose tilings are named after mathematician and physicist Roger Penrose who investigated these sets in the 1970s. This gist describes the tiling in terms of a rewriting grammar (an 'L-system') and renders using a turtle (https://github.com/rm-hull/turtle) on…
(ns lindenmayer-systems.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.vector :only [->svg]]
[turtle.renderer.canvas :only [->canvas]]
[enchilada :only [ctx canvas svg]]
[dommy.core :only [set-html! insert-after! replace! hide! show!]]
[jayq.core :only [show]])
(:use-macros [dommy.macros :only [sel1]]))
(def L '(:left 36))
(ns mod-test.example)
; Something very odd is happening with mod when used with some string values whose content happen to be numbers.
;
; Clearly it shouldn't be called with a string, but this doesn't appear to affect modulo "1", "3", "9", "11"
;
; when the rem function is used with string numbers is not affected in the same way, and appears to operate consistently.
;
; Is this some funky gotcha with javascript, or is it a side-effect of the way clojurescript implements mod?
;
@rm-hull
rm-hull / quadratic-residues.cljs
Last active June 30, 2016 22:24
Exploring quadratic residues and fixed points with clock arithmetic and digraphs, in Clojurescript with force-directed graph layout provided by _arbor.js_. Inspired, in part, by http://pi3.sites.sheffield.ac.uk/tutorials/week-8. Defaults to 51 data points, which produces a pleasing digraph, but add a _num=X_ param to the URL to show different ri…
(ns quadratic-residue.demo.core)
(defn follow [lookup-table]
(fn [n]
(loop [k n
edges {}]
(let [next-k (lookup-table k)]
(if (edges next-k)
edges
(recur next-k (assoc edges k next-k)))))))
@rm-hull
rm-hull / world-choropleth.cljs
Last active December 17, 2015 02:38
Example world choropleth demonstrating C2 integration, using Albers equal-area conic projection (http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html). C2 is a Clojure and ClojureScript data visualization library that lets you declaratively create HTML and SVG markup based on data.
(ns world-choropleth.demo
(:use-macros [c2.util :only [bind!]])
(:use [jayq.core :only [show hide]]
[c2.core :only [unify]]
[c2.geo.core :only [geo->svg]]
[c2.geo.projection :only [albers]]
[dataset.geo.world :only [countries]]
[enchilada :only [canvas svg]])
(:require [c2.scale :as scale]))
s = 640, t = 480, u = Math, v = [
[0, 0, 0],
[255, 0, 0],
[255, 255, 255]
], q = document, k = 'center', x = q.createElement('input');
c.width = s;
c.height = t;
b.style.textAlign = x.style.textAlign = k;
var k, l, w = function (b) {
a.fillStyle = '#000';