Skip to content

Instantly share code, notes, and snippets.

View n1ywb's full-sized avatar

Jeff Laughlin n1ywb

View GitHub Profile
import math
from qgis.core import *
from processing.core.VectorWriter import VectorWriter
##degspacing=number 30
##distance=number 5000000
##numrings=number 4
##centerx=number 0.0
##centery=number 0.0
@n1ywb
n1ywb / dataobject.py
Created January 2, 2013 15:55
Non-functional concept of the observer pattern for Twisted python objects using descriptors and metaclasses.
lass DataObject(object):
def to_html(self, updated_station):
self.html = "whatever"
self.on_html_update.callback(self.html)
def update(self, updated_stations):
self.json = self.to_json(updated_stations)
self.on_json_update.callback(self.json)
@n1ywb
n1ywb / gist:3925430
Created October 21, 2012 01:48
Example use case for functools.partial
def render(self, request):
# Encapsulate the function call we wish to make into a partial object.
# Now if we change the function name or arguments we only change them
# in ONE place, instead of the two places this function is called from.
f = functools.partial(self.dlstatus.stn_to_json, self.id)
try:
request.setHeader("content-type", "application/json")
if request.args.has_key('callback'):
request.setHeader("content-type", "application/javascript")
return request.args['callback'][0] + '(' +
@n1ywb
n1ywb / crap.py
Created October 9, 2012 19:41
Antelope C API Python bindings with ctypes
#!/usr/bin/env python
from pprint import pprint
from ctypes import CDLL, create_string_buffer, string_at
from ctypes import c_bool, c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort
from ctypes import c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong
from ctypes import c_float, c_double, c_longdouble, c_char_p, c_wchar_p
from ctypes import c_void_p, POINTER, pointer, byref
__all__ = ['orbreap_timeout']
@n1ywb
n1ywb / retries.py
Created May 1, 2012 17:48
A Python function retrying decorator
#!/usr/bin/env python
#
# Copyright 2012 by Jeff Laughlin Consulting LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: