Skip to content

Instantly share code, notes, and snippets.

@samba
samba / backup.sh
Created September 11, 2013 08:29
Backup snapshot script using <fileconvoy.com> as rolling storage
#!/bin/sh
# This script creates encrypted tarballs and then
# 1) Emails them to you, or
# 2) Uploads them to <fileconvoy.com>, and emails you a link and decryption key
# Dependencies: curl, openssl, grep, tar
# Where to find the content to back up
BACKUP_ROOT=/var/backup
@samba
samba / .vimrc
Last active December 17, 2015 09:39
Vim Configuration Redux
" This minimal vimrc is intended to be easily deployed to machines where my
" dotfiles are not already installed, while maintaining a basic feature set
" for usability.
" These directories must exist... @{
set backupdir=$HOME/.vim/backup " backup files location
set directory=$HOME/.vim/swap " swap files location
set tags=./tags,$HOME/.vim/tags " you probably want to add more to these later.
" }@
@samba
samba / find-php-eval.sh
Last active December 17, 2015 08:28
Search for PHP files that call "eval" (that's bad).
#!/bin/sh
BASEDIR="${1:-./}"
listfiles () {
find ${BASEDIR} -type f -print0 | xargs -0 file -i -0 | grep -a "x-php" | cut -d '' -f 1
}
listfiles | xargs grep -l "eval("
@samba
samba / struct.py
Created May 10, 2013 06:01
Python class for masking dictionaries as objects
# Generic data structure for mapping named arguments directly to properties
# More readable code than using dictionaries...
# Usage:
# mystruct = Struct(value1 = "x", value2 = "y", value3 = "z")
# print mystruct.value1
# >> x
class Struct(object):
def __init__(self, **entries):
Struct.update(self, entries)
@samba
samba / find-dirty-git.sh
Created April 9, 2013 17:28
Find dirty Git directories (i.e. projects with uncommitted changes)
#!/bin/sh
git_command_context () {
cd $1;
shift;
is_workdir=`git rev-parse --is-inside-work-tree`
is_gitdir=`git rev-parse --is-inside-git-dir`
is_basedir=`git rev-parse --is-bare-repository`
my_gitdir=`git rev-parse --git-dir`
git "--work-tree=`pwd`" "--git-dir=${my_gitdir}" "$@"
@samba
samba / tricks.sh
Last active December 15, 2015 17:49
Shell tricks
#!/bin/sh
# Show duplicate files (compared by MD5 hash)
find ./ -type f -print0 | xargs -0 md5sum | sort | uniq -w 32 -D
# Remove smart-quotes from a buffer/file
sed "s/[”“]/\"/g; s/[’‘]/'/g"
# Rename a series of files (e.g. restore backups) by regular expression in OS X
find ./ -type f -name '*.bak' -print | sed -E 's/(.*)\.bak$/mv "&" "\1"/' > rename.sh
@samba
samba / replace.py
Last active December 13, 2015 17:19
PERL-style RegExp substitution in Python (but within "s/.../.../", uses Python syntax)
#!/usr/bin/env python
# Python support for PERL's shorthand of pattern substitution (s/.../.../)
# Supports flags:
# i => case insensitive
# m => multiline match (caret and dollar represent line terminations, not whole-string)
# s => "dot-all" - dot matches everything, including new-line
# g => "global" - replace every instance (without this, only the first)
import re
@samba
samba / crypto.sh
Last active December 12, 2015 06:08
OpenSSL for file encryption
## to encrypt
openssl aes-256-cbc -e -in plaintext.txt -out crypted.blob
## to decrypt
openssl aes-256-cbc -d -in crypted.blob -out plaintext.txt
@samba
samba / vm.sh
Last active December 29, 2016 23:18
Virtual Box headless - shell shortcuts
#!/bin/bash
# VirtualBox control handler
# OS X shell context (BSD utilities)
# Simplifies VBoxHeadless and VBoxManage calls.
# In my use-case, the primary objective is to
# Usage:
# vm.sh list lists all your VMs
@samba
samba / simpleformat.140bytes.js
Last active October 13, 2015 18:08
Simple Javascript String Formatter
// This one only supports the '{0}' syntax for now...
function _format(p){var x = arguments;return p.replace(/\{([0-9]+)\}/g, function($0,n){ return x[1+Number(n)] })}