This file contains hidden or 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 convertMongoURIToMongoClient(u) { | |
u = u.replace('mongodb://','') | |
var a = u.split('/') | |
, b = (a.length && a[0].split('@')) | |
, c = (b.length && b[0].split(':')) | |
, d = (b.length === 2 && b[1].split(',')) | |
return d.map(function(_d) { | |
var d = _d.split(':') | |
return (function(o,s) { |
This file contains hidden or 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
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.define "web", primary: true do |web| | |
web.vm.hostname = "dev-env" | |
web.vm.box = "trusty32" | |
web.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box" |
This file contains hidden or 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
Handlebars.registerHelper("select", function(value, options) { | |
return options.fn(this) | |
.split('\n') | |
.map(function(v) { | |
var t = 'value="' + value + '"' | |
return ! RegExp(t).test(v) ? v : v.replace(t, t + ' selected="selected"') | |
}) | |
.join('\n') | |
}) |
This file contains hidden or 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
/** | |
* rotate points around an origin | |
* @param {Array<object>} ps a list of points | |
* @param {Number} a angle in degrees | |
* @param {Object} o origin object | |
* @return {Array<object>} a list of rotated points | |
*/ | |
function rotatePoints(ps, a, o) { | |
return ps.map(function(p) { | |
return { |
This file contains hidden or 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
// ensure the keys being passed is an array of key paths | |
// example: 'a.b' becomes ['a', 'b'] unless it was already ['a', 'b'] | |
const keys = ks => Array.isArray(ks) ? ks : ks.split('.') | |
// traverse the set of keys left to right, | |
// returning the current value in each iteration. | |
// if at any point the value for the current key does not exist, | |
// return the default value | |
const deepGet = (o, kp, d) => keys(kp).reduce((o, k) => o && o[k] || d, o) |
This file contains hidden or 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
# status bar | |
set-option -g status-utf8 on | |
### COLOUR (Solarized dark) | |
# default statusbar colors | |
set-option -g status-bg black #base02 | |
set-option -g status-fg yellow #yellow | |
set-option -g status-attr default |
This file contains hidden or 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 flattenVNodePrototype = (o) => { | |
const proto = Object.getPrototypeOf(o) | |
return !proto ? o : Object.assign(o, proto, o.children && { | |
children: o.children.map(flattenVNodePrototype) | |
}) | |
} |
This file contains hidden or 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
// silly | |
const a = [1, 2, 3] | |
let b = [] | |
a.forEach((item, index) => b[index] = item * 2) | |
// repugnant | |
const a = [1, 2, 3] | |
let b = [] |
This file contains hidden or 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 fs = require('fs') | |
const http = require('http') | |
const VIDEO_PATH = './dive-desktop.mp4' | |
const VIDEO_LENGTH = 13063532 | |
http.createServer(function serveVideo(req, res) { | |
if (req.headers.range) { | |
const range = req.headers.range.replace('bytes=', '').split('-') | |
const start = +range[0] |
This file contains hidden or 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
#!/usr/bin/env osascript -l JavaScript | |
const Spotify = Application('Spotify') | |
const log = console.log.bind(console) | |
function run ([command, ...args]) { | |
const availableCommands = Object.keys(commands).filter(name => !name.includes('Usage')) | |
if (availableCommands.includes(command)) commands[command](...args) | |
else { |