Skip to content

Instantly share code, notes, and snippets.

@jmiserez
jmiserez / update_annotations.sh
Created May 28, 2014 18:13
Annotate LectureNotes PDFs
#!/bin/bash
mkdir /tmp/magick_tmp
MAGICK_TMPDIR=/tmp/magick_tmp
export MAGICK_TMPDIR
LECTURENOTESDIR=/home/ec2-user/Dropbox/LectureNotes/
cd $LECTURENOTESDIR
process_directory() {
@jmiserez
jmiserez / myip.sh
Created December 10, 2014 22:07
myip.sh
#!/bin/bash
dig +short @resolver1.opendns.com myip.opendns.com
@jmiserez
jmiserez / pidtree.sh
Last active October 6, 2015 16:22
Find child processes (and their children, etc.) with one ps call (no race conditions)
#!/bin/bash
# Original idea: http://superuser.com/a/784102/59125
pidtree(){
pids_for_ppid=()
while read pid ppid; do
pids_for_ppid[$ppid]+=" $pid"
done < <(ps -e -o pid,ppid --no-headers)
@jmiserez
jmiserez / xenvm_decrypt_backup.sh
Created December 4, 2015 18:59
Decrypt files encrypted by xenvm_backup_encrypted.sh (https://gist.github.com/jmiserez/f7771d0c82455128839d)
#!/bin/bash
#
# xenvm_decrypt_backup.sh
#
# Author: Jeremie Miserez <jeremie@miserez.org>
# Latest version: https://gist.github.com/jmiserez/11a8aafeee9256645ac5
#
# This script will decrypt encrypted images generated by xenvm_backup_encrypted.sh,
# (https://gist.github.com/jmiserez/f7771d0c82455128839d), when given a .key.enc file
# and if all related files are in the same directory as the .key.enc file.
@jmiserez
jmiserez / xenvm_backup_encrypted.sh
Last active January 6, 2016 13:53
Offline backup (cold, with shutdown/startup) of a XenServer VM with gzip, rate-limiting (pv), and public key + AES256 encryption (openssl). See xenvm_decrypt_backup.sh (https://gist.github.com/jmiserez/11a8aafeee9256645ac5) for decryption. Note: You *must* trust both the remote and local server, as well as the SSH connection.
#!/bin/bash
#
# xenvm_backup_encrypted.sh
#
# Author: Jeremie Miserez <jeremie@miserez.org>
# Latest version: https://gist.github.com/jmiserez/f7771d0c82455128839d
#
# This script will:
# 1. Connect to a remote XenServer server over SSH
# 2. Shutdown the specified VM
@jmiserez
jmiserez / noip
Last active April 17, 2016 14:19 — forked from PaulMaddox/noip
Dynamic DNS for Amazon Route53, using cli53 and remote OpenDNS resolver
#!/bin/bash
# Original author: https://gist.github.com/PaulMaddox/9210543
# Requires cli53 to be installed
# https://github.com/barnybug/cli53
DNS_NAME="home";
DNS_ZONE="example.com";
# not needed, we have a ~/.boto file
@jmiserez
jmiserez / keybase.md
Last active May 11, 2016 06:13
keybase.md

Keybase proof

I hereby claim:

  • I am jmiserez on github.
  • I am jmiserez (https://keybase.io/jmiserez) on keybase.
  • I have a public key ASB1Z3r-6WbG1JJ12os9xUuXhFMe5QElabQLKWD_M29nPQo

To claim this, I am signing this object:

@jmiserez
jmiserez / bash_run_parallel.sh
Last active May 18, 2016 09:17
Run bash functions in parallel for a list of directories. Emulates GNU parallel (grouped output) but only uses standard tools (find, xargs, bash, etc.)
#!/bin/bash
# reliable way to get the directory where this file is stored
SCRIPT=$(readlink -f $0)
export SCRIPTPATH=`dirname $SCRIPT`
SCRIPTNAME=$(basename "$SCRIPT")
if [ "$#" -lt 1 ]
then
echo "Usage: ./$SCRIPTNAME <root folder path> [<pattern for matching directories within root directory, default is \"*\">]"
echo "or ./$SCRIPTNAME -i <single directory path to process>"
#!/bin/bash
# Make default camera /dev/video0 point to the "best" camera present.
# Source: Jason Eisner http://askubuntu.com/a/520857/145754
# on question http://askubuntu.com/questions/396952/how-to-change-the-default-webcam-changing-dfaults-in-multimedia-selctor-not-wor
setdefaultwebcam() {
if [ -h /dev/video0 ]; then
sudo rm /dev/video0 # not first run: remove our old symlink
elif [ -e /dev/video0 ]; then
sudo mv /dev/video0 /dev/video0.original # first run: rename original video0
@jmiserez
jmiserez / vm.c
Created January 6, 2016 14:54
X86 (subset) interpreter, prototype. Reads instructions from plaintext file, instructions separated by spaces.
/*
* vm.c - Simple X86 interpreter
*
* Copyright (c) 2013, Jeremie Miserez <jeremie@miserez.org>
*/
/*
* Highlights/Features not specified in assignment
* ===============================================
* - Memory simulation of all 4GB with paging