Skip to content

Instantly share code, notes, and snippets.

@kybernetikos
kybernetikos / couch-x.html
Created April 26, 2011 09:47
An attachment that can be put on a couchdb document to allow you to avoid the cross domain issue when using the Javascript API from a web page served from a different port on the same host (e.g. from a separate tomcat). It's very useful for development.
<html>
<head>
<script type="text/javascript" src="/_utils/script/couch.js"></script>
<script type="text/javascript">
document.domain = window.location.hostname;
if (window.parent.oncouchready) {
@kybernetikos
kybernetikos / example.html
Created April 26, 2011 10:04
Uses https://gist.github.com/942047 to provide access to a separate couchdb running on a different port to the webserver that this file is loaded from. Assumes you've uploaded that couch-x.html file as an attachment to a document with id 'document' on a
<html>
<head>
<title>CouchTest</title>
<script>
document.domain = window.location.hostname;
window.oncouchready = function(api) {
CouchDB = api;
var database = new CouchDB("somedb");
@kybernetikos
kybernetikos / watchFile monkey patch.js
Created May 8, 2012 20:50
Make fs.watchFile work (kinda) on windows
var os = require('os');
if (os.platform() == 'win32') {
// change fs.watchFile so that it doesn't throw an error on windows.
fs.watchFile = function(filepath, callbackfunc) {
var old = fs.statSync(filepath);
fs.watch(filepath, function() {
fs.stat(filepath, function(err, newStat) {
callbackfunc(old, newStat);
@kybernetikos
kybernetikos / gist:5380463
Last active December 16, 2015 04:49
Define local variables from a map.
// Bad behaviour ahead!
// doesn't work with strict mode.
function local(obj) {
var global = Function("return this")();
var tmpName = "_tmp";
while (tmpName in global) {
tmpName = "_"+tmpName;
}
@kybernetikos
kybernetikos / gist:5588309
Created May 15, 2013 23:37
An example of some js compiled from coffeescript. See https://gist.github.com/josh/2553381 The sourceMappingURL is an entire source map that includes the coffeescript source, encoded in a base64 data uri. This could be generated programmatically. Evalling a string containing this gists contents in chrome canary puts you into the debugger showing…
// Generated by CoffeeScript 1.3.1
(function() {
var cubes, list, math, num, number, opposite, race, square,
__slice = [].slice;
number = 42;
opposite = true;
if (opposite) {
@kybernetikos
kybernetikos / gist:a264fba207527d775032
Created June 29, 2014 17:37
Asteroids: Machine Learning
try {
var WAIT = "wait"
var FIRE = "fire"
var ACTIONS = [WAIT, FIRE]
if (!context.classesDefined) {
context.classesDefined = true;
context.WorldState = function WorldState(numberOfAsteroids, asteroidX, asteroidVx, fired) {
this.asteroidX = asteroidX
@kybernetikos
kybernetikos / gist:61687b05fcf78a17576d
Last active August 29, 2015 14:16
SansBS bookmarklet
javascript:var cssLink=document.createElement('style');cssLink.innerHTML="@font-face { font-family: SansBS; src: url('data:font/ttf;base64,AAEAAAASAQAABAAgRkZUTVGwM9YAAKaYAAAAHEdERUYAJgDYAACmtAAAAB5HUE9T8lpNXgAAptQAABLAR1NVQhvFOicAALmUAAAV5k9TLzKg07VlAAABqAAAAGBjbWFwoIGYEgAABWAAAAGiY3Z0IDl+PkwAABD4AAAB/GZwZ21zhINeAAAHBAAABwVnYXNwAAQABwAApowAAAAMZ2x5Zs5ZPbgAABSkAACJQGhlYWQml1fWAAABLAAAADZoaGVhNgItRwAAAWQAAAAkaG10eMXDVZsAAAIIAAADWGxvY2EqhwaaAAAS9AAAAa5tYXhwA34GYgAAAYgAAAAgbmFtZefcI3UAAJ3kAAAGoHBvc3TfQqePAACkhAAAAgVwcmVwgtwhEwAADgwAAALsAAEAAAABAAB5kUCqXw889QAdCAAAAAAAyBdP9gAAAADRFL1c/qD+FC+aB3MAAAAIAAIAAAAAAAAAAQAAB3P+FAAAL7r+oP6iL+wAAQAAAAAAAAAAAAAAAAAAANYAAQAAANYE+AAXAFMABAACABAALwBaAAACHwDlAAMAAQADBCYBkAAFAAgFmgUzAAABHgWaBTMAAAPQAGYB8gAAAgsGBgMIBAICBOAAAu9AACBbAAAAKAAAAAAxQVNDAEAAICBEBh/+FACEB3MB7CAAAZ8AAAAABEoFtgAAACAAAggAAAAAAAAACAAAAAIUAAACJwCTAzcAhQUrADMEaAB7BpoAZgWeAG0BzwCFAmgAUgJoAD0EaABSBGgAZgIAAD8CkwBSAiUAkwL8ABQEaABiBGgAsgRoAGAEaABSBGgAFwRoAIMEaABxBGgAWgRoAGoEaABqAiUAkwIlAD8EaABmBGgAZgRoAGYDaAAlB
function itrReduce(src, reductionFn, destination) {
let result = {value: undefined, done: false}
let done = {done: true}
let latestDestinationValue = destination
return {
next: function() {
let nextIncomingOpt = src.next()
if (nextIncomingOpt.done) {
return done
@kybernetikos
kybernetikos / keybase.md
Created August 4, 2016 14:56
keybase.md

Keybase proof

I hereby claim:

  • I am kybernetikos on github.
  • I am kybernetikos (https://keybase.io/kybernetikos) on keybase.
  • I have a public key whose fingerprint is 4D54 659A DBC4 D807 220C 03E4 7DD3 2D18 A8D8 2630

To claim this, I am signing this object:

@kybernetikos
kybernetikos / readme.md
Last active March 25, 2017 20:24
Receivers and Receiver Transformers

Transducers Primer

function reducerFn(output, value) {
	// reducer functions know how to build a structure when repeatedly given
	// that structure and values (think of it as 'builder')
	return output
}
function reduceFn(collection, reducerFn, output) {