Skip to content

Instantly share code, notes, and snippets.

#!/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" ] \
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 15:21
webdesignio Secure rendering of components on the server side
'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 15:08
webdesignio Component building
#!/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 \
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
'use strict';
const io = require('run-io');
function performingIO(done) {
console.log('Heay IO ...');
setTimeout(() => done(42), 1000);
}
function *myGenerator() {
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 });
function performingIO(done) {
console.log('Heay IO ...');
setTimeout(() => done(42), 1000);
}
function *myGenerator() {
const a = yield { fn: performingIO };
return a;
}
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 February 2, 2016 09:46
Side-effect-free side effects
'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) {