Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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 / unmount.sh
Last active December 17, 2015 20:39
Unmount and spin-down a drive.
#!/bin/bash
DRIVE_NAME=${1:-Backup}
if [ -z "${DRIVE_NAME}" ]; then
echo 'No drive found.' 1>&2
exit 1
fi
drive_dir="$(mount -l | grep "\[${DRIVE_NAME}\]" | awk '{print $1}')"
@mhluska
mhluska / xprop-output.txt
Last active December 18, 2015 02:39
Xprop output from `xprop -notype -id "62914566"` (in response to http://unix.stackexchange.com/a/78174/40453)
_MOTIF_WM_HINTS = 0x2, 0x0, 0x80, 0x0, 0x0
_NET_WM_ICON_GEOMETRY = 0, 153, 48, 48
_NET_WM_DESKTOP_FILE = "/usr/share/applications/gnome-terminal.desktop"
_COMPIZ_WM_WINDOW_BLUR_DECOR = 4, 0, 5, 4, -28, 6, -4, -27, 5, 2, -27, 6, -2, -26, 5, 1, -26, 6, -1, -25, 5, 0, -25, 6, 0, -23, 5, -1, -23, 6, 1, 0, 9, -1, 0, 10, 1, 1, 5, -1, 0, 9, 0, 0, 6, 0, 0, 10, 1, 0
_UBUNTU_APPMENU_OBJECT_PATH = "/com/canonical/menu/3C00006"
_UBUNTU_APPMENU_UNIQUE_NAME = ":1.86"
XKLAVIER_STATE = 0, 0
WM_STATE:
window state: Normal
icon window: 0x0