Skip to content

Instantly share code, notes, and snippets.

View stuaxo's full-sized avatar
💭
 

Stuart Axon stuaxo

💭
 
View GitHub Profile
@mgunneras
mgunneras / pull_zmq.py
Created August 28, 2011 16:33
Publish data from file or stdin to a zmq socket
#! /usr/bin/env python
"""
Prints data from zmq PULL socket to stdout
"""
import zmq
import sys
def get_socket(host, port):
context = zmq.Context()
@gregburek
gregburek / rateLimitDecorator.py
Created December 7, 2011 01:51
Rate limiting function calls with Python Decorators
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
@techtonik
techtonik / caller_name.py
Created March 21, 2012 19:29
Python - inspect - Get full caller name (package.module.function)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.
@m14t
m14t / fix_github_https_repo.sh
Created July 5, 2012 21:57
Convert HTTPS github clones to use SSH
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
@uhop
uhop / gist:3259255
Created August 4, 2012 18:41
Bezier Shaders & Vector openGL rendering
@bfroehle
bfroehle / .gitignore
Created August 25, 2012 01:12
Bitey Magic, an IPython extension
*.py[oc]
@wolfv
wolfv / bgimage-python-gtk3.py
Created August 25, 2012 20:51
Python GTK 3 Pattern Tiling
#!/usr/bin/env python
from gi.repository import Gtk, Gdk
import cairo
def draw_background( widget, context):
surface = cairo.ImageSurface.create_from_png('bg.png')
sp = cairo.SurfacePattern(surface)
anonymous
anonymous / gist:3986620
Created October 31, 2012 11:46
pixel plotting template
#include <gtk/gtk.h>
#include <stdlib.h>
#include <stdio.h>
void put_pixel(GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue, guchar alpha);
struct widgets
{
GtkWidget *window, *image;
GdkPixbuf *pixbuf;
@jawa0
jawa0 / loadTexture.py
Created November 2, 2012 17:39
Use the Python Imaging Library (PIL), and NumPy to read an image into an OpenGL texture
from OpenGL.GL import *
import Image
import numpy
imname = 'uv-grey.jpg'
# glTexImage2D expects the first element of the image data to be the bottom-left corner of the image.
# Subsequent elements go left to right, with subsequent lines going from bottom to top.
#
# However, the image data was created with PIL Image tostring and numpy's fromstring, which means we
@schlamar
schlamar / gist:4149031
Created November 26, 2012 16:11
pygtk + pyglet
#!/usr/bin/python
import sys
import time
import math
import gtk
import gobject
import pyglet
import pyglet.gl as gl