Skip to content

Instantly share code, notes, and snippets.

@calvinfroedge
calvinfroedge / gist:5a59fc347d18c124139f884d532b6d58
Created April 21, 2016 13:21
Example reducer with redux-modifiers
import { handleActions } from 'redux-actions'
import { INVOICE } from '../constants'
import { INVOICE_JSON } from '../data'
import { array, target, update } from 'redux-modifiers'
let obj = {};
let { ADD, UPDATE, REMOVE, RECIPIENT_ADD, ITEM_REMOVE, ITEM_ADD } = INVOICE;
let pl = (value)=>{
@calvinfroedge
calvinfroedge / redux-helpers.js
Created March 26, 2016 01:42
Shorter function for 'connect' from 'react-redux'
import { connect } from 'react-redux'
const stateConnector = function(){
let stateKeys = Array.from(arguments);
let obj={};
return connect((state)=>{
stateKeys.forEach((key)=>{
obj[key] = state[key];
});
@calvinfroedge
calvinfroedge / example.js
Created March 24, 2016 15:50
Use react-docgen to automatically add json to a README.md
#!/usr/bin/env node
var sync = require('child_process').spawnSync;
var fs = require('fs');
var START = '<!--(auto-->';
var END = '<!--/auto)-->';
function makeSection(file, title){
var json = JSON.parse(sync('./node_modules/react-docgen/bin/react-docgen.js', ['--pretty', './'+file]).output[1].toString());
var str = "## "+title+"\n\n";

#render me?

@calvinfroedge
calvinfroedge / threads-futures.py
Last active October 2, 2015 19:08
Threads + Futures in Python
'''
Pros:
- Get the spawned thread (use thread.join() to wait on it, for example)
- Get the future
- Calling worker.future.result() will automatically raise an exception in the main thread
'''
from concurrent.futures import Future
import threading
import time
@calvinfroedge
calvinfroedge / gist:fad60de2e90371684d45
Last active September 10, 2015 13:21
SVG masks / clipping
<!--<img class="svg-clipped" src="http://sarasoueidan.com/demos/css-svg-clipping/html-img-clipped-with-css-svg-clippath/flowers.jpg" style=""/>-->
<svg height="100" width="100">
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="100" height="100">
<image xlink:href="http://sarasoueidan.com/demos/css-svg-clipping/html-img-clipped-with-css-svg-clippath/flowers.jpg" x="0" y="0" width="100" height="100" />
</pattern>
</defs>
<path fill="url(#img1)" stroke="#000000" stroke-width="0" stroke-miterlimit="" d="M 74.3243675,137.7170575 C 70.8806075,133.8579775 62.2817,126.3346375 55.2156925,120.99853 C 34.2796675,105.18807 31.43027,102.899975 22.9298095,95.07272 C 7.2586775,80.6426775 0.6034055,66.145215 0.62621195,46.48781 C 0.63733985,36.8918475 1.2914038,33.1948225 3.9786835,27.538495 C 8.53785825,17.94206675 15.253749,10.81116675 23.840013,6.44986425 C 29.9213625,3.36091875 32.920675,1.98855115 43.07612,1.9324059 C 53.6994425,1.8736974 55.9357775,3.11233675 62.1847975,6.54536475 C 6
var listchooser = function(choices, opts){
var opts = opts || {};
opts.transforms = opts.transforms || {};
opts.events = opts.events || {};
var container = $('<div></div>');
if(opts.transforms.container){
opts.transforms.container(container);
}
@calvinfroedge
calvinfroedge / gist:ca1168a3416a60d363e8
Last active August 29, 2015 14:25
Math parser in Python
'''
"operator":[precedence, associativity]
'''
operators = {
"#":[5, "r", lambda x:x*-1], #unary minux
"^":[4, "r", lambda x,y: pow(x, y)],
"*":[3, "l", lambda x,y: x*y],
"/":[3, "l", lambda x,y: x/y],
"+":[2, "l", lambda x,y: x+y],
"-":[2, "l", lambda x,y: x-y]
var quizStore = require('../dist/quiz').quizStore;
var quizInstance = require('../dist/quiz').quizInstance;
var md5 = require('md5');
var sampleQuiz = function(){
return {
name: 'test',
questions: [
[
'the question',
@calvinfroedge
calvinfroedge / gist:080dfba68519bc926124
Created June 5, 2015 14:22
Altered node-redis client, supports auto encryption, json, expiry, completely compatible with connect-redis
'use strict'
#deps
redis = require('redis')
cryptoService = require('../lib/crypto')
module.change_code = 1
'''
Possible options:
expiry: number of seconds till key is deleted from cache