Skip to content

Instantly share code, notes, and snippets.

View nicolashery's full-sized avatar

Nicolas Hery nicolashery

View GitHub Profile
@nicolashery
nicolashery / keybase.md
Created April 17, 2015 16:09
Keybase proof

Keybase proof

I hereby claim:

  • I am nicolashery on github.
  • I am nicolashery (https://keybase.io/nicolashery) on keybase.
  • I have a public key whose fingerprint is 852A E7B2 14A7 7B4A 4A49 27D3 FA69 6E9C F40A DF41

To claim this, I am signing this object:

@nicolashery
nicolashery / 01-simplest.jsx
Last active November 18, 2015 09:26
Snippets for blog post on isomorphic React + Flux
// - rendering library (like React) should be able to "pick up" where server
// left off (i.e. hook up to the existing HTML)
// server.js
var server = express();
server.use(function(req, res) {
var appHtml = React.renderToString(<App />);
var html = injectIntoHtml({app: appHtml});
res.send(html);
// Exploring using "expose React component tree as data" @swannodette
// (https://www.youtube.com/watch?v=5hGHdETNteE#t=1559)
// for routing and fetching data ("react-router-mega-demo" @ryanflorence)
// (https://github.com/rackt/react-router-mega-demo/blob/master/app/utils/fetchData.js)
var appState = {
route: '/contacts',
contacts: [],
messages: []
};
@nicolashery
nicolashery / typed-event-driven.ts
Last active August 29, 2015 14:14
Sketchpad: Event-driven design in TypeScript
// Playing around with TypeScript
// Inspiration: https://github.com/abdullin/omni
// core.event
interface DomainEventType {
name: string;
}
interface DomainEvent {
_type: DomainEventType;
@nicolashery
nicolashery / gulpfile-react-jshint.js
Created October 20, 2014 17:06
Gulpfile for JSHint on a React app with watch, JSX error logging, and cache
var gulp = require('gulp');
var react = require('gulp-react');
var jshint = require('gulp-jshint');
var cache = require('gulp-cached');
var jsFiles = [
'src/**/*.js',
'test/**/*.js',
'*.js'
];
@nicolashery
nicolashery / divshot-webpack.md
Created September 25, 2014 16:42
Using env variables with Webpack and Divshot

Using env variables with Webpack and Divshot

This shows a way to have "environment variables" working for both the webpack-dev-server (local development) and the Divshot server (to test a build locally).

Problem:

  • Divshot server expects a .env.json file in the project directory, and uses it to serve a __/env.js file
  • Webpack dev server can serve static files from the project directory, but we need to create the __/env.js file ourselves

A solution:

var merge = require('react/lib/merge');
var m = require('mori');
var toArray = function (val) {
if (!Array.isArray(val)) {
val = [val];
}
return val;
};
@nicolashery
nicolashery / throttle.js
Last active August 29, 2015 14:06
Throttle a channel in js-csp
// https://github.com/jlongster/js-csp
// Throttle ported from:
// https://gist.github.com/swannodette/5886048
var csp = require('js-csp');
var chan = csp.chan;
var go = csp.go;
var put = csp.put;
var take = csp.take;
var timeout = csp.timeout;
@nicolashery
nicolashery / README.md
Last active August 29, 2015 14:06
(deprecated) Throttling key presses in JavaScript CSP
@nicolashery
nicolashery / Makefile
Created March 21, 2014 11:17
Building UMD modules with dependencies with Browserify
dist:
browserify \
--external lodash \
--external moment \
--require ./index.js:robot \
> bundle.js
cat umd-head.js bundle.js umd-tail.js > robot.js