Skip to content

Instantly share code, notes, and snippets.

View mjackson's full-sized avatar
💿

Michael Jackson mjackson

💿
View GitHub Profile
@mjackson
mjackson / app.js
Created December 29, 2015 05:07
Using webpack with pixi.js
var PIXI = require('pixi.js')
console.log(PIXI)
var JSONStream = require('jsonstream')
var es = require('event-stream')
function handleRequest(data, callback) {
callback(null, JSON.stringify(data) + '\n')
}
process.stdin
.pipe(JSONStream.parse())
.pipe(es.map(handleRequest))
@mjackson
mjackson / WindowScrollTo.js
Last active January 16, 2017 02:11
Make window.scrollTo declarative using a <WindowScrollTo> React component
import React from 'react'
import warning from 'warning'
const { number, object } = React.PropTypes
const WindowScrollTo = React.createClass({
contextTypes: {
windowScrollTo: object
},
@mjackson
mjackson / fetchJSON.js
Created February 23, 2016 22:23
fetch JSON with a callback
function fetchJSON(url, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
const headers = (options.headers || (options.headers = {}))
headers.Accept = 'application/json'
@mjackson
mjackson / babel+webpack.js
Last active March 2, 2016 16:22
Crazy babel+webpack bug.
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["HTTPClient"] = factory();
else
root["HTTPClient"] = factory();
})(this, function() {
<div className="pricing" style={{ opacity: purchasing ? 0.25 : '' }}>
{purchaseComplete ? (
<div className="purchase-complete">
<h2>Thanks!</h2>
<p>
Thank you for your purchase of {formatPrice(this.state.total)}.
We’ll send you a receipt shortly.
</p>
<p>
<button
@mjackson
mjackson / SVGIcons.js
Last active June 24, 2016 13:08
Building reusable SVG icons w React
import React from 'react'
// So, this is awesome. And it's the approach I took in my own site.
// Nothing wrong with it!
const IconUmbrella = React.createClass({
render() {
return (
<svg className="umbrella" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" aria-labelledby="umbrella icon">
<title>Umbrella</title>
<path d="M27 14h5c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2v0zM27 14c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2v0 14c0 1.112-0.895 2-2 2-1.112 0-2-0.896-2-2.001v-1.494c0-0.291 0.224-0.505 0.5-0.505 0.268 0 0.5 0.226 0.5 0.505v1.505c0 0.547 0.444 0.991 1 0.991 0.552 0 1-0.451 1-0.991v-14.009c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2c0-1.105-1.119-2-2.5-2s-2.5 0.895-2.5 2c0-5.415 6.671-9.825 15-9.995v-1.506c0-0.283 0.224-0.499 0.5-0.499 0.268 0 0.5 0.224 0.5 0.499v1.506c8.329 0.17 15 4.58 15 9.995h-5z"/>
@mjackson
mjackson / .eslintrc
Last active January 12, 2018 22:28
My personal ESLint config
{
"extends": "airbnb",
"parser": "babel-eslint",
"rules": {
"array-bracket-spacing": [2, "always"],
"comma-dangle": 0,
"consistent-return": 1,
"curly": [1, "multi-or-nest", "consistent"],
"eqeqeq": [2, "smart"],
"max-len": 1,
import throttle from 'lodash/throttle'
import React, { PropTypes } from 'react'
const ThrottledInput = React.createClass({
propTypes: {
delay: PropTypes.number
},
getDefaultProps() {
return {
@mjackson
mjackson / createBinding.js
Last active September 18, 2021 09:19
A workaround for the lack of a promise cancelation API
/**
* Registers the given callback to be called in the node.js callback
* style, with error as the first argument, when the promise resolves.
*
* Also, returns a function that may be used to prevent the callback
* from ever being called. Calling the returned function is synonymous
* with saying "I no longer care about the resolution of this promise,
* even if it fails."
*
* Since there is no provision in the promise spec for cancel/abort