Skip to content

Instantly share code, notes, and snippets.

View lelandrichardson's full-sized avatar

Leland Richardson lelandrichardson

View GitHub Profile
@lelandrichardson
lelandrichardson / InlineCssModule
Created September 28, 2012 05:36
Quick HttpModule to inline CSS stylesheets using PreMailer.Net
using System;
using System.IO;
using System.Web;
/// <summary>
/// Removes CSS from rendered HTML page.
/// </summary>
public class InlineCssModule : IHttpModule
{
@lelandrichardson
lelandrichardson / ko-convenience.js
Created March 5, 2014 01:11
Knockout.js Custom Utility Bindings
(function (ko, handlers, unwrap, extend) {
"use strict";
extend(handlers, {
href: {
update: function (element, valueAccessor) {
handlers.attr.update(element, function () {
return { href: valueAccessor() };
});
}
},
@lelandrichardson
lelandrichardson / eachAsync.js
Created March 13, 2015 15:17
Asynchronous Serial iteration
function eachAsync(iter, list, delay) {
var i = 0,
stopped = false,
fwhenDone;
delay = delay || 0;
function run() {
iter(list[i], done);
}
function hold() {
@lelandrichardson
lelandrichardson / MyComponent.js
Last active August 29, 2015 14:20
Idea / Proof of concept for React Native component scaffolding
var React = require('react-native');
var {
StyleSheet,
ListView,
ActivityIndicatorIOS,
Image,
// ...
} = React;
var {
Text,
@lelandrichardson
lelandrichardson / InfiniteScroll.js
Created July 9, 2015 01:02
Super Light Infinite Scroll Component in React
var React = require('react');
var { Component, PropTypes } = React;
var throttle = require('lodash/function/throttle');
class InfiniteScroll extends React.Component {
static propTypes = {
hasMore: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
onLoadMore: PropTypes.func.isRequired,
threshold: PropTypes.number,
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 / operators.js
Last active December 21, 2020 00:15
React Native Animated API: Operators
/*
// All methods would return Animated values.
// All parameters would be either Animated Values or regular Numbers
// Examples:
// =========
Animated.Add(a, b); // a + b
Animated.Subtract(a, b); // a - b
Animated.Mult(a, b); // a * b
Animated.Divide(a, b); // a / b
@lelandrichardson
lelandrichardson / User.jsx
Last active October 30, 2015 04:15
Thoughts for an API for better shape validators
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
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.`);
}
}
// 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.