Skip to content

Instantly share code, notes, and snippets.

View cstorey's full-sized avatar

Ceri Storey cstorey

View GitHub Profile
@cstorey
cstorey / tyche.js
Created March 1, 2014 23:35
Pseudorandom number generator in Javascript. Algorithm from "Fast and Small Nonlinear Pseudorandom Number Generators for Computer Simulation" by Samuel Neves and Filipe Araujo.
function Tyche(seed, idx) {
this.a = seed & 0xffffffff;
this.b = (seed / ((2<<16)*(2<<16))) & 0xffffffff;
this.c = 2654435769;
this.d = (1367130551 ^ idx) >>> 0;
for (var i = 20; i > 0; --i) {
this._mix();
}
}
(require '[clojure.core.async :refer [alt! <!! chan go-loop]])
(defn events [quit-ch {perpage :perpage offset :offset orderby :orderby}]
(let [out-port (chan)
(go-loop [offset offset]
(let [res (client/get
(str "https://api.meetup.com/2/events?page=" perpage
"&offset=" offset
"&orderby=" orderby
"&status=upcoming,past&"
PATH := ./foo:$(PATH)
export PATH
foo:
mkdir -vp $@
foo/bar: foo
printf "#!/bin/echo Hello\n" > $@.tmp && chmod +x $@.tmp && mv -v $@.tmp $@
runit_okay: foo/bar
@cstorey
cstorey / IMG.sh.txt
Last active August 29, 2015 14:03
Render an image in a 256 colour capable terminal.
Adapted for 256 color terminals from the 24-bit colour version at https://git.gnome.org/browse/vte/tree/perf/img.sh?h=vte-0-36 .
Original script (and this adaptation) licensed under GPLv2.
Octocat image used under presumed license from https://octodex.github.com/faq.html
@cstorey
cstorey / nice_xpath.js
Created August 2, 2012 21:37
Run an xpath expression against the current document
function nice_xpath(xp) {
var x = document.evaluate(xp, document.documentElement, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null, null);
if (x) {
var node = x.iterateNext();
while (node) {
console.log(node);
node = x.iterateNext();
}
}
}
@cstorey
cstorey / index.html
Created September 8, 2012 20:53
Using Flapjax in ClojureScript
<html>
<head>
<title>Flapjax Demo: Time 1</title>
</head>
<p>The time is <span class="fixedBlock"><span id="timer">not initialized</span></span>.</p>
<p>The time in seconds is <span class="fixedBlock"><span id="timer2">not initialized</span></span>.</p>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
: cez@rhk; (cd /usr/local/ && git remote -v)
origin https://github.com/mxcl/homebrew.git (fetch)
origin https://github.com/mxcl/homebrew.git (push)
: cez@rhk;
@cstorey
cstorey / erlang_confusion.md
Last active December 11, 2015 01:48
The tribulations of finding parallels between actors and objects in Erlang.

It's quite easy to draw parallels between the Alan Kay's definition of objects (ie: the important part is messaging) and actors as found in Erlang (independent processes communicating via messages). And one parallel seems to be between the supervisor, and factories (as supervisors are responsible for the lifecycle of it's child processes, as a factory can be for objects, I think).

So, if you have processes A and B supervised by S, but B needs to send messages to A, then it might seem like a good idea to dynamically create both in Module:start_link, eg:

-module(something_sup).

-behavior(supervisor).

start_link() -&gt;
@cstorey
cstorey / gist:4969536
Last active December 13, 2015 20:19
Clojure's rest arguments are quite fast, as it turns out:
user=> (doseq [f [(fn [& r] r) list vector]] (time (dotimes [_ 10000000] (f 1 2))))
"Elapsed time: 89.534 msecs"
"Elapsed time: 1619.788 msecs"
"Elapsed time: 659.573 msecs"
nil
user=> (doseq [f [(fn [& r] r) list vector]] (time (dotimes [_ 100000000] (f 1 2))))
"Elapsed time: 284.97 msecs"
"Elapsed time: 16061.555 msecs"
"Elapsed time: 6207.421 msecs"
nil