Skip to content

Instantly share code, notes, and snippets.

View cstorey's full-sized avatar

Ceri Storey cstorey

View GitHub Profile
@cstorey
cstorey / gist:5377503
Last active December 16, 2015 04:29
Include a background worker in a heroku web dyno.
web: (while true; do echo MARK $(date --iso-8601=seconds); sleep 5; done) & ruby --version; bin/rackup -Ilib -s puma rackup.ru -p $PORT
# Or slightly more clearly
web: rake resqueue:worker & ruby --version; bin/rackup -Ilib -s puma rackup.ru -p $PORT
@cstorey
cstorey / gosnow.rb
Created April 12, 2013 10:39
Playing around with id generation inspired by gosnow. And by "inspired by" I mean "a blatant copy of".
require 'zlib'
require 'socket'
require 'thread'
WORKERID_BITS = 10
MAX_WORKER_ID = -1 ^ (-1 << WORKERID_BITS)
SEQUENCE_BITS = 12
MAX_SEQUENCE = -1 ^ (-1 << SEQUENCE_BITS)
SINCE_MILLIS = Time.utc(2012, 1, 1).to_f * 1000
@cstorey
cstorey / hack.patch
Last active December 15, 2015 21:59
Mutant crash on 39cd9d72d of cstorey/srsrb.
Mutant configuration:
Matcher: #<Mutant::Matcher::Method::Instance identification="SRSRB::CardEditorApp#card_models_as_dictionary">
Filter: Mutant::Mutation::Filter::ALL
Strategy: #<Mutant::Strategy::Rspec::Full>
Subject: SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110
Alive: rspec:noop:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:24ec0 (0.71s)
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:3e242 (0.43s)
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:5d14b (0.43s)
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:3aca1 (0.42s)
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:d8c97 (0.45s)
@cstorey
cstorey / gist:5129666
Last active December 14, 2015 18:29
Ruby's rather non-deductive behavior difference between lambdas / procs. (Edited for coherency).
1.9.3p0 :004 > require 'pp'
=> true
1.9.3p0 :002 > p = proc { |a| pp proc_args: a }
=> #<Proc:0x0000010090b838@(irb):2>
1.9.3p0 :010 > p.call(1,2)
{:proc_args=>1}
1.9.3p0 :008 > stabby = ->(a) { pp stabby_args: a }
=> #<Proc:0x00000101099410@(irb):8 (lambda)>
1.9.3p0 :009 > stabby.call(1,2)
ArgumentError: wrong number of arguments (2 for 1)
@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);
@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 / 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 / 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;
: 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;