View penguin_heroku_start.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
View service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 => { |
View build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function performingIO(done) { | |
console.log('Heay IO ...'); | |
setTimeout(() => done(42), 1000); | |
} | |
function *myGenerator() { | |
const a = yield { fn: performingIO }; | |
return a; | |
} |
View generator_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *myGenerator() { | |
const a = yield 2; | |
return a; | |
} | |
const it = myGenerator(); | |
it.next(); // => { value: 2, done: false } | |
it.next('hello') // => { value: 'hello', done: true } |
View flow_io.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) { |
NewerOlder