Skip to content

Instantly share code, notes, and snippets.

View andrewp-as-is's full-sized avatar
🔍

Andrew P andrewp-as-is

🔍
View GitHub Profile
@andrewp-as-is
andrewp-as-is / sqlite3.sh
Created May 4, 2019 09:36
sqlite database locked
#!/usr/bin/env bash
# https://stackoverflow.com/questions/2740806/python-sqlite-database-is-locked
function sqlite3() {
executable="$(which sqlite3)" || exit
out="$("$executable" "$@" 2>&1)" && echo "$out" && return || {
[[ "$out" == *"locked"* ]] && exit; echo "$out" 1>&2 && exit 1
}
}
@andrewp-as-is
andrewp-as-is / url escape.sh
Last active July 19, 2021 08:10
url escape
#!/usr/bin/env bash
set -- "word1 word2 word3"
printf "/%s" $(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")
@andrewp-as-is
andrewp-as-is / gists.command
Last active July 19, 2021 08:07
gists management (create, delete orphaned, push updates, update description)
#!/usr/bin/env bash
# pip install gist-delete gist-description gist-exec gist-generator gist-id gists-id
# export GITHUB_TOKEN=<GITHUB_TOKEN>
# cd ~/git/gists
# gist-exec https://gist.github.com/looking-for-a-job/c9d7fb87ec5ebfa0740b2e2dbe4d25bb
# create
gist-exec https://gist.github.com/looking-for-a-job/25cd417fdde68a84eb0a7efa716f6415
# delete orphaned
@andrewp-as-is
andrewp-as-is / ip geolocation.sh
Last active July 19, 2021 08:07
ip geolocation
#!/usr/bin/env bash
{ set +x; } 2>/dev/null
ip="$(curl -s ipecho.net/plain)" || exit
tmp="$(mktemp)" || exit
curl -fs https://freegeoip.app/xml/$ip > "$tmp"
cat "$tmp"
grep "CountryCode" "$tmp" | sed -n 's:.*<CountryCode>\(.*\)</CountryCode>.*:\1:p'
@andrewp-as-is
andrewp-as-is / ip.sh
Last active July 19, 2021 08:07
ip internal and public
#!/usr/bin/env bash
{ set +x; } 2>/dev/null
ipconfig getifaddr en1
curl -s ipecho.net/plain; echo # public ip
@andrewp-as-is
andrewp-as-is / sound.sh
Last active July 25, 2022 19:25
macOS startup sound #macos
defaults write .GlobalPreferences com.apple.sound.beep.sound /System/Library/Sounds/Basso.aiff
@andrewp-as-is
andrewp-as-is / headerless top.sh
Last active August 14, 2019 08:08
unix top examples
#!/usr/bin/env bash
top -l 1 -n 5 | awk '!$0{i++;next;}i==1'
# top -l 1 -n 5 | awk '/^PID/{if (p) next; p=1} p && NF>30 {printf("%-8s %-12s %-6s %-6s\n", $1, $2, $3, $8)}'
#!/bin/sh
sudo fs_usage -f filesys | grep -v grep #| grep desktop
@andrewp-as-is
andrewp-as-is / github ssh test.sh
Last active July 19, 2021 07:46
github ssh test
#!/bin/sh
ssh -T git@github.com
ssh -T git@gist.github.com
@andrewp-as-is
andrewp-as-is / DeRez.sh
Last active July 19, 2021 07:46
macOS Finder icon
#!/usr/bin/env bash
img=~/img.png
xattr -d com.apple.FinderInfo "$img" # remove the custom icon
! [ -e "$img" ] && echo "$img NOT EXISTS" 2> /dev/null && exit 1
icns=~/icns.icns
DeRez -only icns "$img" > $icns
du -k "$icns"