Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
#! /usr/bin/env python
import sys, os
import httplib # JSON Retrieval
import simplejson # JSON Parsing
class Story(object):
"""
Class to represent a single Reddit story.
BWPRICE = 0.045
COLPRICE = 0.12
unless ARGV[0] then
puts "Usage: #{$0} [#bwpages] [#colpages] [#copies] [binding-price/copy]"
exit 1
end
binding_price = ARGV[3].to_f
@jiphex
jiphex / uniweek.php
Created July 26, 2008 10:33
Week calculator for Lancaster University
<?php
// The year start date...
define("YEARSTART", mktime(0, 0, 0, 10, 5, 2007), FALSE);
// Calculates the week number from the start of the year as set in the
// general configuration files. Returns an array containing the uni week
// number [0], the term name as a string [1] and a boolean if the current
// week is during a holiday [2]...
function universityWeek() {
@jiphex
jiphex / bashrc.sh
Created November 24, 2008 20:27
My bash/vim/git environment
#! /bin/bash
# James Hannah - Bash Prompt.
# If no prompt, quit here.
[ -z "$PS1" ] && exit
# Get the important things sorted first
export EDITOR=vim
# Lets define some colors
@jiphex
jiphex / trends.py
Created April 19, 2009 19:52
Script to print the current twitter trends.
@jiphex
jiphex / testthrottle.sh
Created July 13, 2009 22:46
Script for Tomato Firmware based routers to detect Virgin Media (UK) traffic shaping, then trigger events such as LED switching and backend calling (e.g To Twitter)
#! /bin/sh
PINGHOST="212.58.226.77" # BBC news
THROTTLEFILE="/tmp/throttlestate"
PINGTIME=`ping -c 5 -q $PINGHOST | grep ^round | cut -d "/" -f 4 | cut -d "." -f 1`
WASTHROTTLED=`cat $THROTTLEFILE`
PINGISGT=`expr $PINGTIME \> 100`
if [ $PINGISGT -eq 1 ]; then
echo "I think I'm throttled (with a ping of $PINGTIME ms)"
THROTTLESTATE="yes"
else
/**
* Copyright 2006 Paul Querna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/**
* Copyright 2006 Paul Querna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
#! /usr/bin/env python
# Unpostmap - reverse postmap'ed data
import os,sys,datetime
try:
import bsddb
hashed = bsddb.hashopen(sys.argv[1], 'r')
print "# hashed by unpostmap (%s)"%sys.argv[1]
for key in hashed:
print "%s %s" % (key, hashed[key])
@jiphex
jiphex / testdns.c
Created November 11, 2009 11:12
Barebones dig using inet_ntoa in C
#include <netdb.h>
#include <stdio.h>
int main(int argc, char * argv[]) {
if(argc > 1) {
int i;
struct hostent *hent;
hent = gethostbyname(argv[1]);
printf("Hostname: %s\n", hent->h_name);
for(i = 0; hent->h_addr_list[i] != 0; i+=1) {
printf("IP: %s\n", inet_ntoa(*((long *)hent->h_addr_list[i])), i);