# Create a new directory and enter it function md() { mkdir -p "$@" && cd "$@" } # Start an HTTP server from a directory, optionally specifying the port function server() { local port="${1:-8000}" open "http://localhost:${port}/" # Set the default Content-Type to `text/plain` instead of `application/octet-stream` # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" } # Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL. # Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!) function httpcompression() { encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" } # Syntax-highlight JSON strings or files function json() { if [ -p /dev/stdin ]; then # piping, e.g. `echo '{"foo":42}' | json` python -mjson.tool | pygmentize -l javascript else # e.g. `json '{"foo":42}'` python -mjson.tool <<< "$*" | pygmentize -l javascript fi } # All the dig info function digga() { dig +nocmd "$1" any +multiline +noall +answer } # Escape UTF-8 characters into their 3-byte format function escape() { printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u) echo # newline } # Decode \x{ABCD}-style Unicode escape sequences function unidecode() { perl -e "binmode(STDOUT, ':utf8'); print \"$@\"" echo # newline }