Skip to content

Instantly share code, notes, and snippets.

type tree: {payload: int, void | {l, r: tree*}}

fun treePrint: (root: tree*) -> void {

}

Algebraic data types

  • Declare using named case labels inside struct
  • Fields declared before a case are common to all cases
@Fedjmike
Fedjmike / for_dir.h
Last active August 26, 2015 04:58
A macro for iterating over the contents of a directory.
#include <dirent.h>
#define for_dir(entry, dirname, continuation) \
do { \
DIR* for_dir_dir__ = opendir(dirname); \
for (struct dirent* (entry); \
((entry) = readdir(for_dir_dir__));) { \
continuation \
} \
closedir(for_dir_dir__); \
@Fedjmike
Fedjmike / runner.c
Created September 15, 2015 21:59
runner.c that separates the runner entry point from the AST handler
#include "runner.h"
#include <gc.h>
#include "dirctx.h"
#include "sym.h"
#include "ast.h"
#include "type.h"
#include "value.h"
@Fedjmike
Fedjmike / value.c
Created September 15, 2015 22:01
value.c with a ProgramInvocation kind for lazy invocation
#include "value.h"
#include <stdio.h>
#include <unistd.h>
#include <gc.h>
#include <common.h>
#include "sym.h"
#include "runner.h"
#include "invoke.h"
@Fedjmike
Fedjmike / model.py
Last active April 4, 2016 03:27
merging releases
def merge_into_release(self, dest_release, src_release):
"""Transfers all data from a release to another and removes the source.
Overwrites the destination where the release info differs.
There is never loss of user information."""
#merge = replace in dest + remove in src
#move = insert in dest + remove in src
def move_actions(model, dest_id, src_id):
model.execute("update actions set object_id=? where object_id=?", src_id, dest_id)
@Fedjmike
Fedjmike / assign_artist_mbids.py
Created April 5, 2016 10:33
Work out artist mbids using release mbids, incomplete field
import sys
from model import Model, NotFound
import musicbrainzngs as mb
def mb_get_author_ids(release_mbid):
mb.set_useragent("Skiller", "0.0.0", "mb@satyarth.me")
response = mb.get_release_by_id(release_mbid, includes=["artists"])["release"]
return [artist["artist"]["id"] for artist in response["artist-credit"] if isinstance(artist, dict)]
@Fedjmike
Fedjmike / assign_artist_image.py
Last active April 24, 2016 12:24
Scrape wikipedia images
import sys
from model import Model, NotFound
from tools import get_wikipedia_image
def safe_print(*args):
try:
print(*args)
except:
pass
@Fedjmike
Fedjmike / convert_datetimes.py
Last active April 24, 2016 14:43
Convert user and action creation datetimes from ISO 8601 (EDT) to Unix timestamps
import arrow
from model import Model
def convert_actions():
with Model() as model:
model.db.executescript(
"""drop table if exists actions_2;
create table actions_2 (
id integer primary key,
user_id integer not null,
@Fedjmike
Fedjmike / fix_release_art.py
Created July 26, 2016 23:47
Fix release cover arts whose canonical URL has changed
import requests
from multiprocessing import Pool
from model import Model, NotFound
from mb_api_import import get_album_art_urls
def safe_print(*args):
try:
print(*args)
except:
pass
import sys
from model import Model, NotFound
from tools import get_wikipedia_summary
def safe_print(*args):
try:
print(*args)
except:
pass