Skip to content

Instantly share code, notes, and snippets.

The Magical Expanding Interface

Here is a series of logical, defensible actions that end up with a sub-optimal result:

  • We need to share some code between two applications (App A and App B), so we move it out of App A into somewhere else (i.e. its own repo, or into components or essentials or some similar collection.)
  • The interface exposed by this shared code isn't quite right for App B. Perhaps it's not ergonomic for the application for some reason, so to keep things DRY, they create a wrapper to provide whatever configuration, defaults, or argument shifting makes sense for App B. Now, all call sites in App B go through the wrapper.
  • Time goes by, and something else changes. Perhaps App A changes a bit, and so the engineers do step 2 above (but -- to be clear, they implement it in a different, App A specific way). Alternately, App B becomes more complex and the lower level wrapper is no longer s
class ConnectKoa extends Koa {
callback() {
// compose middleware stack
const fn = compose(this.middleware);
// expose a connect-conforming function
return (req, res, next) => {
// create context
const ctx = this.createContext(req, res);
@bttmly
bttmly / jenkins-theme.css
Last active August 31, 2016 00:39
jenkins theme
@import url(https://fonts.googleapis.com/css?family=Roboto:400,700,500,300);@import url(https://fonts.googleapis.com/css?family=Roboto+Mono:400,700,500,300);@-webkit-keyframes a{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes a{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@-webkit-keyframes b{0%{opacity:1}50%{opacity:0}to{opacity:1}}@keyframes b{0%{opacity:1}50%{opacity:0}to{opacity:1}}[src$='blue.png']{background-image:url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIxOCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsPSIjMDA5Njg4IiBkPSJNMTIgMkM2LjQ4IDIgMiA2LjQ4IDIgMTJzNC40OCAxMCAxMCAxMCAxMC00LjQ4IDEwLTEwUzE3LjUyIDIgMTIgMnptLTIgMTVsLTUtNSAxLjQxLTEuNDFMMTAgMTQuMTdsNy41OS03LjU5TDE5IDhsLTkgOXoiLz48L3N2Zz4=)}[src$='red.png']{background-image:url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE4IiB2aWV3Qm94PSIwIDAg
@bttmly
bttmly / generate_personal_podcast.rb
Created July 6, 2016 23:24 — forked from kelan/generate_personal_podcast.rb
A script for generating a personal podcast feed from mp3 files in a public Dropbox folder.
#!/usr/bin/env ruby -wKU
#
# by Kelan Champagne
# http://yeahrightkeller.com
#
# A script to generate a personal podcast feed, hosted on Dropbox
#
# Inspired by http://hints.macworld.com/article.php?story=20100421153627718
#
# Simply put this, and some .mp3 or .m4a files in a sub-dir under your Dropbox
@bttmly
bttmly / error-stacks.js
Created May 12, 2016 18:25
demonstration of Error.captureStackTrace
function Miss () {
return new Error("My stack trace is wrong");
}
function Hit () {
var err = new Error("My stack trace is right");
Error.captureStackTrace(err, Hit);
return err;
}
package turbofan
import "reflect"
type Turbofan struct {
Blast func(bool)
}
// New just creates a new turbofan
func New(chans ...chan bool) *Turbofan {
@bttmly
bttmly / for-channel-demo.go
Last active April 1, 2016 03:37
If a struct field is a channel and it might change (say, for a stub/mock in tests?), careful how you "range" over it
package main
import "log"
type ForTest struct {
ch chan int
}
func main() {
thing := &ForTest{ch: make(chan int)}
@bttmly
bttmly / parse-docs.js
Created February 26, 2016 04:36
parse the nba_py docs into an array of endpoint descriptions that can be used to dynamically construct an API client
// targets this file: https://github.com/seemethere/nba_py/wiki/stats.nba.com-Endpoint-Documentation
var fs = require("fs");
var markdown = fs.readFileSync("./stats.nba.com-Endpoint-Documentation.md", "utf8");
function createDescription (block) {
var name = block[0].slice(3, -1);
var params = block.slice(2).map(line => line.slice(4)).filter(Boolean);
return {name, params};
}
@bttmly
bttmly / promisify-es6.js
Created September 17, 2015 00:58
promisify is a one-liner in idiomatic es6
let promisify = func => (...args) => new Promise((resolve, reject) => func(...args, (err, result) => err ? reject(err) : resolve(result)));
//
let promisify = fn => (...args) =>
new Promise((resolve, reject) => {
fn(...args, (err, result) => {
if (err) return reject(err);
resolve(result);
});
});