Skip to content

Instantly share code, notes, and snippets.

View amintos's full-sized avatar

Toni Mattis amintos

View GitHub Profile
@amintos
amintos / vm.py
Last active December 30, 2015 00:39
Trans-chroot helper for translating and running the R/Squeak (SPy) VM
#! /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
@amintos
amintos / tags.py
Created December 11, 2013 15:36
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
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 / lda.py
Created April 29, 2015 01:00
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
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 / btm.py
Created May 2, 2017 13:42
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.
ACM, DOI: https://doi.org/10.1145/2488388.2488514
This module requires pre-processing of textual data,