Skip to content

Instantly share code, notes, and snippets.

View craSH's full-sized avatar

Ian Gallagher craSH

View GitHub Profile
@craSH
craSH / updatechromiumnightly
Created November 17, 2009 02:16
Simple script to automatically download and install the latest available Chromium nightly build for Mac OSX
#!/bin/bash
#
# Simple script to update OSX Chromium to the latest nightly build.
# Will not download if you already have the latest (call with --force
# to override this check)
#
# Copyleft 2010 Ian Gallagher <crash@neg9.org>
#
LATEST=$(curl -s "http://build.chromium.org/f/chromium/snapshots/Mac/LATEST")
@craSH
craSH / SkypeDial.scpt
Created November 17, 2009 22:08
AppleScript plugin for Address Book to add a Dial with Skype menu item to phone numbers. Place in ~/Library/Address Book Plug-Ins/
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for p with e
if label of e is equal to "Skype" then
return "Call Skype Name"
else
@craSH
craSH / backup_wordpress
Created December 21, 2009 19:12
A very simple script to save differential backups of a wordpress installation directory and it's database. Should be easy enough to adapt to other needs.
#!/bin/bash
# You must init a git repo in $backup_root for this to work
# You must also have a remote repo added per $git_remote
# It's assumed that you have your remote git host configured
# via ~/.ssh/config or something for automatic login with a key
# Local stuff
wwwroot="/var/www/your-blog/" # Trailing slash is important (for rsync)
db_name="blog_db"
db_user="blog_user"
@craSH
craSH / chowntoparent
Created January 20, 2010 20:02
Simple script that will set the ownership of a file to that of the directory in which it resides.
#!/bin/bash
#
# Simple script that will set the ownership of a file to that
# of the directory in which it resides. Useful for example,
# after copying a file from /home/user_alpha/ to /home/user_bravo/
# and you want it to have user_bravo's uid/gid so they can
# access it.
#
# This script is pretty naive, it would most certainly fail
# if a filename had a forward slash in it somehow.
@craSH
craSH / git-new-shared
Created February 25, 2010 00:02
Create a new, shared, bare git repo in a given directory. Make it suitable for multiuser envs (assuming perms on that directory are set properly, and all your git people are in the group which owns that directory)
#!/bin/bash
#
# Create a new, shared, bare repo in a given directory.
# Make it suitable for multiuser envs (assuming perms on that
# directory are set properly, and all your git people are in
# the group which owns that directory)
#
# (C) 2009 Ian Gallagher <crash@neg9.org>
#
@craSH
craSH / hashstore.py
Created April 24, 2010 03:03
Store data somewhere on disk based on that data's sha1 (or whatever) hexdigest. Useful for storing lots of random data on a filesystem when you don't want to use a database for some reason.
#!/usr/bin/env python
#
# (C) Ian Gallagher <crash@neg9.org>
#
def savedata(basedir, data, hashalgo="sha1"):
"""
Given a base directory and chunk of data, store that data in a path composed of it's
SHA1 (default) hexdigest as split in to single-byte hex directories, with the file being the last byte of the digest.
@craSH
craSH / cdp.sh
Created April 24, 2010 05:43
cd to nearest matching parent directory (stuff in a .bashrc or source it)
function cdp() {
# cd to the nearest matching parent directory
# e.g. if PWD is /foo/bar/baz/alice/bob/eve, 'cdp baz' will cd to /foo/bar/baz/
shopt -q nocaseglob
nocaseglob=$?
shopt -s nocaseglob
pat="^(.+)$1[^/]*"
if [[ "$PWD" =~ $pat ]] ; then
newdir=${BASH_REMATCH[0]}
@craSH
craSH / hashpromptshort.sh
Created April 24, 2010 07:02
color your prompt based roughly (1/8*2 hashing) on hostname -f output. Also strip vowels from hostname to give a shorter prompt.
if [ "$PS1" ]; then
if [ "$BASH" ]; then
shortname=${HOSTNAME%%.*}
shortname=${shortname//[aeiou]/}
hostname_crc=$(echo $HOSTNAME | tr 'A-Z' 'a-z' | cksum)
hostname_crc=${hostname_crc%% *}
hostcolor_a=$(( (0x${hostname_crc} + 1) % 2 ))
hostcolor_b=$(( 0x${hostname_crc} % 8 + 30 ))
PS1="\[\e[33;1m\]\u@\[\e[${hostcolor_a};${hostcolor_b}m\]${shortname}:\[\e[0m\]\w"'\$ '
PS2='\[\e[31;1m\]>\[\e[0m\]'
@craSH
craSH / windows_prefetch_paths.py
Created May 7, 2010 07:05
Given a path to a Windows Prefetch file, extract and print a list of all file paths that it contains (which will be prefetched)
import struct
def get_file_paths(pf_file):
"""
Given a path to a Windows Prefetch file, extract and return a list of all file
paths that it contains (which will be prefetched)
References:
- http://en.wikipedia.org/wiki/Prefetcher
- http://msdn.microsoft.com/en-us/magazine/cc302206.aspx
@craSH
craSH / stringsall.sh
Created May 23, 2010 10:58
Write out all possible encodings that strings can deal with for a given file.
#!/bin/sh
# Write out all possible encodings that strings can deal with for a given file.
input=$1
# 7 bit ascii
mode="s"
strings $@ -e $mode $input > strings_$input.$mode
# 8 bit characters