Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
eddieantonio / $cree-grapheme-stats.md
Last active June 25, 2019 18:57
Count unigrams and bigrams in the Wolfart-Ahenakew corpus

Cree Grapheme Stats

Count unigrams and bigrams in the Wolfart-Ahenakew nêhiyawêwin corpus!

Why

When building a keyboard for typing Cree, it is useful to know which graphemes are typed often, and which pairs of graphemes are typed one

@eddieantonio
eddieantonio / nonullfree.c
Last active April 10, 2019 16:14
nonullfree.c -- throw errors when you call free(NULL)
/**
* nonullfree.c -- throw errors when you call free(NULL)
*
* BUILDING:
*
* $ gcc -shared -fPIC nonullfree.c -ldl -o nonullfree.so
*
* USAGE (Linux):
*
* $ LD_PRELOAD=./nonullfree.so ./my-program
@eddieantonio
eddieantonio / compile_c_inline.py
Last active March 18, 2019 19:38
Demo of compiling a small C dynamic library in a Python script and directly loading it with ctypes.
import ctypes
import tempfile
import distutils.ccompiler
from pathlib import Path
from random import randint
SOURCE_CODE = f"""
int roll(void) {{
return {randint(1, 6)};
@eddieantonio
eddieantonio / generate_forms_hfst.py
Last active March 9, 2019 02:03
Generate word forms using hfst-optimized-lookup
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright 2019 Eddie Antonio Santos <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Install `fst_lookup` using pip:
#
# $ pip install fst-lookup
#
# Or, if you're using pipenv:
#
# $ pipenv install fst-lookup
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
dull(1) dull(1)
NAME
dull -- the opposite of pointed
@eddieantonio
eddieantonio / pipe.py
Last active December 10, 2018 18:41
ceci n'est pas une pipe
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import re
from dataclasses import dataclass
from functools import partial
from typing import TypeVar, Generic, Callable
from unicodedata import normalize
A = TypeVar('A')
<script>
var url = URL.createObjectURL(new Blob(['(', MyWebWorker.toString(), '())'], {
type: 'text/javascript'
}));
console.log(url);
var worker = new Worker(url);
worker.onmessage = function (event) {
console.log("from worker:", event);
}
class Duration {
constructor(number) {
this._number = number;
}
valueOf() {
return this._number;
}
then(fn) {
@eddieantonio
eddieantonio / cree-classes.py
Last active November 15, 2018 19:00
Ideas on how to represent Cree morphological data.
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Some ideas about how to organize data from the FST, to how to store Cree
wordforms.
Usage:
Analyzing a wordform descriptively yields "raw" FST output: