Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Shamelessly stolen from parts of bash-it (https://github.com/hmans/bash-it)
alias reload='source ~/.bash_profile'
# Directory stuff
alias sl=ls
alias ls='ls -G' # Compact view, show colors
alias la='ls -AF' # Compact view, show hidden
alias ll='ls -al'
@bitsandbooks
bitsandbooks / geticon.sh
Created April 18, 2012 16:21
Bash function to grab an app's icon
#!/bin/bash
# Lovingly ripped off from Brett Terpstra.
# http://brettterpstra.com/grabbing-a-mac-apps-icon-advanced-bash-usage-2/
function geticon() {
APP=`echo $1|sed -e 's/\.app$//'`
APPDIR=''
for dir in "/Applications/" "/Applications/Utilities/" "/Developer/Applications/" "/Developer/Applications/Utilties/"; do
if [[ -d ${dir}$APP.app ]]; then
APPDIR=$dir
#!/usr/bin/python
# VertiCal: A slim monthly calendar (that's perfect for GeekTool)
# by Rob Dumas
# Copyright (c) 2012 GNU Public License version 3.
# See http://www.gnu.org/licenses/licenses.html for details on this license.
import sys
import datetime
import calendar
@bitsandbooks
bitsandbooks / baseconv.py
Created May 9, 2012 22:40
Python base-conversion method
"""
Source: http://djangosnippets.org/snippets/1431/
Convert numbers from base 10 integers to base X strings and back again.
Sample usage:
>>> base20 = BaseConverter('0123456789abcdefghij')
>>> base20.from_decimal(1234)
'31e'
>>> base20.to_decimal('31e')
@bitsandbooks
bitsandbooks / fib.py
Created May 15, 2012 21:31
Using Python to Print Fibonacci Sequences
#!/usr/bin/python
"""
fib.py
A simple Fibonacci sequencer.
by Rob Dumas.
Public Domain (no copyright restrictions).
If someone using our program wants to get 13 numbers in the Fibonacci sequence
(or 10 or 100 or any other number), they have to edit our program by hand. Most
people don't want to do this, so Python has LIBRARIES (collections of tools)
@bitsandbooks
bitsandbooks / backup-flash-drive.sh
Last active October 10, 2015 06:07
Back up Flash Drive
#!/usr/bin/env sh
#
# This script backs up your flash drive to a local folder. If you're also
# using a backup system such as Time Machine (and you are, right?), this
# ensures you will have a snapshot of your flash drive the last time you
# plugged it in. Time Machine will then capture the folder, thus
# automatically creating time-based backups for even your portable storage!
#
# If you use launchd to run this script whenever you plug your flash drive
# into your Mac, you don't even need to think about it. Full instructions on
@bitsandbooks
bitsandbooks / links_controller.rb
Created April 19, 2013 04:14
Expected response to be a <:redirect>, but was <200>. Failure is on lines 29 and 57 of the test.
@bitsandbooks
bitsandbooks / add-nginx-vhost.sh
Last active June 22, 2017 01:45
My custom script for adding a vhost to Nginx.
#!/usr/bin/env bash
#
# Nginx - new server block
# http://rosehosting.com
# Functions
ok() { echo -e '\e[32m'$1'\e[m'; } # Green
working() { echo -ne '\e[1;33m'$1'\e[m'; } # Yellow
die() { echo -e '\e[1;31m'$1'\e[m'; exit 1; }
@bitsandbooks
bitsandbooks / tmvolume.rb
Last active December 22, 2015 20:38
My Time Machine Server doesn't need to be serving all day, so I wrote this script to start/stop the relevant services (netatalk, avahi-daemon) and mount/umount the volume. Cron calls this script twice a day: once at 6:00 AM to shut off the services (so my laptop isn't in the middle of a backup when I leave for work) and again at 5:00 (so when I …
#!/usr/bin/env ruby
# tmvolume.rb
# by Rob Dumas <rob@bitsandbooks.com>
# Starts and stops the Time Machine volume. Intended to be called from cron.
action = ARGV[0]
mountpoint = "/mnt/timecapsule"
servicefolder = "/etc/init.d/"
servicenames = [ "netatalk", "avahi-daemon" ]
@bitsandbooks
bitsandbooks / setup.sh
Created June 22, 2014 17:47
Basic setup script for a fresh Ubuntu server. Will set the machine's hostname and install Git, Puppet (with APT module) and ZFS.
#!/usr/bin/env bash
# Basic setup script for a fresh Ubuntu machine. Will set the machine's
# hostname and install Git, Puppet and ZFS.
RELEASE=`lsb_release -s -c`
NAME="servername"
# Set the machine's hostname. If you pass a name as $1, that hostname
# will be used. Otherwise, just change the $NAME variable above.
if [ -n "$1" ]; then; unset $NAME && NAME=$1; fi