Skip to content

Instantly share code, notes, and snippets.

View Olical's full-sized avatar
🧙‍♂️
(magic)

Oliver Caldwell Olical

🧙‍♂️
(magic)
View GitHub Profile
{
"storage": {
"packages": ".bower/cache",
"registry": ".bower/registry"
},
"tmp": ".bower/tmp"
}
@Olical
Olical / EventEmitter.js
Created March 8, 2014 19:00
EventEmitter v4.2.7 snapshot
/*!
* EventEmitter v4.2.7 - git.io/ee
* Oliver Caldwell
* MIT license
* @preserve
*/
(function () {
'use strict';
@Olical
Olical / e.js
Last active August 29, 2015 13:58
Absolutely tiny emitter.
function e(m,i,t){return m.map(function(l){return l(i,m)})}
@Olical
Olical / factory.js
Created November 21, 2014 00:03
Screeps hervester swarm - http://screeps.com
var _ = require('lodash');
function countType(type) {
return _.size(_.filter(Game.creeps, function (creep, creepName) {
return creepName.split('_')[0] === type;
}));
}
function build(spawn, type, attrNames) {
var attrs = attrNames.map(function (name) {
@Olical
Olical / compile.js
Last active August 29, 2015 14:10
Compiles an array tree structure into React DOM. Skip JSX, but without being SUPER verbose (will turn into an actual library soon)
var React = require('react');
var _ = require('lodash');
/**
* Compiles an array into a React DOM structure recursively. All segments of the node array are optional.
*
* The array segments can be in any order apart from the node type, that always needs to be first.
*
* Actually works really well, I'd quite like to open source this with CSS selector parsing in the nodeName.
*
@Olical
Olical / expand.vim
Created December 10, 2014 10:08
Expand lines like bash in Vim https://asciinema.org/a/14558
" Run expand on your current line or range of lines.
" Allows you to repeat {lines,blocks} like this {1..3} times.
" Allows you to repeat lines like this 1 times.
" Allows you to repeat lines like this 2 times.
" Allows you to repeat lines like this 3 times.
" Allows you to repeat blocks like this 1 times.
" Allows you to repeat blocks like this 2 times.
" Allows you to repeat blocks like this 3 times.
function SomeThing {
var sortOfPrivateThroughClosure = true;
this.someVal = {};
this.doThing = function () {
// ...
};
// Then sometimes the values are ES5 getter/setter methods with side effects.
// The only way to tell is to read the source of the object you're dealing with though.
#!/usr/bin/env bash
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
cat >>~/.vimrc <<EOL
set nocompatible
call plug#begin()
Plug 'tpope/vim-sensible'
/**
* Turns a number (in number or string form) into a string with commas used as
* a thousands separator.
*
* Example: 10000000 -> 10,000,000
*
* @param {String|Number} num
* @return {String}
*/
function formatNumberWithCommas(num) {