Skip to content

Instantly share code, notes, and snippets.

@kylef
kylef / dict.c
Created March 27, 2009 17:11
A key/value dictionary system in C
/* A key/value dict system in C */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEST TRUE /* Comment this line out to compile without a main function (used when including into another application). */
typedef struct dict_t_struct {
char *key;
void *value;
@kylef
kylef / dispatch.fcgi
Created May 21, 2009 13:58
Django fastCGI dispatcher
#!/usr/bin/env python2.4
import sys, os
from fcgi import WSGIServer
if __name__ == '__main__':
sys.path += ['/home/kylef/python']
os.environ['DJANGO_SETTINGS_MODULE'] = 'kylef.settings'
from django.core.handlers.wsgi import WSGIHandler
WSGIServer(WSGIHandler()).run()
@kylef
kylef / Toggle Mute (Skype)
Created May 31, 2009 13:11
Applescript to toggle mute on Skype
tell application "Skype"
if (send command "GET MUTE" script name "MuteToggler") is equal to "MUTE ON" then
send command "SET MUTE OFF" script name "MuteToggler"
else
send command "SET MUTE ON" script name "MuteToggler"
end if
end tell
@kylef
kylef / iphone-update-checker.py
Created June 17, 2009 13:36
This python script queries iTunes update url to see if iPhone OS 3.0 has been released for the iPhone 3G
import urllib2
import re
from time import sleep
class PageScraper(object):
"""
This class scrapes a url for a string, can be used with a loop.
"""
def __init__(self, url, string=''):
@kylef
kylef / html.py
Created July 8, 2009 23:46
This middleware strips unnessicery characters from a HTML document in order to save bytes. It will removes things like CR, LR, TAB's and multiples spaces.
"""
The idea of this was to strip responses of any unnecessary
characters to save bandwidth, after some testing the savings
were only up-to 8% on rare occasion.
"""
import re
re_is_html = re.compile(r'(*)</html>(*)')
@kylef
kylef / Django HTCPCP Middleware.py
Last active November 25, 2015 01:09
A HTCPCP Implementation for Django
from random import randint
from django.http import HttpResponse
class HTCPCPMiddleware(object):
"""
This middleware allows a your django project to act as a HTCPCP (Hyper
Text Coffee Pot Control Protocol) server. If the user requests to BREW
a coffee, and it is not on the list. Then it will get a `406 Not
Acceptable`, and randomly it will respond with `418 I'm a teapot`.
@kylef
kylef / irc-znc.xml
Created January 10, 2010 02:07
This is a SMF script for OpenSolaris for ZNC
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='znc'>
<service
name='network/irc'
type='service'
version='1' >
<instance name='znc' enabled='false'>
@kylef
kylef / russian_roulette.cpp
Created January 10, 2010 13:19
This is a russian routlette module which may kick a user when he says !roulette
#include <main.h>
#include <Modules.h>
#include <Chan.h>
class CRussianRoulette_Mod : public CModule {
public:
MODCONSTRUCTOR(CRussianRoulette_Mod) {}
virtual ~CRussianRoulette_Mod() {}
EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
@kylef
kylef / sabnzbd.py
Created January 11, 2010 15:04
SABnzbd python api
import urllib, json
class SABnzbd(object):
"""
Usage:
>>> from sabnzbd import SABnzbd
>>> s = SABnzbd('sakar.local', 8080, '4488f2881b90d7753bef8fb9e1bc56b3')
>>> s.pause() # Pauses the downloads
>>> s.shutdown() # Shut's down SABnzbd+
"""
@kylef
kylef / irc-unreal.xml
Created January 11, 2010 15:18
This is a SMF script for OpenSolaris for UnrealIRCd
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='unrealircd'>
<service
name='network/irc'
type='service'
version='1' >
<instance name='unreal' enabled='false'>
<dependency name='network'