Skip to content

Instantly share code, notes, and snippets.

View cstorey's full-sized avatar

cstorey

View GitHub Profile
@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 / protocol-stub.cljs
Created September 8, 2012 11:51
Stubbing a protocol in Clojurescript.
(require '[cljs.analyzer :as a])
(defn methods-by-protocol [ns]
(->> (a/get-namespace ns)
:defs
(map val)
(filter :protocol)
(reduce
(fn [map d]
(update-in map [(:protocol d)] #(conj (or % #{}) d)))
@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>
@cstorey
cstorey / index.html
Last active January 11, 2019 18:21
PyStone (really Dhrystone) ported to Javascript.
<html>
<head>
<title>Pystones.js</title>
</head>
<p>Result: <span id="result">Pending</span></p>
<p><button id="run">Run</button></p>
<script type='text/javascript' src="pystone.js"></script>
<script type='text/javascript'>
// <![[CDATA[
const runbutton = document.querySelector("#run");
: 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
@cstorey
cstorey / cek.ml
Created February 19, 2013 21:55
Today's lunchtime fun: Rewriting the code from Matt Might's article on CEK machines in OCaml
(* See http://matt.might.net/articles/cek-machines/ *)
type var = string
type term =
Ref of var
| Lam of lambda
| App of term * term
and lambda = L of var * term
@cstorey
cstorey / signals.c
Last active December 14, 2015 03:48
Test program for re-enterancy of signal handlers. Compile with 'gcc -o signal signal.c' (or adjust to taste).
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
handler(int signum)
{
printf("Catching signal %d\n",signum);
sleep(1);