Skip to content

Instantly share code, notes, and snippets.

View jasonrhodes's full-sized avatar

Jason Rhodes jasonrhodes

View GitHub Profile
<ul>
{ordinances.map((o) => <Ordinance ordinance={o} key={o.ReferenceNo} />)}
</ul>
@jasonrhodes
jasonrhodes / dont-use-var.js
Last active October 26, 2017 16:09
Looking at using let and const vs using var, semantically
function getNameWithLetAndConst(options) {
// `name` scoped to its nearest parent block (here: the function-block)
let name = 'Jill'
if (options.test) {
// `combined` is scoped to its nearest parent block (here: the if-block)
// because of how block-scoping works, `name` is also available here
const combined = `${name}-tested`
if (options.someCondition) {
@jasonrhodes
jasonrhodes / ChainingAsync.js
Last active October 13, 2017 02:57
the trouble with redux async chaining
class ChainingAsync extends React.Component {
componentWillReceiveProps(newProps) {
// handle changes in connected props to do things
// like show alerts, redirect, etc.
}
updateThings(values) {
this.props.updateSequence(values)
// ^^ HERE, ASSUME updateThing1 FAILED...
export class ProtectedRoute extends Component {
render() {
const { component: Component, auth, access, ...rest } = this.props;
return (
<Route {...rest} render={(props) => (
auth.loggedIn ? (
access(state) ? <div><Component {...props} /></div> : <Something>
) : (
<Redirect to={{
pathname: '/auth',
@jasonrhodes
jasonrhodes / factory.js
Created September 16, 2017 19:43
import/export makes testing hard
// actions/helpers/factory.js
export default function ({ request, onSuccess }) {
return (action) => (dispatch) => {
return request().then((results) => onSuccess({ results, dispatch }));
}
}
@jasonrhodes
jasonrhodes / .env.production
Last active April 9, 2017 01:52
Notes I kept while getting my Digital Ocean + Docker + SparkPost Mastodon environment set up
# Service dependencies
REDIS_HOST=redis
REDIS_PORT=6379
DB_HOST=db
DB_USER=postgres
DB_NAME=postgres
DB_PASS=
DB_PORT=5432
# Federation
<?php
class Wrapped {
public function __construct($type) {
$class = $type . 'Banner';
$this->instance = new $class();
}
}
@jasonrhodes
jasonrhodes / allSettled.js
Last active October 14, 2018 17:41
Native promise implementation of something like q.allSettled
const captureSuccess = (result) => ({ state: 'succeeded', result })
const captureFail = (error) => ({ state: 'rejected', error })
module.exports.allSettled = (promises, { only }) => {
const settled = Promise.all(promises.map((p) => p.then(captureSuccess).catch(captureFail)))
return only
? settled.then((results) => results.filter((r) => r.state === only).map((r) => r.result))
: settled
}
@jasonrhodes
jasonrhodes / anyfile.js
Created October 15, 2016 13:48
Trying to use a symlink in node_modules alongside npm@3 shrinkwrap
// anywhere we need to require the controller, either in production code or tests:
// const controller = require('../../../lib/controller')
const controller = require('lib/controller')
// etc.
@jasonrhodes
jasonrhodes / dokku-user.sh
Created April 3, 2016 19:00
How to add a dokku ssh user
# from your local machine
# replace dokku.me with your domain name or the host's IP
# replace root with your server's root user
# USER is the username you use to refer to this particular key
cat ~/.ssh/id_rsa.pub | ssh root@dokku.me "sudo sshcommand acl-add dokku USER"