Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / blocks.cljs
Last active January 2, 2016 06:19
Core.async example from Timothy Baldridge's Clojure/Conj 2013 talk: http://youtu.be/enwIIGzhahw, demonstrating 4800 'green' threads. Code modified from: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj#L585
(ns clojure-conj-talk.core
(:use [enchilada :only [canvas ctx canvas-size]]
[monet.canvas :only [fill-style fill-rect]]
[jayq.core :only [show]])
(:require [cljs.core.async :refer [<! >! chan timeout]])
(:require-macros [cljs.core.async.macros :as m :refer [go]]))
(def colors
(rand-nth [
[
@rm-hull
rm-hull / sin.cljs
Last active December 30, 2015 01:49 — forked from martintrojer/sin.cljs
Sample core.async - see it running in the browser: http://programming-enchiladas.destructuring-bind.org/rm-hull/7758795
(ns async-test.sinewave.core
(:require [cljs.core.async :refer [<! >! chan timeout]])
(:require-macros
[cljs.core.async.macros :as m :refer [go]]))
(defn sin-vals [offset]
(map #(Math/sin %) (iterate (partial + 0.1) offset)))
(let [events (chan)]
@rm-hull
rm-hull / boids.cljs
Last active December 26, 2015 11:39
Boids, originally written by Craig Reynolds in 1986, is an artificial live program which simulates flocking birds (but in this case just in 2D). It is an example of emergent behaviour; that is, the complexity of Boids arises from the interaction of individual agents adhering to a set of simple rules, (i) separation: steering to avoid crowding lo…
(ns boids
(:use [enchilada :only [canvas ctx value-of canvas-size]]
[jayq.core :only [show]]
[monet.core :only [animation-frame]]
[monet.canvas :only [save restore
begin-path move-to line-to close-path
stroke stroke-style fill fill-rect fill-style
rotate translate]]
[boids.rules :only [step make-boid]])
(:require [boids.vector :refer [heading]]))
(ns recurring.example
(:require [enchilada]))
(loop [xs [[1 1 1] [2 2 2] [3 3 3]]]
(when-let [[a b c] (first xs)]
(println a b c)
(recur (rest xs))))
@rm-hull
rm-hull / TORUS.md
Last active December 26, 2015 05:09
A tumbling three-dimensional wireframe torus (and other assorted shapes) in ClojureScript rendered on a canvas, using the wireframes library.
@rm-hull
rm-hull / quine.cljs
Last active December 25, 2015 23:59
From Wikipedia: "A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs. A quine is a fixed point of an ex…
(println
(#(list % (list 'quote %)) '#(list % (list 'quote %))))
(ns tests
(:refer-clojure :exclude [==])
(:use-macros
[cljs.core.logic.macros
:only [run run* == conde conda condu fresh defne matche all]])
(:require-macros [cljs.core.logic.macros :as m]
[clojure.tools.macro :as mu])
(:use
[enchilada :only [ctx]]
[cljs.core.logic
@rm-hull
rm-hull / classic-ai.cljs
Last active December 24, 2015 14:59
Adapted to clojurescript flavor, derived from https://github.com/clojure/core.logic/wiki/Examples
(ns classic-ai-example
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [-take*]]))
(m/defne moveo [before action after]
([[:middle :onbox :middle :hasnot]
:grasp
[:middle :onbox :middle :has]])
([[pos :onfloor pos has]
:climb
@rm-hull
rm-hull / core-logic-demo.cljs
Created October 3, 2013 19:58
Simple script to check that core.logic is wired in properly
(ns example
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [membero]]))
(println
(m/run* [q]
(membero q '(:cat :dog :bird :bat :debra))))
@rm-hull
rm-hull / sudoku.cljs
Last active December 24, 2015 14:49 — forked from swannodette/gist:3217582
(ns sudoku
;(:refer-clojure :exclude [==])
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [everyg infd distinctfd]]))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))