Skip to content

Instantly share code, notes, and snippets.

View jaredpalmer's full-sized avatar

Jared Palmer jaredpalmer

View GitHub Profile
@jaredpalmer
jaredpalmer / form.js
Last active August 29, 2015 14:12 — forked from dhcole/form.js
$(function(){
var formUrl = '/* ex: https://docs.google.com/a/developmentseed.org/spreadsheet/formResponse?formkey=... */';
// Set up map
var m = mapbox.map('map').addLayer(mapbox.layer().id(' /* mapbox-account.id */ '));
// Set up map ui features with point selector
var ui = mapbox.ui().map(m).auto().pointselector(function(d) {
// Remove all points except the most recent
rows = 30
cols = 30
gutter = 16
width = 50
height = 50
for rowIndex in [0..rows-1]
for colIndex in [0..cols-1]
EventEmitter = (require?("./EventEmitter") || Framer).EventEmitter
class AppStateMachine extends EventEmitter
constructor: ->
@states = []
# Start the state machine with the document's hash, or the given route
start: (name) ->
@go if document.location.hash then document.location.hash[1..-1] else name
/** @jsx React.DOM */
'use strict';
var React = require('react'),
escapeTextForBrowser = require('react/lib/escapeTextForBrowser'),
{ PropTypes } = React;
var UncontrolledContentEditable = React.createClass({
propTypes: {
component: PropTypes.func,
@jaredpalmer
jaredpalmer / app.js
Created March 24, 2016 17:56 — forked from kevinSuttle/app.js
Gulp, BrowserSync, Sass, Autoprefixer, Nodemon
var express = require('express');
var app = express();
var router = express.Router();
var hbs = require('hbs');
app.set('view engine', 'html');
app.engine('html', hbs.__express);
app.use(express.json());
app.use(express.urlencoded());
@jaredpalmer
jaredpalmer / index.js
Created April 8, 2016 16:40 — forked from netsensei/index.js
Using the Promise library + Fast-CSV to read/write CSV files
var promiseCSV = require('promiseCSV.js');
var path = "in.csv";
var options = { 'headers': true };
promiseCSV(path, options).then(function (records) {
// do other stuff
});
@jaredpalmer
jaredpalmer / advanced.md
Created June 15, 2016 13:00 — forked from koenbok/advanced.md
Learn Programming

Advanced Programming

Programming setup

  • Instant visual output.
  • Fast startup time, fast execution.
  • Sensible errors, with code locations.
  • Easy to set up and get working.

Architecture

@jaredpalmer
jaredpalmer / InfiniteScroll.js
Created March 2, 2017 20:19 — forked from lelandrichardson/InfiniteScroll.js
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,
@jaredpalmer
jaredpalmer / prefetch.js
Created October 19, 2017 14:27 — forked from acdlite/prefetch.js
Prefetching in React
function prefetch(getKey, getValue, getInitialValue, propName) {
const inFlight = new Set();
const cache = new Map();
return ChildComponent => {
return class extends React.Component {
state = {value: getInitialValue(this.props)};
componentWillReceiveProps(nextProps) {
const key = getKey(nextProps);
if (cache.has(key)) {
// Use cached value
if (typeof window!=='undefined' && navigator.serviceWorker && navigator.serviceWorker.controller) {
let reloadOnNext = false;
let pushState = history.pushState;
history.pushState = function(state, title, url) {
pushState.call(this, state, title, url);
if (reloadOnNext===true) location.reload(true);
};
navigator.serviceWorker.controller.addEventListener('statechange', e => {