Skip to content

Instantly share code, notes, and snippets.

@rahulg
rahulg / goinit
Last active December 18, 2015 23:08
Initialise a golang project by setting up the directory structure and creating the virtualenv-like activate script.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $(basename "${0}") <project>"
exit 1
fi
mkdir -p "${1}"/{,src,pkg,bin}
cat << 'EOF' > "${1}/activate"
@rahulg
rahulg / activate
Created June 25, 2013 14:30
Virtualenv-like activate & deactivate for golang. Source this file the normal way from bash to activate the GOPATH, deactivate to deactivate.
export GOPATH="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
export OLDPS1=$PS1
export PS1="[go:$(basename $GOPATH)] $PS1"
alias gcd="cd $GOPATH"
deactivate() {
export PS1=$OLDPS1
unset GOPATH
unset OLDPS1
unalias gcd
unset deactivate
@rahulg
rahulg / gist:5232531
Created March 24, 2013 16:23
~/.gitignore OS X-specific fragment
# OS X
.DS_Store
._*
.Spotlight-V100
Icon?
.Trashes
@rahulg
rahulg / _x_segfault.c
Created October 4, 2012 06:22
Free segfaults for everyone!
#define _x_segfault() \
__asm__ __volatile__ ("movq $0, %%r11\n" \
"movq (%%r11), %%r10\n" \
: \
: \
: "%r11", "%r10" \
)
@rahulg
rahulg / nestedmess.cc
Created September 9, 2012 14:02
This nested stuff is ugly.
struct Pixel
{
union
{
struct {
uint8_t red, green, blue, alpha;
};
uint32_t raw;
};
};