Skip to content

Instantly share code, notes, and snippets.

@tammoippen
tammoippen / list-table-sizes.sql
Created September 15, 2021 15:23
List the size of all tables in postgresql
SELECT
schemaname,
tablename,
PG_SIZE_PRETTY(
PG_TOTAL_RELATION_SIZE(schemaname || '.' || tablename)
) AS tablesize
FROM
pg_catalog.pg_tables
WHERE
schemaname NOT IN ('pg_catalog', 'information_schema')
# execute like: python hanoi.py a b 5
from time import sleep
DO_SLEEP = False
class Hanoi:
def __init__(self, pilon: str, height: int):
self.pilons = {
'a': [],
'b': [],
@tammoippen
tammoippen / braille-font.py
Created July 22, 2019 10:13
Print ttf fonts using braille / plottille canvas. `pip install plotille freetype-py` get font from https://fonts.google.com/specimen/Ubuntu+Mono . Inspired by https://mrandri19.github.io/2019/07/18/modern-text-rendering-linux-ep1.html
import math
import sys
import freetype
import plotille
def chunks(l, n):
n = max(1, n)
return (l[i:i+n] for i in range(0, len(l), n))
_roots = None
def roots_level_domains():
global _roots
if _roots is not None:
return _roots
# get https://publicsuffix.org/list/effective_tld_names.dat
rld = []
with open('effective_tld_names.dat', 'rb') as f:
for l in f:
ul = l.strip().decode('UTF-8')
@tammoippen
tammoippen / idf.py
Last active September 19, 2017 12:20
Compute the inverse document frequency
from __future__ import division
from collections import Counter
import math
def idf(documents):
freq = Counter()
for doc in documents:
words = set(doc.split())
freq.update(words)

Keybase proof

I hereby claim:

  • I am tammoippen on github.
  • I am tammoippen (https://keybase.io/tammoippen) on keybase.
  • I have a public key ASBXMCFYTyAd4m_Y7w4KAuHlOVcnJTFvTPA3R89OKFEb_wo

To claim this, I am signing this object:

@tammoippen
tammoippen / bed-tree.py
Created August 10, 2017 12:02
Some algorithms from the paper "Bed-Tree: An All-Purpose Index Structure for String Similarity Search Based on Edit Distance", Zhang et al. (doi 10.1145/1807167.1807266)
from collections import defaultdict
from functools import lru_cache
from typing import Dict, Iterable, List, Tuple
import mmh3
import numpy as np
from slugify import slugify
def verify_edit_distance(s1: str, s2: str, th: int) -> bool:
@tammoippen
tammoippen / crappyhist.py
Last active July 13, 2024 15:05
Draw a crappy text-mode histogram of an array (python 3)
import numpy as np
def crappyhist(a, bins=50, width=140):
h, b = np.histogram(a, bins)
for i in range (0, bins):
print('{:12.5f} | {:{width}s} {}'.format(
b[i],
'#'*int(width*h[i]/np.amax(h)),
h[i],