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
# print value pairs from an array in lower case | |
jq --raw-output '.[] | "\(.key_1 | ascii_downcase) \(.key_2 | ascii_downcase)"' | |
# convert `key=value` lines into `{"key":"value"}` json | |
jq --raw-input 'split("=") | {(.[0]):.[1]}' some.conf | jq --slurp 'add' | |
# validate json (bad) | |
echo '{hello: "there"}' | jq . >/dev/null 2>&1 && echo good json || echo bad json | |
bad json |
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 -w | |
use Getopt::Long; | |
# use diagnostics; | |
sub usage { | |
my $name = $0; | |
$name =~ s/.*\///; | |
print <<EOT; | |
Usage: $name [options] in-list other-list |
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 -w | |
use Net::CIDR; | |
use Getopt::Long; | |
# Net::CIDR one liner: | |
# perl -mNet::CIDR -ne 'print if Net::CIDR::cidrlookup($_, ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"))' | |
# | |
# TODO: add ip address validation |
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
## setting up a personal git repository that you can push change sets to | |
## ssh-host: a host defined in ~/.ssh/config (see: ssh_config(5)) | |
## camaro: the name of the repo | |
# on a remote host or local filesystem: | |
git init --bare camaro.git # (option: use --shared if there are other contributors) | |
# on local host cd to camaro directory: | |
git remote add origin ssh-host:[path/]camaro.git | |
# (for origin on local filesystem: git remote add origin file:///media/volume-name/camaro.git) |
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 | |
get_data() { | |
# if the parameter is a local file just cat it (for testing) otherwise try curl | |
{ test -r "$1" && cat "$1" || curl -s "$1"; } | \ | |
jq --raw-output \ | |
'.[] | "\(.symbol | ascii_downcase) \(.price_usd)"' | |
} | |
process() { |
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/sh | |
# sample usage: | |
# ontouchdo malformed.html 'clear; xmllint --noout --valid malformed.html 2>&1 | head -n20' | |
# | |
# Now fix some things in malformed.html and save. See the remaining errors in real time. Ctrl-c to quit. | |
[ ! -r "$1" ] && echo 'Nothing to watch.' && exit 1 | |
[ ! -n "$2" ] && echo 'Nothing to do.' && exit 1 |
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
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'cleartext-password'; | |
GRANT SELECT,INSERT,UPDATE,DELETE ON `database`.* TO 'someuser'@'localhost'; |
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
# Use awk to to redirect docker build output to stderr for visual feedback | |
# while capturing the image id on stdout when the build is sucessfull | |
ID=$(docker build . | awk '{print > "/dev/stderr"} END {if (/^Successfully built /) print $NF; else exit 1}') | |
# given docker volume path, return local storage path | |
doc2loc(){ docker inspect --format "{{range .Mounts}}{{if eq .Destination \"$1\"}}{{.Source}}{{end}}{{end}}" $2;} |
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 | |
START=$(date +%s) | |
read -s -n1 -p $'Press a key when done.\n' | |
ELAPSED_SECONDS=$(bc <<< "scale=10; ($(date +%s) - $START)") | |
if [ $ELAPSED_SECONDS -gt 60 ]; then | |
ELAPSED_MINUTES=$((ELAPSED_SECONDS / 60)) | |
ELAPSED_SECONDS=$((ELAPSED_SECONDS - ELAPSED_MINUTES * 60)) | |
echo -n "$ELAPSED_MINUTES minutes " | |
fi |
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
telnet smtp.example.com 25 | |
Trying 203.0.113.1... | |
Connected to smtp.example.com. | |
Escape character is '^]'. | |
220 example.com running My Bitchin Mail Server 1.0.0 | |
HELO example.org | |
250 example.com hello example.org (198.51.100.1) | |
MAIL FROM:<postmaster@example.org> | |
250 2.1.5 sender OK | |
RCPT TO:<someone@example.com> |