Skip to content

Instantly share code, notes, and snippets.

View ericf's full-sized avatar

Eric Ferraiuolo ericf

View GitHub Profile
@ericf
ericf / timeago.js
Created November 11, 2015 07:14
<TimeAgo> with React Intl v2
import React from 'react';
import {
injectIntl,
FormattedRelative,
} from 'react-intl';
const TimeAgo = ({date, intl}) => {
let year = intl.formatDate(date, {year: 'numeric'});
let month = intl.formatDate(date, {month: '2-digit'});
let day = intl.formatDate(date, {day: '2-digit'});
@ericf
ericf / messages.js
Last active November 9, 2015 18:19
/*
* Copyright 2015, Yahoo Inc.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
import {Component, Children, PropTypes} from 'react';
import {intlShape} from '../types';
import {invariantIntlContext} from '../utils';
@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.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">
</head>
<body>
<div class="pure-g">
'use strict';
var serialize = require('./serialize');
module.exports = Exposed;
function Exposed() {
Object.defineProperties(this, {
// Brand with constructor.
'@exposed': {value: Exposed},
Exposed.prototype._getApplicableNamespaces = function () {
var namespaces = this.__namespaces__.concat(),
proto = Object.getPrototypeOf(this);
function isApplicable(namespace) {
return !namespaces.some(function (ns) {
var nsRegex = new RegExp('^' + ns + '(?:$|\\..+)');
return nsRegex.test(namespace);
});
}
app.expose('foo', 'window.foo');
console.log(res.locals.state); // => window.foo = "foo";
app.expose('bar', 'window.bar');
console.log(res.locals.state); // => window.foo = "foo";
exports
.local
✓ should have a .local property
✓ should be the string "state"
.namespace
✓ should have a .namespace property
✓ should be null
.extend
✓ should have a .extend property
✓ should respond to .extend()
'use strict';
var fs = require('fs'),
path = require('path'),
Promise = require('es6-promise').Promise,
zlib = require('zlib');
var utils = require('../utils');
module.exports = function fileSizes(pureDir, callback) {
'use strict';
var fs = require('fs'),
path = require('path'),
parseCSS = require('css-parse'),
Promise = require('es6-promise').Promise;
module.exports = function gridUnits(pureDir, callback) {
readUnits(path.join(pureDir, 'grids-units.css'))
.then(parseCSS)