Skip to content

Instantly share code, notes, and snippets.

View timofurrer's full-sized avatar
Commits are my own. Powered by coffee.

Timo Furrer timofurrer

Commits are my own. Powered by coffee.
View GitHub Profile
@timofurrer
timofurrer / select.sh
Created February 6, 2013 09:10
bash select menu example (choose block device which matches pattern /dev/sd?)
#!/bin/bash
PS3="Choose device: "
select dev in /dev/sd?
do
echo you picked device $dev \($REPLY\)
break
done
@timofurrer
timofurrer / gist:4706153
Created February 4, 2013 11:04
mount /dev and /proc in chroot environment
mount -t proc none /mnt/chroot/proc
mount -o bind /dev /mnt/chroot/dev
@timofurrer
timofurrer / gist:4087558
Created November 16, 2012 13:58
bash function to show last error code in bash prompt
function __return_value()
{
ret=$?
if [[ "$ret" -ne "0" ]]; then
echo -e "\033[1;31m[Error: \033[0;31m$ret\033[1;31m]\033[00m"
fi
}
@timofurrer
timofurrer / gist:3924126
Created October 20, 2012 17:27
Remove old linux images, headers and modules
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
@timofurrer
timofurrer / gist:2931425
Created June 14, 2012 16:46
Apple Keyboard Xmodmap
! Swap Alt and Cmd keys.
keycode 37 = Control_L
keycode 49 = less greater less greater backslash brokenbar bar
keycode 133 = Alt_L Meta_L
keycode 64 = Super_L
keycode 108 = Super_R
keycode 134 = ISO_Level3_Shift Multi_key
keycode 105 = Control_R Multi_key
clear Shift
clear Lock
@timofurrer
timofurrer / gcc call
Created June 4, 2012 12:29
make use of anonym union in struct in c
gcc -Wall -o union union.c
@timofurrer
timofurrer / gist:2725779
Created May 18, 2012 15:11
C++ convert string to every type using template function
template <typename T>
T ConvertString( const std::string &data )
{
if( !data.empty( ))
{
T ret;
std::istringstream iss( data );
if( data.find( "0x" ) != std::string::npos )
{
iss >> std::hex >> ret;
@timofurrer
timofurrer / compile with g
Created May 5, 2012 11:50
range-based for loop in c++11
g++ -o for for.cpp -std=c++0x -Wall
@timofurrer
timofurrer / asm.s
Created April 21, 2012 10:07
Minimal Assembly "Hello World"
.data
hello:
.string "Hallo, Welt!\n"
.text
.global _start
_start:
movl $4, %eax /* write() */
movl $1, %ebx /* 1 = stdout */
movl $hello, %ecx /* Adresse von hello */
@timofurrer
timofurrer / gist:2124946
Created March 19, 2012 19:18
Python permutations of a list
#!/usr/bin/python3.2
import itertools
print( list( itertools.permutations( [1, 2, 3, 4], 2) ) )