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
var getComputedStyle = require('computed-style'); | |
var fontStyles = ['font-family', 'font-size', 'font-weight', 'font-style']; | |
module.exports = function getFontStyles(domElement) { | |
return { | |
element: domElement, | |
styles: extractFontStyles(domElement) | |
} | |
} |
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/sh | |
set -e | |
# !!!! | |
echo "*** REPLACE this with the line which builds docs" | |
# !!!! | |
echo "*** Docs built ***" | |
tmpdir=`mktemp -d /tmp/gh-pages-build.XXXXXX` |
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
// assuming that the React app is inside /client/ | |
// clear cached client modules so next server render uses new stuff | |
webpack.plugin('done', function() { | |
Object.keys(require.cache).forEach(id => { | |
if (/\/client\//.test(id)) { | |
delete require.cache[id]; | |
} | |
}); | |
}); |
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
var Immutable = require('immutable'); | |
var FooRecord = Immutable.Record({ a: 1, b: 2 }, 'foo'); | |
Immutable.is(new FooRecord(), new Immutable.Map({a: 1, b: 2})); | |
// => true |
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
<?php | |
public function providerGetEventId() { | |
return array( | |
'wrong way around' => array( | |
'Premier League', | |
array('id' => 5,'name' => 'Hull', 'shortname' => 'HUL'), | |
array('id' => 6,'name' => 'Manchester City', 'shortname' => 'MNC'), | |
null | |
), | |
'different event type' => array( |
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
var _ = require('underscore'); | |
/** | |
* functional zip() for JS objects | |
* | |
* Skips keys not present in both sides | |
* | |
* @param a left object | |
* @param b right object | |
* @param f(key, aval, bval) iterator |
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
# List processes via pgrep, then prompt to pkill | |
pgk() { | |
[ -z "$*" ] && echo 'Usage: pgk <pattern>' && return 1 | |
pgrep -fl $* | |
[ "$?" = "1" ] && echo 'No processes match' && return 1 | |
echo 'Hit [Enter] to pkill, [Ctrl+C] to abort' | |
read && pkill -f $* | |
} |
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
(ns water | |
(require [clojure.string :as s])) | |
(defn right-reductions [f l] | |
"just like (reductions) but form the right" | |
(reverse (reductions f (reverse l)))) | |
(defn transpose [m] | |
"Transpose a list of lists" | |
(apply mapv vector m)) |
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
// Basically every data read ever looks something like this | |
// Can this be optimised using the callback advice from http://blog.trevnorris.com/2013/08/long-live-callbacks.html | |
function getData(callback) { | |
http.get('http://localhost/whatever', function(err, res) { | |
if (err) return callback(err); | |
res.on('error', callback); | |
var buffers = [], length = 0; | |
res.on('data', function(chunk) { |
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
var app = express(); | |
database.connect(function(err, db) { | |
app.db = db; | |
app.listen(1337); | |
}) | |
app.get('/stuff/:id', stuffHandler); | |
function stuffHandler(req, res) { | |
app.db.fetch(req.params.id, function datastoreCallback(err, data) { |