Skip to content

Instantly share code, notes, and snippets.

@dylan-evans
dylan-evans / simple_hash.c
Created February 4, 2012 14:53
Simple hash
/** \file simple_hash.h
*
* This simple hashing routine was created after finding the hsearch function
* a bit inadequate, due to the lack of a reentrant function in posix and
* the inability to do simple operations such as delete... and for fun.
*/
#include <string.h>
#include <stdio.h>
#include <unistd.h>
@dylan-evans
dylan-evans / example.c
Created May 23, 2011 03:16
Example implementation of prototype programming in C
/*
* An example of prototype programming in C
*/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "proto.h"
/*
@dylan-evans
dylan-evans / audacity_rescue.sh
Created April 10, 2011 10:19
Recover from an Audacity crash by reassembling the saved data files
#!/bin/bash
#Recover from an Audacity crash by reassembling the saved data files
if [ $# != 2 ]; then
echo "ERROR: Not enough arguments"
echo "$0 [SOURCE PATH] [DESTINATION]"
exit 1
fi
@dylan-evans
dylan-evans / tree.sql
Created March 25, 2011 15:33
An sqlite3 demonstration of hierarchical data
-- A method for storing and retrieving hierarchical data in sqlite3
-- by using a trigger and a temporary table.
-- I needed this but had trouble finding information on it.
-- This is for sqlite3, it mostly won't work on anything else, however
-- most databases have better ways to do this anyway.
PRAGMA recursive_triggers = TRUE; -- This is not possible before 3.6.18
-- When creating the Node table either use a primary key or some other
@dylan-evans
dylan-evans / cgiexec.py
Created March 15, 2011 15:04
Execute legacy CGI in modern web app
#!/usr/bin/python
# Execute a cgi script
# Created in order to allow legacy cgi to be used in modern web apps
# Main cgiexec module
from subprocess import Popen, PIPE
import re
# CGI must be dead, i can't get hold of a standard
# For now i am referenceing Apache mod_cgi
@dylan-evans
dylan-evans / tweet.py
Created February 24, 2011 04:58
Tweet processor, inserts link markup for users and hashtags
# Tweet processor, inserts link markup for users and hashtags
# I became frustrated with third party tools which do not link to users and hashtags, so i wrote this.
# Public Domain - please use this, i am happy to rewrite it in any other language.
# Dylan Evans <dylan@contentfree.info>
import re
def html_hashtag(tag, html_class='hashtag'):
"HTML hashtag - create a search link"
return '<a class="%s" href="http://www.twitter.com/search/%s">%s</a>' \
@dylan-evans
dylan-evans / statgen.py
Created February 7, 2011 14:38
This snippet generates some reasonably normal statistics. I wrote it as an experiment to find a way to generate this data for a game, which i never wrote, so precision was never a goal. I had trouble finding information about doing this sort of thing, but
#!/usr/bin/python
# Generate a (roughly normal) sample population for a given mean & standard deviation.
# This was intended for use modelling hypothetical demographics in a sim game.
"""\
Demonstration of the StatGen class
This script demonstrates the StatGen class which generates a normalized sample
from a mean and standard deviation. The algorithm can be adjusted, tweaked and
broken in many different ways which can provide some interesting results, but