This file contains 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
res() { | |
old=$(stty -g) | |
stty raw -echo min 0 time 5 | |
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty | |
IFS='[;R' read -r _ rows cols _ < /dev/tty | |
stty "$old" |
This file contains 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/python2.7 | |
# How many digits can I remember? How good is that approximation? | |
import math | |
import decimal | |
def compute_pi(): | |
"""Compute Pi to the current precision. | |
>>> print(pi()) | |
3.141592653589793238462643383 |
This file contains 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
brew info --json --installed |jq -r '.[] |{name: .name, desc: .desc} |join("\t")' |column -ts $'\t' |
This file contains 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/python | |
# ibitize: take an integer argument, return a string using ibi binary prefixes | |
# echo '32*2^30'|bc | |
# 34359738368 | |
# echo 'l(34359738368)/l(2)' |bc -l | |
# 35.00000000000000000036 | |
# ibitize 34359738368 | |
# 32.0 Gi |
This file contains 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/perl | |
# hostify: try to translate everything that looks like IP addresses | |
# into hostnames. Leave them alone if DNS doesn't resolve them. | |
# echo "Please tip your 127.0.0.1 well." |hostify | |
# Please tip your localhost well. | |
use Socket; | |
sub host { return gethostbyaddr(inet_aton($_[0]), AF_INET) // $_[0]} |
This file contains 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
#!/bin/bash | |
# https://stackoverflow.com/questions/19104847/how-to-generate-a-dockerfile-from-an-image | |
case "$OSTYPE" in | |
linux*) | |
docker history --no-trunc --format "{{.CreatedBy}}" $1 | # extract information from layers | |
tac | # reverse the file | |
sed 's,^\(|3.*\)\?/bin/\(ba\)\?sh -c,RUN,' | # change /bin/(ba)?sh calls to RUN | |
sed 's,^RUN #(nop) *,,' | # remove RUN #(nop) calls for ENV,LABEL... | |
sed 's, *&& *, \\\n \&\& ,g' # pretty print multi command lines following Docker best practices |
This file contains 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 python3 | |
# Makes an HTTP request to the specified URL and sends response to stdout. | |
# A drop-in replacement for some limited uses of curl, like: | |
# hcat $URL -H "Authorization: Bearer $TOKEN" | |
import urllib.parse | |
import urllib.request | |
import sys | |
import argparse |
This file contains 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
#!/bin/bash | |
# Usage: | |
# orl 'https://eu.httpbin.org/#/HTTP_Methods' | |
orl () { | |
url=$1 | |
rex="\([^:]*\)://\([^/]*\)\(/.*\)" | |
uscheme=$(echo $url |sed "s,$rex,\1,") | |
uauthority=$(echo $url |sed "s,$rex,\2,") | |
upath=$(echo $url |sed "s,$rex,\3,") |