Skip to content

Instantly share code, notes, and snippets.

@toonetown
toonetown / patch-emulator
Created November 4, 2014 01:01
Launch Android Emulator with patch scripts
###############
# Launches (and patches) the android emulator by running all the scripts within the patch directory. The default
# value of ANDROID_EMU_PATCHES is ${HOME}/.android/avd/patches. You can specify a different value for the patch
# directory by specifying ANDROID_EMU_PATCHES as an environment variable.
#
# The scripts within the patch directory will be executed in order. The variable "${ADB}" can be used within a
# script to get the correct adb command to run (targetted to the appropriate port). The variable "${ANDROID_EMU_TDIR}"
# points to a directory that will be cleaned up when the emulator exits. The variable "${ANDROID_EMU_PATCHES}" will
# be set to the effective patch directory.
#
@toonetown
toonetown / homebrew-bootstrap.sh
Last active August 26, 2021 16:58
Bootstraps a Homebrew development environment, with optional packages (taps, brews, casks, and services)
###########
# Installs and/or updates homebrew and various components
#
#!/bin/bash
: ${HOMEBREW_INST_URL:="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"}
: ${HB_BOOTSTRAP_GIST_URL:="https://gist.githubusercontent.com/toonetown/48101686e509fda81335/raw"}
if [ $# -eq 0 ]; then
echo "Usage: ${0} [--fetch-only] <PACKAGES...>"
echo ""
@toonetown
toonetown / webserver
Last active September 7, 2022 21:11
A quick-and-dirty python web server
#!/usr/bin/python3
import http.server, ssl, argparse, re
from tempfile import mkdtemp
from shutil import rmtree
from contextlib import contextmanager
from os.path import exists, join, abspath
@contextmanager
def TemporaryDirectory():
name = mkdtemp()
@toonetown
toonetown / link-sdks
Last active July 8, 2016 03:50 — forked from rnapier/fix-xcode
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
@toonetown
toonetown / base64
Last active November 7, 2023 17:25
Adds an option to encode/decode url-safe base64
###
# Shell script which adds the ability to encode/decode web-safe URLs in base64. Do this by specifying
#
#!/bin/bash
ARGS=()
BAD_CHARS="+/="
SAFE_CHARS="-_ "
URL="n"; CONVERT="n"; DECODE="n"; IN="-"; OUT="-"; HELP="n"
while (($#)); do
case "${1}" in
@toonetown
toonetown / add_user
Created May 12, 2016 18:24
Adds a user to OS X (Yosemite and later), sets the machine as "Setup Done" and skips iCloud registration for the created user.
#!/bin/bash
# Adds a user via command line, and sets the machine as "Setup Done"
# Ensure that it runs as root
if [ "$(id -u)" != "0" ]; then
echo "${0} must be run as root, or using sudo"
exit 1
fi
if [ -n "${1}" -a -n "${2}" -a -n "${3}" -a -n "${4}" ]; then
@toonetown
toonetown / reset_system
Last active September 18, 2017 17:32
Permanently deletes the given local users and resets the OS X (Yosemite and later) system to an empty state. After running this script, the setup assistant will run again.
#!/bin/bash
# Permanently deletes the given users and resets the system to an empty state
# Ensure that it runs as root
if [ "$(id -u)" != "0" ]; then
echo "${0} must be run as root, or using sudo"
exit 1
fi
if [ ! "${1}" ]; then
@toonetown
toonetown / docker_pipe
Last active May 20, 2016 19:56
Allows passing of data from the host to a docker container
#!/bin/bash
#
# A script to facilitate passing data from host to container in a daemon
#
# To read a variable (from within the container):
# VAR="$(docker_pipe read)"
#
# !!! Note that reading a variable will block until it is written to !!!
#
# To write to the variable that is being read (from the host):
@toonetown
toonetown / ssh_expect
Last active May 20, 2021 11:58
An expect script that will spawn ssh and automatically enter the password
#!/usr/bin/expect
#
# A script to handle automatic entering of ssh passwords. It is intended that this script
# mainly be used from within a docker image in conjunction with docker_pipe to avoid
# placing private keys and passwords in your image.
#
# This script can be used as a drop-in replacement for ssh, as all parameters are passed
# to the ssh command.
#
# To use (reading the password from the command line):
@toonetown
toonetown / check-code
Last active June 7, 2016 17:11
A script which performs some code style checking (line length, trailing spaces, etc.)
#!/bin/bash
#######
# A script which finds various code violations (such as line spacing or trailing spaces)
#
_SCRIPT="${0}"
_QUIET=""; _TRAIL_ONLY=""; _EMPTY=""; _LENGTH_ONLY=""; _MAX_LENGTH=120; _PATHS=(); _ERR=""
_err () { "${_SCRIPT}" __XXX__ "$@"; exit $?; }
while [ $# -gt 0 ]; do