Skip to content

Instantly share code, notes, and snippets.

View n1ywb's full-sized avatar

Jeff Laughlin n1ywb

View GitHub Profile
@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:
@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 / 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 / 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)
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 / git-working-history
Last active August 29, 2015 14:25 — forked from gabro/git-working-history
Github-like working directory history
#!/bin/bash
FILES=`git ls-tree --name-only HEAD .`
MAXLEN=0
IFS=$(echo -en "\n\b")
for f in $FILES; do
if [ ${#f} -gt $MAXLEN ]; then
MAXLEN=${#f}
fi
done
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
TC5->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE;
while (TC5->COUNT16.STATUS.bit.SYNCBUSY);
TC5->COUNT16.CTRLA.reg = TC_CTRLA_SWRST;
while (TC5->COUNT16.STATUS.bit.SYNCBUSY);
@n1ywb
n1ywb / sketch.ino
Last active January 1, 2018 16:00
feather m0 samd21 externally clocked counter
/*
WiFi Web Server
A simple web server that shows the value of the analog input pins.
using a WiFi shield.
This example is written for a network using WPA encryption. For
WEP or WPA, change the WiFi.begin() call accordingly.
Circuit:
#!/usr/bin/env bash
wget http://mything.com/mything.tgz
tar xzf mything.tgz
cd mything
make all; make test; sudo make install
echo -e '#!/usr/bin/env bash\ninsmod mything.so' > /etc/rc.local