Skip to content

Instantly share code, notes, and snippets.

View jaketrent's full-sized avatar
🎹
Coding a power ballad

Jake Trent jaketrent

🎹
Coding a power ballad
View GitHub Profile
@jaketrent
jaketrent / dom.js
Created March 7, 2016 19:35
jsdom with localStorage
import jsdomGlobal from 'jsdom-global'
import jsdom from 'jsdom'
import localStorage from 'localStorage'
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
const win = doc.defaultView
win.localStorage = localStorage
global.document = doc
global.window = win
jsdomGlobal()
@jaketrent
jaketrent / dom.js
Created March 7, 2016 19:35
jsdom with localStorage
import jsdomGlobal from 'jsdom-global'
import jsdom from 'jsdom'
import localStorage from 'localStorage'
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
const win = doc.defaultView
win.localStorage = localStorage
global.document = doc
global.window = win
jsdomGlobal()
@jaketrent
jaketrent / exportsExample.css
Created March 5, 2016 17:59
CSS modules when using exports
:export {
className: 'composedHashedClassName hashedClassName'
}
@jaketrent
jaketrent / areaUnderLineAnimation1.js
Created February 5, 2016 18:21
Animate area under line (line and area separate, animate unsync'ed)
import d3 from 'd3'
import css from './index.css'
const rawData = [{'date':'2016-01-06','hours':2.7},{'date':'2016-01-07','hours':1.735},{'date':'2016-01-08','hours':0.5219},{'date':'2016-01-09','hours':0.0},{'date':'2016-01-10','hours':0.0},{'date':'2016-01-11','hours':2.2708},{'date':'2016-01-12','hours':1.2692},{'date':'2016-01-13','hours':0.2219},{'date':'2016-01-14','hours':3.2722},{'date':'2016-01-15','hours':0.3353},{'date':'2016-01-16','hours':0.5389},{'date':'2016-01-17','hours':0.0},{'date':'2016-01-18','hours':1.3308},{'date':'2016-01-19','hours':2.1228},{'date':'2016-01-20','hours':1.0539},{'date':'2016-01-21','hours':0.0},{'date':'2016-01-22','hours':1.2525},{'date':'2016-01-23','hours':1.8133},{'date':'2016-01-24','hours':1.9583},{'date':'2016-01-25','hours':3.3772},{'date':'2016-01-26','hours':0.9175},{'date':'2016-01-27','hours':0.4208},{'date':'2016-01-28','hours':0.0},{'date':'2016-01-29','hours':1.1847},{'date':'2016-01-30','hours':0.0175},{'date':'2016-01-31','hours':0.49},{'date':'2016-0
@jaketrent
jaketrent / simple-promise-retry.js
Created January 14, 2016 17:36 — forked from briancavalier/simple-promise-retry.js
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);
import mockPromises from 'mock-promises'
// it should something
mockPromises.reset()
Promise = mockPromises.getMockPromise(Promise)
const reqPromise = new Promise((resolve, reject) => {
resolve(res)
})
sinon.stub(fetchCurrentUser, 'request', () => reqPromise)
@jaketrent
jaketrent / es6styleFunctions.js
Last active August 29, 2015 14:22
ES6 function styles -- available via traceur or babel
var fnEs6Style = () => {
return 1
}
var fnNoParens = num => {
return 2
}
var fnImplicitReturnParens = () => 3
@jaketrent
jaketrent / mountUnmount.js
Created May 22, 2015 15:02
Mount/Unmount React Example
import React from 'react'
class Comp {
componentDidMount() {
console.log('Comp - I mounted!')
}
componentWillUnmount() {
console.log('Comp - My time has come')
}
render() {
node - bin to run things
npm - bin to install things
npm init - start new node project
package.json - describing your project; your dependencies
npm install packageName - install things
npmjs.com - all the libs
REST API - noun - resource; verb - action
endpoint GET /books; POST /books
lib - expressjs.com - npm install express
@jaketrent
jaketrent / 1-installAutobindDecorator.sh
Last active August 29, 2015 14:20
Use autobind-decorator with babel on webpack
npm install autobind-decorator --save-dev