Skip to content

Instantly share code, notes, and snippets.

View EmilHernvall's full-sized avatar

Emil Hernvall EmilHernvall

View GitHub Profile
@EmilHernvall
EmilHernvall / proxy.py
Last active October 17, 2023 20:30
Transparent proxy for rewriting web pages to include The Hoff
"""
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 / data2sound.py
Created September 29, 2011 14:07
Encode data as sound, and retrieve it using a FFT
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 June 24, 2011 15:18
sudoku solver written in 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 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 / 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 / Base64.java
Last active February 24, 2021 06:24
Simple base64-encoder for java
public class Base64
{
public static String encode(byte[] data)
{
char[] tbl = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
@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 / 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
*/
/**
Compiled from "Test1.java"
public class Test1 {
public Test1();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
import json
import pymysql
import pymysql.cursors
import os
import csv
from datetime import datetime
with open("data/premier-league/schema.json") as fh:
schema = json.loads(fh.read())
fields = schema["fields"]