Skip to content

Instantly share code, notes, and snippets.

View EmilHernvall's full-sized avatar

Emil Hernvall EmilHernvall

View GitHub Profile
@EmilHernvall
EmilHernvall / genprimes.c
Created May 3, 2011 17:29
Simple prime sieve
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: genprimes num\n");
return 0;
}
@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
@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 / 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)
{
import urllib2
import re
import base64
def searchForNext(str, unique):
d = 10
last = str[-d:]
print "searching for continuation of " + last
matches = []
for x in unique:
@EmilHernvall
EmilHernvall / route53_dyndns.py
Created April 10, 2013 13:22
Script for dynamically updating a route53 record when your external ip changes.
#!/usr/bin/python
import boto.route53
import os
import sys
import urllib2
import time
def get_zone_id(r53, zone_name):
zone_result = r53.get_hosted_zone_by_name(zone_name)
if not zone_result:
@EmilHernvall
EmilHernvall / generatewav.c
Created May 3, 2011 17:28
Experiment with generating sound in wave-format
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct GlobalFormat {
unsigned int id;
unsigned int size;
unsigned int type;
};
@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 / wordcount.java
Created May 3, 2011 17:15
Find the most popular words in a file - Java version
import java.io.*;
import java.util.*;
public class wordcount
{
public static class Word implements Comparable<Word>
{
String word;
int count;

Keybase proof

I hereby claim:

  • I am emilhernvall on github.
  • I am aderyn (https://keybase.io/aderyn) on keybase.
  • I have a public key whose fingerprint is 8684 23E6 23E7 9338 7711 E0E1 5537 3432 E97B 576A

To claim this, I am signing this object: