Skip to content

Instantly share code, notes, and snippets.

View lelandrichardson's full-sized avatar

Leland Richardson lelandrichardson

View GitHub Profile
@lelandrichardson
lelandrichardson / MyComponent.js
Last active August 29, 2015 14:20
Idea / Proof of concept for React Native component scaffolding
View MyComponent.js
var React = require('react-native');
var {
StyleSheet,
ListView,
ActivityIndicatorIOS,
Image,
// ...
} = React;
var {
Text,
View Ferrisel.js
var Ferrisel = React.createClass({
getInitialState() {
return {
panX: new Animated.Value(0),
panY: new Animated.Value(0)
};
},
render() {
var { pages } = this.props;
var { panX, panY } = this.state;
@lelandrichardson
lelandrichardson / InlineCssModule
Created September 28, 2012 05:36
Quick HttpModule to inline CSS stylesheets using PreMailer.Net
View InlineCssModule
using System;
using System.IO;
using System.Web;
/// <summary>
/// Removes CSS from rendered HTML page.
/// </summary>
public class InlineCssModule : IHttpModule
{
@lelandrichardson
lelandrichardson / User.jsx
Last active October 30, 2015 04:15
Thoughts for an API for better shape validators
View User.jsx
import UserShape from '../shapes/UserShape';
import UserCard from './UserCard';
import UserBadge from './UserBadge';
export default class User extends React.Component {
static defaultProps = {
user: UserShape.requires(`
first_name,
last_name,
`) // the needs of *this* component
@lelandrichardson
lelandrichardson / ko-convenience.js
Created March 5, 2014 01:11
Knockout.js Custom Utility Bindings
View ko-convenience.js
(function (ko, handlers, unwrap, extend) {
"use strict";
extend(handlers, {
href: {
update: function (element, valueAccessor) {
handlers.attr.update(element, function () {
return { href: valueAccessor() };
});
}
},
View ReactComponentPropType.js
function ReactComponentPropType(props, propName, componentName, ...rest) {
const Component = props[propName];
if (Component === undefined) return null;
if (typeof Component === 'function' && Component.prototype.isReactComponent) {
// it's a real react component
return null;
} else {
return new Error(`${componentName}.${propName} is expected to be a React component.`);
}
}
View bridgeDebugger.js
// This file allows us to inspect the traffic going over the Native <-> JS bridge, and can be
// helpful for debugging. Setting this to true should never be committed to git
const ENABLE_BRIDGE_DEBUGGER = false; // <-- THIS SHOULD NOT BE TRUE IN MASTER!!!!
// if true, function arguments will get pretty printed
const PRETTY_PRINT = false;
// enable this if you want to ignore EVERY event, except for the ones that match the `FOCUSED_*`
// constants. If true, you configure what you want to see. If false, you configure what you DONT
// want to see.
View i18n-tag.js
function t(strings, ...values) {
const string = strings.reduce((s, next, i) => `${s}%{${i}}${next}`);
return new IntlMessageFormat(string, 'en-us').format(values);
}
const person = 'Mike';
const age = 28;
console.log(t`${person} is age ${age}`);
View find-rn-imports.js
const walk = require('babylon-walk');
const babylon = require('babylon');
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const zip = (a, b, fn) => a.forEach((el, i) => fn(el, b[i], i));
const promisify = fn => new Promise((res, rej) => {
const done = (err, val) => (err ? rej(err) : res(val));
@lelandrichardson
lelandrichardson / eachAsync.js
Created March 13, 2015 15:17
Asynchronous Serial iteration
View eachAsync.js
function eachAsync(iter, list, delay) {
var i = 0,
stopped = false,
fwhenDone;
delay = delay || 0;
function run() {
iter(list[i], done);
}
function hold() {