Skip to content

Instantly share code, notes, and snippets.

@samba
samba / nginx-cache.sh
Created June 15, 2012 18:24
Nginx Cache Search/Removal
#!/bin/sh
# Nginx Cache Manager (search, remove content by URL or grep)
# NOTE:
# in my nginx config, I use:
# proxy_cache_key $scheme://$host$uri$is_args$args@$remote_user;
# ... which facilitates easier searching of cache files
cachefiles () {
find /var/lib/nginx/cache -type f $@
}
@samba
samba / setmagic.js
Created June 28, 2012 03:31
Simple set handling for Javascript, with "in" operator
/* Set theory implementation, woot!
* (c) Sam Briesemeister, 2012
*
*
* Uses Javascript objects' properties as a shortcut for determining set content.
*
* Elements must be string-like or numeric.
*
* Usage:
*
@samba
samba / dd-local-monitor.sh
Created August 27, 2012 15:41
DD Imaging util
#!/bin/sh
# usage:
# sudo dd-local-monitor.sh if=/dev/sda bs=24M | gzip > /mnt/external/myimage.blob.gz
main () {
echo "# dd: $@" >&2
dd $@ &
@samba
samba / lib.csv.js
Created August 30, 2012 23:42
CSV Parser in Javascript
/* CSV parser
* (c) Sam Briesemeister, 2012
*
* Features:
* - Parses CSV through a sequential tokenizer
* - Supports alternative field separator and quote characters
* - Ignores empty lines and comments (lines starting with #)
* - Provides label support through lookup function
*
* Usage:
@samba
samba / csv-to-json.py
Created November 25, 2012 07:53
Very simple CSV to JSON converter
#!/usr/bin/env python
# Very simple CSV to JSON converter
# Supports CSV labels
# Usage:
# (without labels)
# csv-to-json.py ./data.csv > ./data.json
# like: [ [ 1, 2, 3 ] ]
# (with labels)
# csv-to-json.py -l ./data.csv > ./data.json
@samba
samba / find_superblock.sh
Created November 28, 2012 05:38
Superblock finder
#!/bin/sh
# A tool to find superblocks in an EXT4 volume (probably easily adapted for EXT2,3)
# The usecase for this tool is likely pretty narrow...
# I have an LVM volume on a RAID array that was incorrectly reassembled (i.e. recreated)
# in the wrong order (I think), and I'm trying to recover from it, but it's unrecognizable
# as a filesystem since the primary superblock is missing.
# This tool identifies all (seemingly) valid superblocks in a volume, though using them may
# introduce other errors if your filesystem is badly damaged. USE WITH CAUTION.
# The goal is to estimate how far offset the superblocks are and if disc order in the array
@samba
samba / restore.sh
Created November 28, 2012 07:14
Compressed disc image restoration with "threading"
#!/bin/sh
# Assumes images are broken out into 1024mb chunks, separately gzipped,
# stored as ./image/image.X.blob.gz, where X is an integer (0...).
# Decompresses and writes 6 in parallel (i.e. threading) since Gzip is slow.
DEVICE=$1
sectionsize=1024
maxthreads=5
curthreads=0
@samba
samba / host_setup.sh
Created December 6, 2012 21:33
LXC Setup script
#!/bin/bash
# THIS IS A WORK IN PROGRESS, might break things.
# Sets up LXC host configuration in AWS EC2 environments
# Reference: http://www.activestate.com/blog/2011/10/virtualization-ec2-cloud-using-lxc
# Exit NOW because we don't want to blow anything up outside our test systems
# (This is being drafted in a production environment.)
exit 1
echo 'none /sys/fs/cgroup cgroup defaults 0 0' >> /etc/fstab
@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)] })}
@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