flatter is a command-line tool for determining a source file's "indentedness", which provides a rough indication of how well factored the code is.
$ flatter src
cheerio = require 'cheerio' | |
request = require 'request' | |
tutor = require 'tutor' | |
request 'http://www.wizards.com/magic/tcg/events.aspx?x=mtg/event/playerschamp/2012/cubepool', | |
(err, res, body) -> | |
throw err if err? | |
$ = cheerio.load body | |
names = $('a.nodec').map -> @text() |
A woman has two children, (at least) one of whom is a boy. What's the probability that she has two boys?
B B-B 1/4
/
/
B
/ \
/ \
/ G B-G 1/4
/
#!/usr/bin/env python | |
import json | |
import re | |
import subprocess | |
import sys | |
if len(sys.argv) > 1: | |
lsregister = sys.argv[1] | |
else: |
decorate = (klass, methodName, fn) -> | |
method = klass::[methodName] | |
klass::[methodName] = (args...) -> | |
method.apply this, args | |
fn.apply this, args | |
# Example | |
decorate Array, 'push', (args...) -> |
#!/usr/bin/env bash | |
echo | |
for filename in $(find $1); do | |
loc=$(sed /^\s*$/d $filename | wc -l) | |
printf %24s $(echo $filename | sed 's!.*/!!') | |
printf %8s $loc | |
echo -n ' ' | |
indent=$(seq -s ' ' 36 | sed s/[0-9]//g) | |
seq -s '+' $loc | sed -e s/[0-9]//g -e "s/.\{100\}/&,$indent/g" | tr , '\n' |
{abs, floor, round} = Math | |
# > @localize = (timestamp) -> | |
# . $.localize.format (new Date timestamp), new Date "1 Mar 2012 00:30:45" | |
# | |
# > localize "30 Jan 2012 23:59:59" | |
# "2012-01-30" | |
# > localize "31 Jan 2012 00:00:00" | |
# "30 days ago" | |
# > localize "28 Feb 2012 23:59:59" |
Apply a patch on the clipboard to the current Git/Hg repo:
pbpaste | patch -p1
Or, if the trailing "\n" is missing:
pbpaste | xargs -0 echo | patch -p1
# Problem: Determine all the paths for a given node. | |
# | |
# A | |
# / \ | |
# / \ | |
# B C | |
# / \ \ | |
# / \ \ | |
# C D D | |
# \ |
(req, res) -> | |
# Attach language codes to request object. | |
h = req.headers['accept-language'] | |
req.languages = h and (/[^\s;-]+/.exec(l)[0] for l in h.split ',') or [] |