Skip to content

Instantly share code, notes, and snippets.

View EmilHernvall's full-sized avatar

Emil Hernvall EmilHernvall

View GitHub Profile
@EmilHernvall
EmilHernvall / LoggingConnection.java
Created May 5, 2011 01:21
Delegate implementation of the java.sql.Connection and java.sql.PreparedStatement interfaces that transparently collects statistics about query execution
package net.quenchnetworks.panthera.feedimport.util;
import java.util.*;
import java.sql.*;
public class LoggingConnection implements Connection
{
public static class LogEntry
{
public String sql;
@EmilHernvall
EmilHernvall / diff.php
Created May 3, 2011 19:47
PHP-script for calculating the difference between two dates.
<?php
/**
* Calculate differences between two dates with precise semantics. Based on PHPs DateTime::diff()
* implementation by Derick Rethans. Ported to PHP by Emil H, 2011-05-02. No rights reserved.
*
* See here for original code:
* http://svn.php.net/viewvc/php/php-src/trunk/ext/date/lib/tm2unixtime.c?revision=302890&view=markup
* http://svn.php.net/viewvc/php/php-src/trunk/ext/date/lib/interval.c?revision=298973&view=markup
*/
@EmilHernvall
EmilHernvall / bigdecoder.py
Created May 3, 2011 18:54
Decoder for EA games .big-files
# bigdecoder.py, by aderyn@gmail.com, 2009-03-01
#
# decoder for .BIG-format files utilized by Red Alert 3 and C&C: Zero Hours
# among others. .big is a trivial archival format. quite frankly, this is
# probably the simplest compound file format imaginable.
#
# this script is written for microsoft windows. it can probably be easily
# adapted for other platforms, but i haven't tried.
#
# file structure:
@EmilHernvall
EmilHernvall / WordTrainer.java
Created May 3, 2011 18:34
A tiny java-program for language training
/**
* WordTrainer 2008-12-02
* Simple language training in Java. This program accepts text-files
* containing where each line contains two words in two diffrent languages
* separated by a comma (,). The first line follows the same format but
* specifies the language.
*
* Sample gloss-file:
* Engelska,Svenska
* cloud,moln
@EmilHernvall
EmilHernvall / spellcheck.php
Created May 3, 2011 17:40
Surpringly smart spellchecker in PHP
<?php
/**
* spellcheck.php
*
* @version 0.1
* @author Emil Hernvall <aderyn@gmail.com>
* @license Public Domain
*/
/**
@EmilHernvall
EmilHernvall / binutils.py
Created May 3, 2011 17:39
Some small python functions for converting between binary and denary
def Denary2Binary(n):
'''convert denary integer n to binary string bStr'''
bStr = ''
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
n = n >> 1
return bStr
@EmilHernvall
EmilHernvall / reorderhand.c
Created May 3, 2011 17:32
Given a hand of n cards and k attempts, use recursion to shuffle the cards into a given order.
/**
* Emil Hernvall - 2007-12-15
* Given a hand of n cards and k attempts, use recursion to shuffle the cards
* into a given order.
*/
#include <stdio.h>
int compare(int* first, int* second, int size)
{
@EmilHernvall
EmilHernvall / perm.c
Created May 3, 2011 17:32
setuid to another user and give group members write permissionto files with certain extensions. No idea why I ever needed this.
// perm.c - setuid to another user and give group members write permission
// to files with certain extensions.
// Emil Hernvall, 2008-04-14
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
@EmilHernvall
EmilHernvall / mkdirp.c
Created May 3, 2011 17:31
Function for creating all the folders in a path automatically
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
int mkdirp(const char *path, mode_t mode)
{
char *pos, *base;
char **dirs;
@EmilHernvall
EmilHernvall / hashtable.c
Created May 3, 2011 17:30
A hashtable implementation, which probably doesn't work as efficiently as advertised
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define DEBUG 1
#define HASHTABLE_HASH_A 41
#define HASHTABLE_COMPRESSION_A 77
#define HASHTABLE_COMPRESSION_B 42
#define HASHTABLE_BUCKET_INITIALSIZE 2