Skip to content

Instantly share code, notes, and snippets.

View proof.md

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 5B7E 106F 7A1F B3B2 8236 78E1 398A 0566 9E87 493F

To claim this, I am signing this object:

@EmilHernvall
EmilHernvall / proxy.py
Last active Mar 8, 2018
Transparent proxy for rewriting web pages to include The Hoff
View proxy.py
"""
Install twisted (pip install twisted) and PIL (pip install PIL), and run the script.
On your gateway, run the following commands:
iptables -t nat -A PREROUTING -i br0 -s ! 192.168.0.20 -p tcp --dport 80 -j DNAT --to 192.168.0.20:8080
iptables -t nat -A POSTROUTING -o br0 -s 192.168.0.0/24 -d 192.168.0.20 -j SNAT --to 192.168.0.1
iptables -A FORWARD -s 192.168.0.0/24 -d 192.168.0.20 -i br0 -o br0 -p tcp --dport 8080 -j ACCEPT
Substitute 192.168.0.20 for the computer running the proxy.
"""
@EmilHernvall
EmilHernvall / route53_dyndns.py
Created Apr 10, 2013
Script for dynamically updating a route53 record when your external ip changes.
View route53_dyndns.py
#!/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:
View gist:2332678
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 / data2sound.py
Created Sep 29, 2011
Encode data as sound, and retrieve it using a FFT
View data2sound.py
class GlobalFormat(object):
def __init__(self):
self.id = 0x46464952 # RIFF
self.size = 0
self.type = 0x45564157 # WAVE
def as_bin(self):
return struct.pack("III", self.id, self.size, self.type)
@EmilHernvall
EmilHernvall / sudoku.c
Created Jun 24, 2011
sudoku solver written in c
View sudoku.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct grid_t_ {
unsigned int grid[81];
struct grid_t_ *next;
} grid_t;
typedef struct sub_t_ {
@EmilHernvall
EmilHernvall / LoggingConnection.java
Created May 5, 2011
Delegate implementation of the java.sql.Connection and java.sql.PreparedStatement interfaces that transparently collects statistics about query execution
View LoggingConnection.java
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
PHP-script for calculating the difference between two dates.
View diff.php
<?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 / vector.c
Last active Mar 16, 2019
Simple vector-implementation in C
View vector.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vector.h"
void vector_init(vector *v)
{
v->data = NULL;
v->size = 0;
@EmilHernvall
EmilHernvall / bigdecoder.py
Created May 3, 2011
Decoder for EA games .big-files
View bigdecoder.py
# 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:
You can’t perform that action at this time.