Skip to content

Instantly share code, notes, and snippets.

@staydecent
staydecent / stapes_react.js
Created February 12, 2014 19:45
Re-render React component on stapes module change event
var Module = Stapes.subclass();
var mod = new Module();
function initRender() {
// MyApp would be some Reacy component you've defined
React.renderComponent(<MyApp mod={mod} />, node);
}
// ready is a custom event to trigger initRender
// from the Module contructor
@staydecent
staydecent / background.js
Last active August 29, 2015 14:00
Command Tabs Opera Extension
// on proper key press
chrome.runtime.onMessage.addListener(function(request, sender) {
if (!request.tabIndex) { return; }
var tabIndex = request.tabIndex;
chrome.tabs.query({currentWindow: true, index: tabIndex}, function(tab) {
if (!tab.length) { return; }
chrome.tabs.update(tab[0].id, {active: true});
@staydecent
staydecent / dispatcher.js
Created August 19, 2014 03:37
Dispatcher / Synchronous Events
/**
* Dispatcher
*
* Requires: <script src="http://d3js.org/queue.v1.min.js"></script>
*/
var Dispatcher = function() {
this._q = queue(1);
this._events = {};
this._E = function(message) {
this.message = message;
@staydecent
staydecent / generate_keys.py
Created October 5, 2014 19:05
Generate secret keys for Flask app
#!/usr/bin/env python
# encoding: utf-8
"""
generate_keys.py
Generate CSRF and Session keys, output to secret_keys.py file
Usage:
generate_keys.py [-f]
var width = 460,
height = 300,
radius = Math.min(width, height) / 2,
twoPi = 2 * Math.PI,
progress = 0,
formatPercent = d3.format(".0%");
var arc = d3.svg.arc()
.startAngle(0)
@staydecent
staydecent / todo.ls
Last active August 29, 2015 14:07
LiveScript, mercury proof attempting to mimic Elm TodoMVC example.
document = require 'global/document'
nextTick = require 'next-tick'
HashRouter = require 'hash-router'
Event = require 'geval'
cuid = require 'cuid'
extend = require 'xtend'
hg = require 'mercury'
h = hg.h
@staydecent
staydecent / autocompleter.jsx
Last active August 29, 2015 14:15
Mithril autocompleter
/** @jsx m */
'use strict';
var R = require('ramda');
var m = require('mithril');
var autocompleter = function() {
var autocompleter = {};
@staydecent
staydecent / boiled-down-vdom.js
Created March 14, 2015 04:30
proof of minimal DOM updates based on a strict atom/state rather than output of vdom functions.
var atom = {"things": []};
function Thing() {
this.isNew = true;
}
function thingView(thing) {
var cls = ['thing'];
cls.push(thing.isNew ? 'new' : 'notNew');
@staydecent
staydecent / index.js
Created June 10, 2015 01:01
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var deku = require('deku');
var dom = deku.element;
var render = deku.render;
var tree = deku.tree;
var App = {
@staydecent
staydecent / autocompltr.js
Created July 31, 2015 22:07
Native DOM AutoCompleter
function AutoCompltr(wrapper, suggestions, inputProps, cb, oninput) {
this.wrapperNode = wrapper;
this.suggestionsList = [];
this.suggestionNodes = [];
this.pointer = -1;
this.callback = cb;
this.suggestionsNode = document.createElement('ul');
this.inputNode = document.createElement('input');
if (suggestions && suggestions.length) {