Skip to content

Instantly share code, notes, and snippets.

View oxyc's full-sized avatar

oxyc

View GitHub Profile
@oxyc
oxyc / gist:1178052
Created August 29, 2011 09:04
Automount encrypted USB drive containg ssh keys.
# Based on several guides, primarily:
# http://ninetynine.be/blog/2009/03/ubuntu-backup-to-usb-drive-on-mount/
# /etc/udev/rules.d/81-local.rules
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="…", ATTRS{idProduct}=="…", RUN+="/usr/bin/truecrypt_mount.sh"
ACTION=="remove", SUBSYSTEMS=="usb", ATTRS{idVendor}=="…", ATTRS{idProduct}=="…", RUN+="/usr/bin/truecrypt_unmount.sh"
# /usr/bin/truecrypt_mount.sh
truecrypt /dev/disk/by-id/… -k … --protect-hidden=no --password= /mnt/houdini/
<?php
/**
* Implements hook_form_alter().
*
* Redirects user logins to the front page.
*/
function HOOK_form_user_login_alter(&$form, &$form_state) {
$form['#action'] = url('user', array('query' => array('destination' => '<front>')));
}
@oxyc
oxyc / .bash_profile
Created January 10, 2012 17:51
Bash prompt
# Logic stolen from https://github.com/gf3/dotfiles
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
prompt_desc() {
#!/bin/bash
# $HOME/bin/track
# Put the following exports in your .profile
# export TRACK_SSH="ssh genero" # Local host only
# export TRACK_LOG_FILE="$HOME/.timetracker.log" # Should exist on all hosts
if [[ "$TRACK_SSH" ]]; then log_content="$TRACK_SSH cat \$TRACK_LOG_FILE"
else log_content="cat $TRACK_LOG_FILE"; fi
output() {
@oxyc
oxyc / .vimrc
Created February 21, 2012 11:29
function! SetWPConfig ()
setlocal shiftwidth=4 softtabstop=4 tabstop=4 noexpandtab
setlocal listchars=trail:·
endfunction
function! SetDrupalConfig ()
setlocal shiftwidth=2 softtabstop=2 tabstop=2 expandtab
setlocal listchars=tab:▸\ ,trail:·
endfunction
" Wordpress files
@oxyc
oxyc / ssh.exp
Created February 23, 2012 06:23
#!/usr/bin/expect -f
# Usage:
# ./ssh.exp USER PASS IDENTITY_FILE HOST COMMAND
set username [lrange $argv 0 0]
set password [lrange $argv 1 1]
set identity_file [lrange $argv 2 2]
set host [lrange $argv 3 3]
set command [lrange $argv 4 4]
set timeout -1
$view = views_get_view('news');
$view->set_display('block_1');
if (!in_array($language->language, array('fi', 'sv'))) {
$view->set_item('block_1', 'filter', 'language_2', NULL);
$view->add_item('block_1', 'filter', 'node', 'language', array('value' => array('value' => 'fi')));
}
$previous_articles = $view->render();
mkdir phpMyAdmin && wget https://github.com/phpmyadmin/phpmyadmin/tarball/RELEASE_3_4_10_1 -O - | tar xzv --directory=phpMyAdmin --strip-components 1
function! DrupalImplementsComment ()
let filename = bufname("%")
let dot = stridx(filename, ".")
let module = strpart(filename, 0, dot)
let current_line = getline(".")
let hook_idx = matchend(current_line, "function " . module . "_")
if !empty(module) && hook_idx != -1
let hook_length = match(current_line, "(") - hook_idx
let hook_name = strpart(current_line, hook_idx, hook_length)
call DoxygenComment ("Implements hook_" . hook_name . "().")
diff --git a/vimrc b/vimrc
index c90fb0c..a81f505 100644
--- a/vimrc
+++ b/vimrc
@@ -14,7 +14,7 @@ call pathogen#infect()
set shiftwidth=2 " auto-indent amount when using cindent, etc
set softtabstop=2 " how many spaces is a tab
-set tabstop=4 " real tabs should be 4
+set tabstop=2 " real tabs should be 4