Skip to content

Instantly share code, notes, and snippets.

View whiteinge's full-sized avatar

Seth House whiteinge

View GitHub Profile
@whiteinge
whiteinge / fabfile.py
Created November 13, 2009 17:16
Example fabric script with VirtualBox automation
# -*- coding: utf-8 -*-
"""MyCompany Fabric script.
* Deploy code
* Set up a local development environment
There are two ways to deploy the myrepo code:
1. :func:`deploy` will do a full virtualenv installation/update and expand a
tarball of the specified git revision (defaults to HEAD) to a timestamped
@whiteinge
whiteinge / apachestats
Created March 19, 2012 02:55
Grab RAM usage, load, and Apache processes
#!/usr/bin/env bash
# List stats helpful for tuning Apache
APIDS=$(pgrep apache | wc -l)
LOADAVG=$(< /proc/loadavg)
# hopefully the prefork section is the first match...
MAXCLIENT=$(grep -m 1 "^MaxClient" /etc/apache2/apache2.conf | cut -d' ' -f 2)
free -mt | awk '
BEGIN {
@whiteinge
whiteinge / xmap.sh
Created May 31, 2012 01:58
Experimental map shell function using xargs
# Pull the username and password out of the xml file and into local vars
# Run the output through sed to escape & and _ characters for MySQL
# Note: the shell quoting here gets a little rough. The final command is:
# sed -e 's/[%_]/\&/g'
read dbuser dbpass <<<$(xmap \
'xmlstarlet sel -t -v "//controller-config/database/@" '${XML_FILE}' \
| sed -e '\''s/[%_]/\\\\&/g'\' \
username password)
@whiteinge
whiteinge / base.js
Created July 5, 2012 20:10
A baseline JS toolbox for new projects
/**
* Allow Prototypal inheritance
* http://javascript.crockford.com/prototypal.html
* @author Douglas Crockford
* @version 2008-04-07
* @param oldObject
* @return newObject
*/
if (typeof Object.create !== 'function') {
Object.create = function (o) {
@whiteinge
whiteinge / bootstrap_venv_fab.py
Created August 8, 2012 02:07
A fabric file to bootstrap an Ubuntu system for use as a VirtualBox master image for development VMs using port-forwarding and shared folders.
# utf-8
"""A fabfile to boostrap a vanilla VirtualBox master image
Generally you will create a master image with the following commands::
fab -f ./bootstrap_venv_fab.py portfwd:guest=somevm-precise64-fresh
fab -f ./bootstrap_venv_fab.py -H 'localhost:2222' -u somedev -p somedev shared
fab -f ./bootstrap_venv_fab.py -H 'localhost:2222' -u somedev -p somedev nopasswd
fab -f ./bootstrap_venv_fab.py -H 'localhost:2222' -u somedev -p somedev resetmac
fab -f ./bootstrap_venv_fab.py -H 'localhost:2222' -u somedev -p somedev -- sudo shutdown -h now
@whiteinge
whiteinge / headed-home.xml
Created January 1, 2013 20:03
A Tasker task for texting a driving time estimate between your current location and home. Expects two variables to be set: HOME: An address, zip code, etc to use as the destination address when querying the Google Maps API. HOMENUM: A phone number to send the text to.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
<Task sr="task2">
<cdate>1345254133188</cdate>
<edate>1357068354779</edate>
<id>2</id>
<nme>Headed Home</nme>
<pri>10</pri>
<Action sr="act0" ve="3">
<code>902</code>
<Int sr="arg0" val="0"/>
@whiteinge
whiteinge / Makefile
Last active December 12, 2015 01:49
A Makefile to help with Salt development
# Easily install, maintain, and cleanly reset (!) a Salt development
# installation inside a virtualenv (no need to "activate" the venv)
SRC := /home/shouse/src/salt/salt
VENV := /home/shouse/tmp/venvs/salt
BIN := $(VENV)/bin
ETC := $(VENV)/etc/salt
PKI := $(ETC)/pki
VAR := $(VENV)/var
TMP := $(VENV)/tmp
@whiteinge
whiteinge / bootstrap-php.sh
Created April 30, 2013 20:59
A script to bootstrap a new Ubuntu machine for use as a PHP webserver. This gist exists to remind me / demonstrate a handful of techniques for organizing a large shell script.
#!/usr/bin/env bash
# Bootstrap a new Ubuntu machine for use as a PHP env for <company>.
# These functions are intended to be run largely in the order they appear
# below.
NAME=$(basename $0)
declare -A SITES
SITES[s1]="site1"
SITES[s2]="site2"
@whiteinge
whiteinge / postconfig-vbox.sh
Created April 30, 2013 21:17
Shell functions for doing post-OS-install configuration of a VirtualBox VM. In particular, a shell wrapper around ``VBoxManage guestcontrol`` that allows running commands on the guest without knowing the IP or having ssh configured. Also includes an example of pushing small files (through stdout) to the guest via HEREDOC.
#!/usr/bin/env bash
# Post-configure a newly imported development VM.
NAME=$(basename $0)
# These vars may be overridden by envionment variables of the same name but
# with a preceeding "DEV_"
USER=${DEV_USER:-"somedev"}
PASS=${DEV_PASS:-"somedev"}
VM=${DEV_VM:-"localdev"}
@whiteinge
whiteinge / salt-lowdata-formats.rst
Last active January 7, 2023 17:21
Salt is used to execute functions across a wide variety of locations in a wide variety of ways. It does this by mapping the function name and function parameters within a data structure (JSON-serializable). Unfortunately, there is a variety of formats in different parts of Salt for doing so.

Various formats of mapping data to function calls in Salt

Note

Legend

mod
Module name
fun
Function name (in module)