Skip to content

Instantly share code, notes, and snippets.

@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;
};
};
@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 / gist:5232531
Created March 24, 2013 16:23
~/.gitignore OS X-specific fragment
# OS X
.DS_Store
._*
.Spotlight-V100
Icon?
.Trashes
@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 / 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 / SetFont.java
Created July 12, 2013 15:53
Setting a custom typeface on Android.
TextView tv = (TextView) findViewById(R.id.someTextView);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/fontname.otf");
tv.setTypeface(tf);
const int main = 0xC3C031;
@rahulg
rahulg / rmbstatus.py
Last active August 29, 2015 14:16
Poll the Apple Store for shipping status of the 12" MacBook
#!/usr/bin/env python
# coding: utf-8
import json
import re
import sys
try:
import urllib.request as _urllib
except ImportError:
@rahulg
rahulg / chmow
Created May 8, 2015 02:33
chmod / chown wrapper
#!/usr/bin/env bash
#
# Installation:
# Copy chmow to some directory in your path, like /usr/local/bin
# cd <directory_above>
# chmod 0755 chmow
# ln -s chmow chmod
# ln -s chmow chown
set -e -u
@rahulg
rahulg / twitch-chat.py
Created June 6, 2016 08:47
Dump twitch chat replays
import datetime
import json
import re
import sys
import urllib.request
video_id = sys.argv[1]
try:
start_offset = int(sys.argv[1])
except (IndexError, ValueError):