Skip to content

Instantly share code, notes, and snippets.

View aaronshaf's full-sized avatar

Aaron Shafovaloff aaronshaf

View GitHub Profile
router('/foo', async function(ctx) {
ctx.unsubscribe = await doStuff()
})
router('/foo', async function(ctx) {
ctx.unsubscribeMore = await doMoreStuff()
})
router.after('/foo', async function(ctx) {
await doMoreStuff(ctx)
@aaronshaf
aaronshaf / quote.js
Created October 12, 2015 17:57
annotating a stateless function component in flowtype
/* @flow */
import React from 'react'
type QuoteProps = {
message: string,
quote: string,
name: string,
photoUrl: string,
photoAlt: string
@aaronshaf
aaronshaf / partials.js
Last active August 29, 2015 14:22
Wouldn't partials here be better than virtual methods?
// ES7
getPlayers()
::map(x => x.character())
// ES6
let _val
_val = getPlayers()
_val = map(_val, x => x.character())
// Confused? See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions
function flatten(previous, current) {
return previous.concat(current)
}
var productImages = [
for(section of CatalogSections) [
for(placement of section.ProductPlacements) [
for(item of placement.ProductPlacementItems) [
// Modified from: https://gist.github.com/rpflorence/1f72da0cd9e507ebec29
var React = require('react/addons')
var merge = require('lodash-node/modern/objects/assign')
function makeStubbedElement(Component, props, contextStubs) {
var TestWrapper = React.createClass({
displayName: 'StubbedElement',
npm install jiff --save
@aaronshaf
aaronshaf / gist:5dff8fcaadbde4c971c8
Created November 17, 2014 15:58
Testing with mocha, a custom fixture utility, ES6 destructuring, and ES7 async/await
describe('as a super administrator', function() {
it('create a session', async function(done) {
var {
user,
password
} = await fixtures(['User'], {
user: { superAdministrator: true }
})
request(app)
@aaronshaf
aaronshaf / bookmarklet.js
Last active August 29, 2015 14:05
Bookmarklet for tallying JIRA column points
$('.ghx-columns .ghx-column').each(function() {
var columnPoints = 0;
var dataColumnId = $(this).data('column-id');
$(this).find('.aui-badge').each(function() {
columnPoints += parseInt($(this).text(),10); || 0
});
var h2 = $('#ghx-column-headers .ghx-column[data-id=' + dataColumnId + '] h2');
var span = h2.find('span');
if(!span.length) {
span = $('<span class="badge" style="margin-left: 6px;"></span>');
@aaronshaf
aaronshaf / gist:20be1b4d88bc3b3e6140
Last active August 29, 2015 14:05
Rebase all branches onto master; delete merged branches (credit: github.com/bluej100)
alias superpull='git checkout master; git pull; for branch in $(git branch --no-merged); do git rebase -q master $branch; done; git checkout master && for branch in $(git branch --merged | grep -v master); do git branch -d $branch; done; echo "Done."'
or
[alias]
sp = "!bash -c 'git checkout master; git pull; for branch in $(git branch --no-merged); do git rebase -q master $branch; done; git checkout master && for branch in $(git branch --merged | grep -v master); do git branch -d $branch; done; echo \"Done.\"'"
Predictable
Disposable
Unidirectionality
Discoverable / greppable
Smaller mental maps
Single source of truth
vs
Cascading and concatenation