Skip to content

Instantly share code, notes, and snippets.

import typeof {Foo} from './foo'
class Bar extends Component {
props: {
foolike: Foo
}
render (){....}
}
@nsfmc
nsfmc / .babelrc
Last active July 22, 2016 17:02
`unstable_handleError` and `ReactDOMServer.renderToString` test case
{
"presets": ["es2015", "react"]
}
@nsfmc
nsfmc / convert-from-markdown.js
Last active July 8, 2016 18:10
a barely working node module that uses markdown-it (and lodash) to build draft content states
import MarkdownIt from 'markdown-it';
import {convertFromRaw} from 'draft-js';
import util from 'util';
import _ from 'lodash';
const flog = (whatever) => {
console.log(util.inspect(whatever, {depth: null, colors: true}));
};
@nsfmc
nsfmc / require-default-codeshift.js
Created February 24, 2016 17:12
change .default-less require calls for certain modules to require().default
/**
* add .default to requires for 'stores/index' that don't already have them.
*
* this comes up because babel6 Does The Right Thing with es6 exports and
* commonjs requires now need to play by the rules of the es6 exported modules
* and specify the default argument. see more:
* https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.tjlvbfd4x
*
*/
export default function transformer(file, api) {
@nsfmc
nsfmc / jsx-require-codeshift.js
Last active February 24, 2016 03:25
change jsx requires to require extension-less version
/**
* jsx-require-codeshift changes all import/require calls for .jsx files to their root files
*
* this is not a very complicated jscodeshift transform, but the more the merrier imo, since there
* aren't very many out there to peek at. (it could probably be satisfied with a not-crazy regex).
*
* What this does is converts calls like `import Foo from 'foo.jsx';` to `import Foo from 'foo';`
* and similarly, it also converts require calls for jsx files to their extensionless versions.
*
*/
@nsfmc
nsfmc / main.js
Last active January 26, 2016 22:53
A bad idea
var Nest = (classlist) => {
// classlist = 'foo bar baz'
let classes = classlist.split(' ');
classes.reverse();
let nestReducer = (prev, current) => <div className={current}>{prev}</div>;
return (el) => (props) => classes.reduce(nestReducer, el)
}
var Hello = React.createClass({
Verifying that +nsfmc is my blockchain ID. https://onename.com/nsfmc
@nsfmc
nsfmc / force.jsx
Last active October 13, 2015 02:07
force sketch components
import React, {Component} from 'react'
export default class Force extends Component {
componentDidMount () {
this.refs.parent.addEventListener('webkitmouseforcewillbegin',
this.handleForceWillBegin.bind(this))
this.refs.parent.addEventListener('webkitmouseforcedown',
this.handleForceDown.bind(this))
this.refs.parent.addEventListener('webkitmouseforceup',
this.handleForceUp.bind(this))
@nsfmc
nsfmc / dice.py
Last active August 29, 2015 04:18
get some diceware numbers
import argparse
import random
def dicenumber():
"""return a 5-digit number suitable for diceware
the 5-digit integer contains only the digits 1-6
"""
return int(''.join([str(random.randrange(1, 7)) for x in range(5)]))
@nsfmc
nsfmc / thumbgen.py
Created July 3, 2015 00:56
extract n equally spaced frames from a video file
import argparse
import av # pip install av
import os.path
import subprocess
def popen_results(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
return proc.communicate()[0]