Skip to content

Instantly share code, notes, and snippets.

View ericf's full-sized avatar

Eric Ferraiuolo ericf

View GitHub Profile
import time
class Bucket(object):
def __init__(self, max_amount, refill_time, refill_amount):
self.max_amount = max_amount
self.refill_time = refill_time
self.refill_amount = refill_amount
self.reset()
def _refill_count(self):
const INCREMENT = 'INCREMENT', DECREMENT = 'DECREMENT';
function reducer(state, action) {
switch (action.type) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
}
}
@summerwind
summerwind / moz_first_paint.js
Last active April 27, 2016 05:27
FirstPaintTime for Firefox
var firstPaint = 0, firstPaintTime, paint;
function paintHandler() {
paint = window.performance.now()
if (firstPaint === 0) {
firstPaint = paint;
firstPaintTime = firstPaint + window.performance.timing.navigationStart;
window.performance.timing.firstPaint = firstPaint;
window.performance.timing.firstPaintTime = firstPaintTime;
}
};
@gaearon
gaearon / combining.js
Created June 3, 2015 18:03
Combining Stateless Stores
// ------------
// counterStore.js
// ------------
import {
INCREMENT_COUNTER,
DECREMENT_COUNTER
} from '../constants/ActionTypes';
const initialState = { counter: 0 };
@jlongster
jlongster / forms-with-react.js
Last active May 8, 2017 14:15
higher-order form components w/react
// Simple wrapper to use bootstrap's grid system to position elements side-by-side
var VerticalFieldsElement = React.createClass({
render: function() {
return dom.div(
{ className: 'clearfix' },
React.Children.map(this.props.children, function(child) {
if(!child) {
return child;
}
@steveluscher
steveluscher / gist:4b54e08aa1e0536b7cb9
Last active April 30, 2021 21:28
Proposed abbreviation API for Intl.NumberFormat

Intl.NumberFormat

Syntax

new Intl.NumberFormat([locales[, options]])
Intl.NumberFormat.call(this[, locales[, options]])

Parameters

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

"use strict";
var _ = SM.import('lodash');
var DOM = SM.import('sm-dom');
var Uri = SM.import('sm-uri');
// WebKit (as of version 538.35.8) fires a useless popstate event after every
// page load, even when the page wasn't popped off the HTML5 history stack. We
// only want to handle popstate events that result from a page actually being
// popped off the HTML5 history stack, so we need a way to differentiate between
@caridy
caridy / export-syntax.js
Last active January 15, 2022 14:22
ES6 Module Syntax Table
// default exports
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class foo {}
@ericf
ericf / CSP + SPDY Push.md
Last active August 29, 2015 14:05
CSP + SPDY Push

SPDY Push for Externalizing Dynamic Inline Scripts for CSP

This is a rough outline of some thoughts on how to leverage [SPDY Push][SPDY] externalize inline <script>s that contain dynamic, page/user-specific configuration and state data to align with [CSP][].

Problem

We are building web apps where the initial rendering (HTML) is built server-side, and in order for the client-side JavaScript app to take over, the app's configuration and initial state are written to an inline <script> element.