Skip to content

Instantly share code, notes, and snippets.

View EmilHernvall's full-sized avatar

Emil Hernvall EmilHernvall

View GitHub Profile
# -*- coding: utf-8 -*-
def columns_to_county(foo):
county = {}
county["id"] = int(foo[0])
county["name"] = foo[1]
county["lon"] = float(foo[3])
county["lat"] = float(foo[4])
return county
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"]
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:
@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 / 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 / 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 / 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 / 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 / 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 / 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)