Skip to content

Instantly share code, notes, and snippets.


Toni Mattis amintos

View GitHub Profile
amintos /
Created May 2, 2017
Bi-term Topic Model implementation in pure Python
Bi-Term Topic Model (BTM) for very short texts.
Literature Reference:
Xiaohui Yan, Jiafeng Guo, Yanyan Lan, and Xueqi Cheng:
"A biterm topic model for short texts"
In Proceedings of WWW '13, Rio de Janeiro, Brazil, pp. 1445-1456.
This module requires pre-processing of textual data,
amintos /
Created Sep 4, 2015
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): = id
self.env = env
self.children = []
def trigger(self, event):
amintos /
Created Apr 29, 2015
LDA with Gibbs Sampling in Python
import random
def dirichlet(alpha):
"""Sample dirichlet-distributed vector from Dir(alpha)"""
s = [random.gammavariate(a, 1) for a in alpha]
norm = sum(s)
return [d / norm for d in s]
amintos / .gitignore
Last active Aug 29, 2015
Sorted .gitignore for output files of LaTeX projects (pdflatex, bibtex, beamer, listings, biber, hyperref, TexMaker, ...)
View .gitignore
amintos /
Created Dec 11, 2013
Hacky super-compact HTML generator for python
# Simple Inline X/HTML Generator
# by Toni Mattis
Example usage:
from tags import *
print div(cls = 'myclass')[ p['Hello'], hr, p[strong['World']] ]
amintos /
Last active Dec 30, 2015
Trans-chroot helper for translating and running the R/Squeak (SPy) VM
#! /usr/bin/python
# This script restarts itself inside the 32-bit chroot environment
# and runs either the translation or a benchmark.
# (!) Double-check that everything uses absolute paths (!)
import os
#!/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
amintos /
Created Sep 6, 2013
Simple string encryption and decryption in pure Python using Threefish-512. No guarantee this implementation is 100% correct!
# Simple Pure-Python Threefish-512 Encryption.
# (No guarantee that this implementation is 100% correct!)
# Use encrypt(text, key) and decrypt(text, key) for string encryption.
# The cipher operates in CBC mode with a random tweak value.
from StringIO import StringIO
amintos /
Created Jul 6, 2013
Simple LZ-Like compression in Java.
/** Fast and simple text compression.
* This is a modified variant of LZ77:
* The algorithm inserts "marker bytes" whose bits state which
* of the following 8 symbols are actual symbols (0) or backward
* references (1). Backward references are actually two bytes, the
* first 6 bits encoding the length and the next 10 bits encoding
* the negative offset where the repetition occurred.
* The idea is related to LZO and LZJB compression.
amintos /
Created Feb 12, 2013
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