Skip to content

Instantly share code, notes, and snippets.

Avatar

Toni Mattis amintos

View GitHub Profile
@amintos
amintos / btm.py
Created May 2, 2017
Bi-term Topic Model implementation in pure Python
View btm.py
"""
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.
ACM, DOI: https://doi.org/10.1145/2488388.2488514
This module requires pre-processing of textual data,
@amintos
amintos / reactive_test.py
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.
View reactive_test.py
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 / lda.py
Created Apr 29, 2015
LDA with Gibbs Sampling in Python
View lda.py
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
amintos / .gitignore
Last active Aug 29, 2015
Sorted .gitignore for output files of LaTeX projects (pdflatex, bibtex, beamer, listings, biber, hyperref, TexMaker, ...)
View .gitignore
*.acn
*.acr
*.alg
*.aux
*.bak
*.bbl
*.bcf
*.blg
*.brf
*.dvi
@amintos
amintos / tags.py
Created Dec 11, 2013
Hacky super-compact HTML generator for python
View tags.py
#
# Simple Inline X/HTML Generator
# by Toni Mattis
#
'''
Example usage:
from tags import *
print div(cls = 'myclass')[ p['Hello'], hr, p[strong['World']] ]
@amintos
amintos / vm.py
Last active Dec 30, 2015
Trans-chroot helper for translating and running the R/Squeak (SPy) VM
View vm.py
#! /usr/bin/python
# --- RPYTHON/CHROOT TOOLCHAIN HELPER ---
#
# 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
View lastexport.py
#!/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
amintos / tf512.py
Created Sep 6, 2013
Simple string encryption and decryption in pure Python using Threefish-512. No guarantee this implementation is 100% correct!
View tf512.py
#
# 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
amintos / compressor.java
Created Jul 6, 2013
Simple LZ-Like compression in Java.
View compressor.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
amintos / base64_fixpoint.py
Created Feb 12, 2013
Method generating a string of given length which is its own prefix in base64 encoding.
View base64_fixpoint.py
def base64_fixpoint(prefix_len):
s = 'rofl'
t = 'lol'
while s != t:
s = t
t = s.encode("base64")[:prefix_len]
return t
You can’t perform that action at this time.