Skip to content

Instantly share code, notes, and snippets.

@kmcallister
kmcallister / dnsmasq.conf
Created March 20, 2012 07:01
Providing WiFi Internet connection to wired Ethernet on Linux
interface=eth0
dhcp-range=10.5.0.50,10.5.0.150,12h
@kmcallister
kmcallister / grub.cfg
Created April 4, 2012 21:37
boot ubuntu iso from grub2
submenu "Ubuntu" {
submenu "10.04 LTS Lucid Lynx" {
submenu amd64 {
menuentry live {
loopback loop /boot/iso/ubuntu-10.04-desktop-amd64.iso
linux (loop)/casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash iso-scan/filename=/boot/iso/ubuntu-10.04-desktop-amd64.iso noeject noprompt --
initrd (loop)/casper/initrd.lz
@kmcallister
kmcallister / gist:2382628
Created April 14, 2012 07:26
clock_gettime
// gcc -Wall -lrt -std=c99 -o foo foo.c
#define _POSIX_C_SOURCE 199309L
#include <time.h>
int main() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return 0;
@kmcallister
kmcallister / gist:2521834
Created April 28, 2012 20:37
update mosh repo
#!/bin/bash -e
git fetch keithw
was_master=
if out=$(git symbolic-ref HEAD); then
if [ "$out" = "refs/heads/master" ]; then
git checkout HEAD@{0}
was_master=yes
fi
@kmcallister
kmcallister / gist:2651938
Created May 10, 2012 08:44
testing 'æ'
#define _XOPEN_SOURCE
#include <wchar.h>
#include <locale.h>
#include <stdio.h>
int main() {
setlocale(LC_ALL, "");
printf("%d\n", wcwidth(0xE6));
return 0;
}
@kmcallister
kmcallister / gist:2695693
Created May 14, 2012 18:54
functools.partial on method
import functools
class Foo(object):
def __init__(self, name):
self.name = name
def add(self, x, y):
print '%s: %d + %d = %d' % (self.name, x, y, x+y)
obj = Foo('bar')
#!/usr/bin/env python
from ctypes import *
for ln in open('/proc/self/maps'):
if "[vdso]" in ln:
start, end = [int(x,16) for x in ln.split()[0].split('-')]
CDLL("libc.so.6").write(1, c_void_p(start), end-start)
break
@kmcallister
kmcallister / gist:2951474
Created June 18, 2012 23:45
Haskell/C polyglot
int x[] = {-1};
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
//-}(); main = putStrLn "Hello, world!"
@kmcallister
kmcallister / print.asm
Created June 22, 2012 08:59
printable COM file
; $ nasm -fbin print.asm -o print.com
; $ cat print.com
; h<|XP- {P_X(%GGG(%GGWZ- sh LI!XI!Hello, DOS!$
;
; C:\>PRINT.COM
; Hello, DOS!
org 100h
; di <- replace
@kmcallister
kmcallister / gist:3306591
Created August 9, 2012 18:03
print all link hrefs
import sys
from BeautifulSoup import BeautifulSoup
for a in BeautifulSoup(sys.stdin).findAll('a'):
print a['href']