Skip to content

Instantly share code, notes, and snippets.

@mhluska
mhluska / sync-backup-drive.sh
Last active December 17, 2015 18:18
Used with udev to sync a backup drive.
#!/bin/bash
drive_name="${1}"
if [ -z "${drive_name}" ]; then
exit 1
fi
USERNAME='username'
SOURCE_DIR="/home/${USERNAME}/Backup"
@mhluska
mhluska / sync-backup-drive-wrapper.sh
Created May 26, 2013 05:23
Used with udev to sync a backup drive.
#!/bin/bash
# Find the absolute path of the script.
# See http://stackoverflow.com/a/246128/659910.
DIR="$( cd "$( dirname "$0" )" && pwd )"
# This script is called by `udev` and needs to complete quickly, so we
# background another script. `${1}` contains the device name.
nohup "${DIR}/sync-backup-drive.sh" ${1} >/dev/null 2>&1 &
@mhluska
mhluska / pass.sh
Last active December 17, 2015 18:18
Bash wrapper that makes `pwsafe` easier to work with. Add it to your `.bash_aliases` file.
function pass {
# If no arguments are passed we just call `pwsafe`. This is useful when we
# want to list all available passwords by typing `pass`.
if [ "${#}" -lt 1 ]; then
pwsafe
return
fi
pwsafe -qp ${*} | perl -ne 'chomp and print' | xclip -sel clip
}
@mhluska
mhluska / backup-drive.rules
Last active December 17, 2015 18:18
Executes the script `sync-backup-drive-wrapper.sh` upon plugging in a USB drive.
ENV{ID_FS_LABEL_ENC}=="?*", ACTION=="add", SUBSYSTEMS=="usb", \
ATTRS{idVendor}=="1058", ATTRS{idProduct}=="0a78", \
RUN+="/home/username/bin/sync-backup-drive-wrapper.sh %k"
@mhluska
mhluska / incremental-filenames.sh
Created April 21, 2013 04:57
Give all the files in a directory incremental file names based on creation date. Example: img_000.jpg, img_001.jpg, etc.
#!/bin/bash
set -e
NAME=$(basename ${0})
USAGE="Usage: ${NAME} source target [prefix]"
function error {
echo "${NAME}: ${1:-'Unknown Error'}" 1>&2
echo ${USAGE} 1>&2
@mhluska
mhluska / commit-date.sh
Created April 2, 2013 19:11
Change the author and commit dates of a commit.
#!/bin/bash
git filter-branch -f --env-filter \
"if [ \$GIT_COMMIT = ${1} ]
then
export GIT_AUTHOR_DATE=\"${2}\"
export GIT_COMMITTER_DATE=\"${2}\"
fi"
@mhluska
mhluska / test.js
Created December 17, 2012 12:22
Compiled JavaScript not being executed. Grunt-requirejs issue: https://github.com/asciidisco/grunt-requirejs/issues/44.
/**
* almond 0.2.3 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
//Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed.
/*jslint sloppy: true */
/*global setTimeout: false */
@mhluska
mhluska / foo.c
Created October 10, 2012 21:09
Pipe and file write test
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main() {
int c, i;
i = 0;
char buffer[256];
FILE *file;