Skip to content

Instantly share code, notes, and snippets.


Erik Ferguson muraiki

View GitHub Profile
muraiki / my functional things
Created Sep 21, 2013
A concussion has prevented me from doing much coding these past 9 months, but in a fit of boredom I wrote this...
View my functional things
lazy semantics and lambda abstractions
point-free in style and pure computation
memoization gives simple caching
these are a few of my functional things
when the state bites
when the C stings
when impure is bad
I simply remember my functional things
and then I don't feel so mad
muraiki / core.clj
Created Oct 8, 2014
View core.clj
(ns ajax-to-websocket.core
(:require [org.httpkit.server :as server]
[org.httpkit.client :as client]
[ :as json]
[ :as data]
[clojure.core.async :refer [chan <! >! go timeout onto-chan]]))
(defn channel-closed
"called when websocket channel is closed"
muraiki / fib.pl6
Last active Aug 29, 2015
View fib.pl6
subset NonNegativeInt of Int where * >= 0;
proto fib (|) is cached returns NonNegativeInt {*}
multi fib (0) { 0 }
multi fib (1) { 1 }
multi fib (NonNegativeInt $n) { fib($n - 1) + fib($n - 2) }
say fib(100)
View gist:492539f842085f980349
def groupBy[A](xs: List[A]): Map[A, Int] =
xs.foldLeft(Map[A, Int]()) { (m: Map[A, Int], x: A) => m + (x -> (m.get(x).getOrElse(0) + 1)) }
muraiki / gist:96d746eff5f564c32990
Created Mar 19, 2015
updating KO model from json
View gist:96d746eff5f564c32990
// map the keys in json to the properties on your model
var desiredKeys = {
"foo": "foo",
"bar": "bar"
Object.defineProperty(self, 'updateFromJson', {
enumerable: true,
value: function (data) {
muraiki / gist:5cc72eaeb20a57da31bc
Created Mar 19, 2015
KO model with getters/setters and json update support
View gist:5cc72eaeb20a57da31bc
function FooModel () {
Object.defineProperties(this, {
_foo: {
value: ko.observable(,
enumerable: true,
configurable: true
_bar: {
value: ko.observable(x.server_id || x.instance_id || x.instanceId),
enumerable: true,
muraiki /
Last active Aug 29, 2015
merge two files
use strict;
use warnings;
open (my $foo, '<', 'foo.txt') or die;
open (my $bar, '<', 'bar.txt') or die;
open (my $merged, '>', 'merged.txt') or die;
print $merged '#!/bin/sh', "\n";
while (not eof $foo and not eof $bar) {
muraiki / gist:077aef846a775028eec8
Created Jul 7, 2015
Intro to anonymous functions in Perl
View gist:077aef846a775028eec8
# Intro to anonymous functions in Perl
use strict;
use warnings;
use feature qw(say);
use utf8;
binmode STDOUT, ':utf8';
# You can declare a sub without giving it a name. Hence, "anonymous" function.
sub { say 'this sub will never be called' };
muraiki / watch_and_chown.p6
Last active Aug 29, 2015
Watch a file and chown it once it exists
View watch_and_chown.p6
my $PATH = '.';
my $USER = 'muraiki';
my $GROUP = 'staff';
.unique(:as(*.path), :expires(1))\
.grep(* ~~ /\.sock/)\
.act(-> $socket {
say "Socket created: $socket"; # actually this happens for any I/O on the file, not just creation
muraiki / watch_source_files.p6
Last active Sep 4, 2015
Watch source files using Supplies
View watch_source_files.p6
# disclaimer: I'm a perl6 noob :)
my $out =;
$out.act: -> $s { say $s }; # actor model semantics; only ever execute this in 1 thread
my $watcher =$*CWD.abspath)\
.unique(:as(*.path), :expires(1))\ # unique paths over last second, to prevent double-triggering from metadata events
.map(*.path.IO)\ # convert event path strings to IO::Path objects
.grep(*.extension eq 'p6')\