Skip to content

Instantly share code, notes, and snippets.

@surt91
surt91 / isingDenoiser.py
Last active December 30, 2015 06:29
a simple implementation of a black-and-white png denoiser (inclusive adding the noise) based on the Ising model. You need python3 and pypng (https://pypi.python.org/pypi/pypng/)
#!/usr/bin/env python3
import png
from random import random, sample
class Bitmap():
def __init__(self, filename):
pic = png.Reader(filename)
w,h,pixel,meta = pic.asDirect()
self.w = w
@surt91
surt91 / dfsMaze.py
Last active September 17, 2016 19:23
draws a maze based on a randomized dfs, see http://en.wikipedia.org/wiki/Maze_generation
#!/usr/bin/env python3
import sys
from random import shuffle
import networkx as nx
# pythons recursion limit is quite low
# increase it, the worst that can happen is a Stack overflow
sys.setrecursionlimit(20000)
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand*{\shear}{0.2}
\newcommand*{\height}{1.0}
\newcommand*{\radius}{0.1}
\newcommand*{\xspacing}{1}
@surt91
surt91 / SHA-256.c
Last active August 29, 2015 14:00
A small, not optimized SHA-256 implementation.
// sha256: https://tools.ietf.org/html/rfc6234
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
// Format string for output
#define FORMAT_SHA256 "%08x%08x%08x%08x%08x%08x%08x%08x"
// First 32 Bits of the fractional part of the cuberoots of the first 64 primes
@surt91
surt91 / sha256.py
Created April 23, 2014 20:11
SHA-256 in Python
print(hashlib.sha256(b"Hallo Welt!").hexdigest())
@surt91
surt91 / simulated_sort.py
Last active August 29, 2015 14:02
Generates an approximation of a sorted list of integers using Simulated Annealing. Faster than Bogosort in many cases!
#!/usr/bin/env python3
from random import random, randint, sample
from math import exp
from copy import deepcopy
from time import time
class SimulatedSort():
def __init__(self):
self.T = [300.0, 100.0, 70.0, 30.0, 10.0, 7.0, 3.0, 1.0]
@surt91
surt91 / atMegaImpMarch.c
Created September 16, 2016 16:45
C Code for the ATMega8 to play the Imperial March
/*
* ImpMarchTiny.c
*
* Created: 03.04.2011 21:06:57
* Author: surt91
*/
#include <avr/io.h>
// "_delay_ms()" is only precise to 261/tact ms (4 ms)
void long_delay(int cs)
@surt91
surt91 / plot.py
Created September 16, 2016 18:08
Solving and plotting the Lorenz Attractor
#!/usr/bin/env python3
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
if __name__ == "__main__":
with open("lorenz.txt","r",encoding='utf-8') as f:
tmp=[i.split(" ") for i in f.readlines()]
#!/usr/bin/env python3
import sys
from random import random
import networkx as nx
def updateAliveNeighbors(G, changedNodes, alive_neighbors):
for n in set(changedNodes):
alive_neighbors[n] = 0
@surt91
surt91 / gzstream.h
Last active December 15, 2016 15:07 — forked from piti118/gzstream.h
Header-only version of gzstream
// ============================================================================
// gzstream, C++ iostream classes wrapping the zlib compression library.
// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,