Skip to content

Instantly share code, notes, and snippets.

View ricardobeat's full-sized avatar

Ricardo Tomasi ricardobeat

View GitHub Profile
function AbortablePromise (fn) {
var abortHandler;
function onAbort (abortFn) {
abortHandler = abortFn;
}
var promise = new Promise(function (resolve, reject) {
fn.call(null, resolve, reject, onAbort);
Verifying I am +ricardobeat on my passcard. https://onename.com/ricardobeat
Promise.prototype.spread = function (fn) {
this.then(function (values) {
fn.apply(this, values)
})
}
function when () {
var requirements = Array.prototype.slice.call(arguments, 0)
return Promise.all(requirements.map(function(name){
@ricardobeat
ricardobeat / stupid-ie7-console-log.js
Last active August 29, 2015 14:13
IE7 panel for console.*
;(function () {
var doc = document.documentElement
var IE7 = navigator.userAgent.indexOf('MSIE 7') > 0
logpane = document.createElement('div')
var height = 180
var width = 480
document.body.appendChild(logpane)
logpane.style.background = '#fff'
logpane.style.padding = '10px'
logpane.style.position = IE7 ? 'absolute' : 'fixed'
@ricardobeat
ricardobeat / chess.js
Last active August 29, 2015 14:13
compiling chess results with node streams
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var dir = process.argv[2]
if (!dir) throw new Error('Usage: ./chess.js path-to-pgn-files/ ')
var white = 0
var black = 0
@ricardobeat
ricardobeat / .prompt
Created December 3, 2014 10:46
simpler prompt
function _e () {
local color; local escape; local newline; local bold=0
if [[ $1 == "bold" ]]; then
shift; bold=1
fi
case $1 in
white ) color=37 ;;
red ) color=31 ;;
green ) color=32 ;;
yellow ) color=33 ;;
@ricardobeat
ricardobeat / .gitconfig
Created December 3, 2014 10:28
git aliases
[alias]
lg = log -20 --graph --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn\\ %C(cyan)%cr]" --decorate --abbrev-commit --date=relative
who = shortlog -sn
dip = diff --patience
stat = status -sb
snapshot = !git stash save "snapshot: $(date)" && git stash apply "stash@{0}"
word = diff --word-diff=color
up = "!git fetch --all -p && git rebase @{u}"
mine = "!git lg --author=\"$(git config user.name)\""
aliases = "!git config --list | grep alias | cut -c 7- | sed 's/=//' | column -t -s ''"
@ricardobeat
ricardobeat / blocks.js
Created October 22, 2014 23:40
blocks 2
;(function(global){
var library = {}
var instances = {}
function define (name, factory) {
if (library[name]) {
throw new Error('Module '+ name +' already registered.')
}
library[name] = factory
@ricardobeat
ricardobeat / git-open
Created September 29, 2014 12:05
git-open - open all modified files
#!/bin/bash
#
# Open all changed files in Sublime Text
#
# Install:
# save this file to /usr/local/bin/git-open
# chmod +x /usr/local/bin/git-open
#
# It will now be available as 'git open'
#
@ricardobeat
ricardobeat / git-find
Created July 14, 2014 16:00
File search using git ls-files with relative path output.
git ls-files | grep $1 | sed s%`git rev-parse --show-prefix`%%