Skip to content

Instantly share code, notes, and snippets.

View penguin_heroku_start.sh
#!/bin/bash
if [[ $NODE_ENV != production ]]; then
echo 'start: This is intended for production, use `npm run serve` instead'
exit 1
fi
test -f .env && source .env
penguin run \
--port "${PORT=3000}" \
--database-driver [ penguin.js/pg --url "$DATABASE_URL" ] \
View router.js
const routes = [
{ path: '/api/v1/websites/:website', method: 'GET', service: getWebsite },
{ path: '/api/v1/websites/:website', method: 'POST', service: createWebsite }
]
const notFound = (req, res) => res.end('Not found')
const api = proxyHandler(routes, { fallback: notFound })
http.createServer(api).listen(3000)
@domachine
domachine / service.js
Created May 30, 2016
webdesignio Secure rendering of components on the server side
View service.js
'use strict'
const fs = require('fs')
const vm = require('vm')
const cluster = require('cluster')
const shortid = require('shortid')
if (cluster.isMaster) {
// Act as master
cluster.on('online', worker => {
@domachine
domachine / build.sh
Created May 30, 2016
webdesignio Component building
View build.sh
#!/bin/bash
for component in src/components/*; do
echo $component
browserify \
--extension .jsx \
-t babelify \
-t rollupify \
-s $(basename $(basename $component .js) .jsx) \
-o components/$(basename $(basename $component .js) .jsx).js \
View pure-list-items-react.jsx
class Todos extends Component {
constructor() {
super();
this.state.todos = [{ name: 'Foo' }, { name: 'Bar' }];
}
onChange(todo, name) {
this.setState({
todos: this.state.todos.map(
(t, i) => i === todo ? { name } : t
View run_io_example.js
'use strict';
const io = require('run-io');
function performingIO(done) {
console.log('Heay IO ...');
setTimeout(() => done(42), 1000);
}
function *myGenerator() {
View io_generator_test.js
function *myGenerator() {
const a = yield { fn: performingIO };
return a;
}
const it = myGenerator();
assert.deepEqual(it.next(), { value: { fn: performingIO }, done: false });
assert.deepEqual(it.next(34), { value: 34, done: true });
View io_generator_example.js
function performingIO(done) {
console.log('Heay IO ...');
setTimeout(() => done(42), 1000);
}
function *myGenerator() {
const a = yield { fn: performingIO };
return a;
}
View generator_example.js
function *myGenerator() {
const a = yield 2;
return a;
}
const it = myGenerator();
it.next(); // => { value: 2, done: false }
it.next('hello') // => { value: 'hello', done: true }
@domachine
domachine / flow_io.js
Last active Feb 2, 2016
Side-effect-free side effects
View flow_io.js
'use strict';
const assert = require('assert');
// Simple goal is to push out side-effects for testability
function liftMethod(ctx, method, opts) {
return lift(ctx[method], Object.assign({ ctx }, opts || {}));
}
function lift(fn, opts) {