Skip to content

Instantly share code, notes, and snippets.

@snim2
snim2 / gist:192726
Created September 24, 2009 13:19
Generic Makefile for OCaml projects
#
# Generic Makefile for OCaml projects.
#
# Sarah Mount
# September 2009.
#
# Code should be structured roughly like this:
#
# project /
# Makefile
@snim2
snim2 / fig.tex
Created September 24, 2009 13:24
Placement and scaling of figures with LaTeX and the graphicx package
%%% Figure placement and scaling with LaTeX and graphicx.
%%%
%%% Sarah Mount.
%%%
%%% Replace all UPPERCASE text with your own.
%%% To change scaling, replace the "0.6\columnwidth" with your preferred size.
%%%
%%% "Hhtbp" is the preference of the author for figure placement:
%%% Place _H_ere > Place _h_ere if possible > place at _t_op of page >
%%% place at _b_ottom of page > place on a _p_age of figures.
@snim2
snim2 / dis-example.py
Created September 24, 2009 15:01
Using the Python disassembler to analyse uncaught exceptions
>>> import dis
>>> 1 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
>>> dis.dis()
1 0 LOAD_CONST 0 (1)
3 LOAD_CONST 1 (0)
--> 6 BINARY_DIVIDE
7 PRINT_EXPR
@snim2
snim2 / tab2space.el
Created November 1, 2009 11:44
Convert tabs to spaces in Emacs
;;; Turn tabs to spaces
(defun tabs-to-spaces (&optional begin end)
"Turn all tabs in a region into four spaces."
(interactive "r")
(save-excursion
(if mark-active
(replace-regexp "\t" " " nil (point) (mark))
(replace-regexp "\t" " " nil (point-min) (point-max))
)
)
@snim2
snim2 / csp-pygame.py
Created November 29, 2009 01:11
Use a python-csp process to render images to Pygame
@process
def Drawme(channel, _process=None):
import pygame
# Constants
WIDTH, HEIGHT = 512, 256
# Open window
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0)
QUIT = False
while not QUIT:
@snim2
snim2 / spaces2tabs4.el
Created December 12, 2009 21:37
Convert spaces to tabs in Emacs
(defun four-spaces-to-tab (&optional begin end)
"Replace four spaces with a tab in a region."
(interactive "r")
(save-excursion
(if mark-active
(replace-regexp " " "\t" nil (point) (mark))
(replace-regexp " " "\t" nil (point-min) (point-max))
)
)
)
@snim2
snim2 / camerastream.py
Created December 13, 2009 00:00
Display the output of a webcam using Python and Pygame
import pygame
import pygame.camera
from pygame.locals import *
DEVICE = '/dev/video0'
SIZE = (640, 480)
FILENAME = 'capture.png'
def camstream():
pygame.init()
@snim2
snim2 / howl.py
Created December 13, 2009 21:46
Access the Howl web service for the Internet of Things via the command line
#!/bin/env python
"""
Execute a single Howl command.
Usage:
$ python howl.py --help
Usage: howl.py [options]
# Fix Eclipse on Ubuntu Karmic
export GDK_NATIVE_WINDOWS=1
#!/usr/bin/env python
def listexns(mod):
module = __import__(mod)
exns = []
for name in module.__dict__:
if (isinstance(module.__dict__[name], Exception) or
name.endswith('Error')):
exns.append(name)
for name in exns: