Skip to content

Instantly share code, notes, and snippets.

View amintos's full-sized avatar

Toni Mattis amintos

View GitHub Profile
@amintos
amintos / .gitignore
Last active August 29, 2015 14:09
Sorted .gitignore for output files of LaTeX projects (pdflatex, bibtex, beamer, listings, biber, hyperref, TexMaker, ...)
*.acn
*.acr
*.alg
*.aux
*.bak
*.bbl
*.bcf
*.blg
*.brf
*.dvi
@amintos
amintos / reactive_test.py
Created September 4, 2015 12:28
Example for modular event handling using "activities" as Python generators, which are stepped by external events. Activities reacting to events are a single method and not scattered across callbacks or multiple handlers.
class Element:
"""I represent an unspecific UI component"""
def __init__(self, id, env):
self.id = id
self.env = env
self.children = []
def trigger(self, event):
@amintos
amintos / shred.py
Created September 6, 2012 12:22
Securely erases free disk space on small disks (flash drives, etc.)
import os
import time
ITERATIONS = 3 # Number of passes
BLOCKSIZE = 1 << 20 # Bytes to be written at once
INFO_SECONDS = 3 # Interval in which output is displayed
FILE = 'crap' # File where random output is dumped
def format_bytes(n):
'''Human readable representation of bytes'''
@amintos
amintos / foomodule.c
Created September 14, 2012 11:09
Example interfacing plain arrays via NumPy
#include "Python.h"
#include "numpy/arrayobject.h"
// ----------------------------------------------------------------------------
// BASIC API
typedef struct {
int data[1024];
} internalColumn;
@amintos
amintos / nn.py
Last active October 13, 2015 02:58
standalone neural networks for simple function approximation (fixed SingleLayerPerceptron and added Biases, 2013/12/05)
#
# NEURAL NETWORK CLASSIFIERS
# Pure Python Implementation
#
# Copyright (c) 2008 - 2013 | Toni Mattis <solaris@live.de>
#
import random, math
# ------------------------------------------------------------------------------
# Imports a Wikipedia dump into a CouchDB
# ... and makes it searchable by Apache Lucene
# REQUIREMENTS:
# - CouchDB
# - couchdb-lucene (https://github.com/rnewson/couchdb-lucene)
# - couchdb-python (http://code.google.com/p/couchdb-python/)
# Run CouchDB, start this script, run couchdb-lucene while script is running
# Trigger Indexing by Sample Query:
@amintos
amintos / knn.py
Last active December 10, 2015 14:38
A **standalone function approximator** using **K-Nearest-Neighbours**. Supports euclidean and cosine similarity measures, weights the top-k results constantly, linearly or exponentially (using Boltzmann/Gibbs) and optionally normalizes the output. Can perform cross-validation on its sample set for parameter tuning and reads CSV files.
#
# K-Nearest-Neighbours Function Approximator
# 2013 | by Toni Mattis
#
import math
import heapq # for efficient top-k retrieval
import random # for cross-validation
import csv # for loading samples from a file
@amintos
amintos / kadokusei.py
Created January 11, 2013 01:39
Module providing Hiragana-like encodings for arbitrary data.
"""
KADOKUSEI Number and Byte-Stream Representation
(c) 2013 | Toni Mattis | MIT Licensed
This code allows abstract numbers, i.e. coordinates, public keys or hashes
to be represented in a pronounceable way. Composition is based on Hiragana.
Example:
>>> encode_number(718428)
@amintos
amintos / base64_fixpoint.py
Created February 12, 2013 10:51
Method generating a string of given length which is its own prefix in base64 encoding.
def base64_fixpoint(prefix_len):
s = 'rofl'
t = 'lol'
while s != t:
s = t
t = s.encode("base64")[:prefix_len]
return t
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of