Skip to content

Instantly share code, notes, and snippets.

@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 <easantos@ualberta.ca>
#
# 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:
@eddieantonio
eddieantonio / server_start_sigusr1.py
Created July 3, 2018 17:21
SIGUSR1 to indicate process is ready.
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
import os
import signal
import sys
from contextlib import contextmanager
from random import randint
from signal import SIGUSR1, SIGTERM
from time import sleep
@eddieantonio
eddieantonio / Makefile
Created June 26, 2018 16:10
How to create Cans-to-Cans FSTs.
# The source analyser and generator FSTs are done entirely in Standard Roman
# Orthography (Latn). However, we require Canadian Aboriginal syllabics
# versions of both. This Makefile converts SRO FSTs in the equivillent
# syllabics FSTs.
#
# analyser-gt-desc.Cans-to-Cans.hfstol
# : An analyzer that accepts input in Canadian Aboriginal syllabics
# and produces a morphological analysis with its lemma also written in syllabics.
# "Descriptive" means it is able to understand non-standard orthography.
#