Skip to content

Instantly share code, notes, and snippets.

@threepointone
threepointone / ionode.diff
Created January 20, 2015 20:55
io.js compatibility
diff --git a/src/clj/cljs/repl/node_repl.js b/src/clj/cljs/repl/node_repl.js
index 6bc1cd2..46e7f7e 100644
--- a/src/clj/cljs/repl/node_repl.js
+++ b/src/clj/cljs/repl/node_repl.js
@@ -1,6 +1,7 @@
process.env.NODE_DISABLE_COLORS = true;
-var net = require("net");
+var net = require("net"),
+ vm = require('vm');
@threepointone
threepointone / csp.js
Last active February 25, 2017 16:15
parallel / series requests with js-csp
var csp = require('js-csp'),
{ chan, putAsync, take, go, put, timeout, spawn} = csp,
request = require('superagent');
var urls = ['http://www.google.com', 'http://www.jlongster.com', 'http://www.myntra.com'];
go(function*(){
// 1. do a bunch of requests in parallel, and save their response lengths
var parallel = yield map(urls, function*(url){
return (yield fetch(url)).text.length;
"use strict";
var [BRA, KET, IDENT] = ['BRA', 'KET', 'IDENT'];
function last(arr){ return arr[arr.length -1] };
export default function act(src, prefix){
var tree = src.split('').reduce((tokens, char)=> {
if(char==='{'){
tokens.push({type: BRA});
@threepointone
threepointone / gist:43f16389fd96561a8b0b
Last active February 13, 2023 02:12
sto alternate api
// store.js
let {store, handler} = sto(initialState, reduceFn); // where reduceFn: function(currentState, action, ...args){}
dispatcher.register(handler);
export store;
// elsewhere
store.get() // -> current state
store.toObservable() // -> to be used with .observe()
@threepointone
threepointone / index.js
Last active March 22, 2016 10:17
time travel with disto
import {Dis} from 'disto';
import {photo} from 'disto/record';
let {register, dispatch, lock, unlock} = new Dis();
let store = photo(register({x: 0}, o => ({x: o.x+1}))); // simple increments
store.subscribe(o => console.log(o.x)); // 0
let t1 = store.snapshot();
dispatch('xyz'); // 1
@threepointone
threepointone / async-disto.js
Last active March 22, 2016 10:16
async action creators in disto
/* global fetch*/
import {Dis, act} from 'disto';
let {dispatch, register} = new Dis();
function timeout(t){
return new Promise(resolve =>
setTimeout(()=> resolve(true), t));
}
@threepointone
threepointone / sto.js
Created July 28, 2015 07:12
a lightweight flux style store as a component
import React from 'react';
export class Sto extends React.Component{
static defaultProps = {
store: x => x
}
state = {
value: this.props.store()
}
dispatch = action => this.setState({
@threepointone
threepointone / rethinkdb-caches.md
Last active October 22, 2022 15:49
better caches with rethinkdb

better caches with rethinkdb

TL;DR - smelly software engineer discusses using rethinkdb changefeeds for building caches, breaks hearts, shaves the cheerleader, shaves the world.

Let's talk about caches.

Imagine that you build UIs for an ecommerce company, possibly in a fancy office with free coffee and whatnot. You've just been asked to build a way for the marketing / sales folks to change landing pages whenever they're running campaigns. After a number of angry discussions involving the ux team about what they can and cannot change, you settle on a 'document' format for these pages. It could be json describing a tree of widgets of banners and carousels, or html, or yaml, or whatever. Maybe you also invent a dsl that marks out parts of the document as dynamic, based on request parameters or something. I dunno, I'm not your boss. You build a little ui over the weekend (with react? maybe!) that lets these folks login, drag and drop their banners, maybe upload an image or two, and save to database.

Yo

@threepointone
threepointone / saga.js
Last active September 24, 2016 18:50
import React, {Component} from 'react';
import {render} from 'react-dom';
import {take, put, fork, join, cps, call, cancel, race, runSaga, SagaCancellationException} from 'redux-saga';
const styles = {
app: {
position: 'absolute',
width: 200,
height: 200,
backgroundColor: 'red',
@threepointone
threepointone / ensure-fsa-optimist.js
Created February 15, 2016 20:03
middleware that ensures actions have flux-standard-action shape, but also allows an `optimist` key
// like https://github.com/meadow/redux-ensure-fsa, but allows `optimist` as a key
import isPlainObject from 'lodash.isplainobject';
const validKeys = [
'type',
'payload',
'error',
'meta',
'optimist'