Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Ferraiuolo ericf

View GitHub Profile
@ericf
ericf / timeago.js
Created Nov 11, 2015
<TimeAgo> with React Intl v2
View timeago.js
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'});
View messages.js
/*
* 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 Aug 29, 2015
CSP + SPDY Push
View CSP + SPDY Push.md

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.

View gist:9255584
<!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">
View gist:8445982
'use strict';
var serialize = require('./serialize');
module.exports = Exposed;
function Exposed() {
Object.defineProperties(this, {
// Brand with constructor.
'@exposed': {value: Exposed},
View gist:8445732
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);
});
}
View gist:8444769
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";
View gist:8443907
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()
View utils.js
'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) {
View gist:8026041
'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)
You can’t perform that action at this time.