Skip to content

Instantly share code, notes, and snippets.

@kolodny
kolodny / gist:7989963
Created December 16, 2013 16:33
Create a client side download.
jQuery.download = function(data, filename) {
$('<a>').prop({
download: filename || '',
href: 'data:Application/octet-stream,' + encodeURIComponent(data)
})[0].click();
};
@kolodny
kolodny / gist:7990638
Created December 16, 2013 17:17
Query String Split
console.log(location.search
.substr(1)
.split('&')
.map(function(a) {
return a.split('=');
})
.reduce(function(a,b) {
var arrayProps = /^(.*)\[(\w*)\]$/.exec(b[0]);
if (arrayProps) {
(a[arrayProps[1]] || (a[arrayProps[1]] = []));
@kolodny
kolodny / JSON-patch.js
Last active February 16, 2018 20:37
Add circular reference support to javascript's JSON implementation. Based off of https://github.com/douglascrockford/JSON-js/blob/master/cycle.js
;(function(JSON) {
var oldStringify = JSON.stringify;
var oldParse = JSON.parse;
if (JSON.circular) { return; }
JSON.stringify = function(value, replacer, space, circular) {
if (circular) {
return oldStringify.call(this, decycle(value), replacer, space);
} else {
return oldStringify.apply(this, arguments);
}
@kolodny
kolodny / couch25k
Created December 29, 2013 03:54
Something I threw together to watch a youtube vid on the treadmill while doing the program
var messages = [
{
html: 'Warmup walking',
seconds: 60 * 5
}
];
var total = messages[0].seconds;
function addItem(html, seconds) {
messages.push({html:html, seconds: seconds});
+ BRANCH_TO_CHECKOUT='__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
+ echo BRANCH_TO_CHECKOUT = '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
BRANCH_TO_CHECKOUT = __sync__0b3465aa338b5fdadc1b67eef7a079e53881de76
+ '[' '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76' == '' ']'
+ echo we need to checkout '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
we need to checkout __sync__0b3465aa338b5fdadc1b67eef7a079e53881de76
+ git fetch
+ git checkout '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
error: pathspec '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76' did not match
any file(s) known to git.
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@kolodny
kolodny / run.js
Last active August 29, 2015 14:03
Simple koa like function
function run(gen) {
step();
function step(value) {
var result = gen.next(value);
if (result.value instanceof Promise) {
result.value.then(step);
} else if (result.value instanceof Array) {
Promise.all(result.value).then(step);

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

#!/usr/bin/env bash
if [ "$2,$3" == "message," ]
then
new_msg=$(echo -n "$(git rev-parse --abbrev-ref HEAD): " | cat - $1)
echo $new_msg > $1
fi
@kolodny
kolodny / list.md
Last active August 29, 2015 14:05