Skip to content

Instantly share code, notes, and snippets.

View hughsaunders's full-sized avatar

Hugh Saunders hughsaunders

View GitHub Profile
@hughsaunders
hughsaunders / django_search_view.py
Created June 17, 2011 12:18
Search View using Julien Phalip's technique.
def search(request):
search_string=request.POST['search_string']
if re.match(r'^\s*$',search_string): return redirect('home')
results=[]
search_fields=('id','name')
equipment_models = \
[model for model in django.db.models.get_models() if\
model._meta.db_table.startswith("equipment_")]
for model in equipment_models:
query=halipsearch.get_query(search_string,search_fields)
@hughsaunders
hughsaunders / LDAPRemoteUserBackend.py
Created June 23, 2011 15:12
Django RemoteUserBackend for REMOTE_USER authentication and LDAP authorisation
# LDAP Remote User Backend for Django 1.3
# Hugh Saunders - hugh@wherenow.org
# Written for the Surgical Materials Testing Laboratory - http://smtl.co.uk
# 2011
from django.contrib.auth.backends import RemoteUserBackend
import settings as s
import ldap
class LDAPRemoteUserBackend(RemoteUserBackend):
@hughsaunders
hughsaunders / base_site.html
Created June 28, 2011 17:13
Django Admin Template Override for adding edit popups to foreign key fields.
{%extends "admin/base.html" %}
{% block extrahead %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.add-another').each(function(i,o){
select_obj=$(o).parent().find('select')[0];
item_id=select_obj.options[select_obj.selectedIndex].value;
@hughsaunders
hughsaunders / HuntGroupReminder.py
Created August 7, 2011 23:31
An annoying program to display a fullscreen reminder message before and after screen lock.
#!/usr/bin/env python
# HuntGroupReminder - Hugh Saunders 2011
# This is probably the most annoying program ever.
# It pops up a window before and after screen locking in order to remind me to login/logout of my desk phone.
# Actually, I couldn't figure out how to show a window before screen lock, so you have to call this program instead of locking the screen.
# This script will initiate screen lock via dbus once the initial window has been shown, it then subscribes to a dbus signal so it is notified
# when the screen is unlocked
# To use this in ubuntu: goto system > preferences > keyboard shortcuts.
@hughsaunders
hughsaunders / t-shirt.svg
Created August 8, 2011 22:27
rackspace t-shirt comp
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hughsaunders
hughsaunders / network-list.txt
Created October 20, 2011 06:13
pesky 2.4ghz overcrowding
hms:~ hms$ airport -s
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
BTHomeHub2-M42K 00:24:17:de:50:21 -55 1 N -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)
BTOpenzone-H 02:24:17:de:50:22 -55 1 N -- NONE
storrier 00:26:44:90:0d:0b -39 1 Y -- WPA(PSK/TKIP/TKIP) WPA2(PSK/AES/TKIP)
BTFON 02:24:17:de:50:23 -55 1 N -- NONE
BTOpenzone-H 02:24:17:f1:e9:a8 -68 1 Y -- NONE
BTFON 02:24:17:f1:e9:a9 -68 1 Y -- NONE
BTHomeHub2-G2CH 00:24:17:f1:e9:a7 -67 1 Y -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)
SKY02133 00:24:b2:f7:3b:06 -85 6 N -- WPA(PSK/TKIP/TKIP)
@hughsaunders
hughsaunders / fieldlisttag.py
Created May 6, 2012 10:54
Django template tag for tabulating model fields.
import re
from django import template
register=template.Library()
class PropertyListNode(template.Node):
def __init__(self,model_string,format_spec):
self.model_string=model_string
self.format_spec=format_spec
def render(self,context):
@hughsaunders
hughsaunders / Usage.txt
Created June 5, 2012 17:04
Rough script for creating jmeter slaves with the rackspace uk cloud api
Scripts:
* setup.py creates cloud instances,installs and starts jmeter-server
* cleanup.py destroys cloud instances who's name matches a pattern
Usage:
1) edit setup.py, and insert your username/api key/ssh keys. Define the number of instances you want
1a) install the dependencies listed at the top of setup.py
2) run setup.py
3) edit jmeter.properties and add the line specified at the end of setup.py's output
4) run jmeter, build a test plan, and start on all remotes.
@hughsaunders
hughsaunders / orange
Created January 5, 2013 16:57
Munin plugin for monitoring an orange uk phone account (data remaining, current spend).
#munin plugin configuration, on debian this goes in /etc/munin/plugin-conf.d/
[orange]
timeout 240
env.owuser YOUR-PHONENUMBER-HERE
env.owpass YOUR-PASSWORD-HERE
@hughsaunders
hughsaunders / gist:4579306
Last active December 11, 2015 09:19
Installing python bindings for Rackspace cloud DNS API
#clone the repository from github
hugh@pond-ng:~/git$ git clone https://github.com/rackspace/python-clouddns.git
Cloning into 'python-clouddns'...
remote: Counting objects: 208, done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 208 (delta 124), reused 185 (delta 104)
Receiving objects: 100% (208/208), 38.14 KiB, done.
Resolving deltas: 100% (124/124), done.
hugh@pond-ng:~/git$ ls