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 / compressor.java
Created July 6, 2013 20:33
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
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 / tf512.py
Created September 6, 2013 01:54
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
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,