Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
🥫

JG tlkahn

🥫
View GitHub Profile
(function(global) {
global.Functor = function(conf) {
Functor.types[conf.key] = {
obj: conf.obj,
fmap: conf.fmap
};
};
Functor.types = {};
@tlkahn
tlkahn / Functor.js
Created November 3, 2015 20:37 — forked from CrossEye/Functor.js
First Functor Fantasy
(function(global) {
var types = function(obj) {
throw new TypeError("fmap called on unregistered type: " + obj);
};
// inefficient as hell, but as long as there aren't too many types....
global.Functor = function(type, defs) {
var oldTypes = types;
types = function(obj) {
if (type.prototype.isPrototypeOf(obj)) {
@tlkahn
tlkahn / 0.js
Created December 6, 2015 18:14 — forked from mxriverlynn/0.js
recursing a tree structure with ES6 generators
function *doStuff(){
yield 1;
yield 2;
yield *doStuff();
}
var it = doStuff();
var res;
res = it.next();
var graph = 'graph.json'
var w = 960,
h = 700,
r = 10;
var vis = d3.select(".graph")
.append("svg:svg")
.attr("width", w)
.attr("height", h)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tlkahn
tlkahn / maybe.traceur
Created December 12, 2015 21:01 — forked from torgeir/maybe.traceur
An es6 js maybe monad, using generators
log = console.log.bind(console);
maybe = v => {
function * f () {
if (v) yield v;
}
f.bind = f =>
v ? f(v) : maybe();
@tlkahn
tlkahn / option.js
Created December 12, 2015 21:06 — forked from igstan/option.js
// `unit` is `return` from Haskell
// `bind` is `>>=` from Haskell, or `flatMap` from Scala
var None = {
bind: function (fn) { return this; },
unit: function (v) { return Option(v); },
getOrElse: function (elseValue) { return elseValue; }
};
var Some = function (value) {
@tlkahn
tlkahn / 0_reuse_code.js
Created December 16, 2015 06:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tlkahn
tlkahn / gists_to_dash_db.rb
Last active December 18, 2015 05:50 — forked from voising/gists_to_dash_db.rb
Connect Gists with Dash (Code Snippet Manager)
#!/usr/bin/env ruby
if ARGV[0].nil? || ARGV[0].match(/-h/)
puts "Usage : #{$0} github_username dash_sqlite_db char_appended_to_keyword [no_comments]"
exit
end
require 'net/http'
require 'open-uri'
#require 'awesome_print'
@tlkahn
tlkahn / vtable.cpp
Created May 17, 2016 19:29 — forked from netguy204/vtable.cpp
Monkey patching a C++ class by modifying its VTABLE.
#include <stdio.h>
#include <stdint.h>
class A {
public:
virtual void doThing() {
printf("I'm an A\n");
}
};