Skip to content

Instantly share code, notes, and snippets.

pervognsen /
Last active Sep 14, 2021
Shift-based DFAs

A traditional table-based DFA implementation looks like this:

uint8_t table[NUM_STATES][256]

uint8_t run(const uint8_t *start, const uint8_t *end, uint8_t state) {
    for (const uint8_t *s = start; s != end; s++)
        state = table[state][*s];
    return state;
lmcinnes / doc_embeddings_with_vectorizers.ipynb
Last active Oct 14, 2021
Document Embeddings with the Vectorizers Library
View doc_embeddings_with_vectorizers.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
rmitton / hipparchus.c
Created Aug 30, 2020
Mandelbrot set rendered from a first-person viewpoint
View hipparchus.c
// I don't know what I'm looking at here.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define OUTPUT "hipparchus.pgm"
#define WIDTH 1024
pkhuong /
Last active Jul 26, 2021
Fully dynamic variance for a bag of observations
import math
import struct
import unittest
import hypothesis.strategies as st
from hypothesis.stateful import Bundle, RuleBasedStateMachine, consumes, invariant, multiple, precondition, rule
class VarianceStack:
def __init__(self):
self.n = 0
jiahao / naivebayes.jl
Last active Apr 28, 2019
Multinomial naive Bayes in Julia, allowing for generic numeric types for the conditional probabilities. When using rational numbers, you can calculate exact probabilities without roundoff error.
View naivebayes.jl
struct MultinomialNaiveBayes{T, V<:AbstractVector}
fit(MultinomialNaiveBayes, [T,] features, labels, α = 1) -> MNB
fits a `MultinomialNaiveBayes` classifier `MNB` using the
`features` matrix and `labels` vector of `Bool`s.
josephg /
Last active Nov 4, 2021
Getting Zig compiling to WASM

In case anyone else wants to play with Zig on webassembly, here's what you need to do to make it work on a mac today.

1. Get LLVM 7 compiled with webassembly support.

You'll need LLVM to output to the WASM target. This has just been added by default in trunk, so if LLVM >7 is available, you might be able to just brew install llvm.

If you have wasm support already you should see:

$ llc --version
rntz /
Last active Mar 4, 2018
An introduction to tone theory, and subtyping for a fragment of modal Datafun
(* A quick note about preorders; skip this if you know about them.
* A preorder is a relation (a ≤ b) satisfying two rules:
* 1. Reflexivity: a ≤ a.
* 2. Transitivity: if a ≤ b and b ≤ c then a ≤ c.
* A good example of a preorder is "lists under containment":
* let (X ≤ Y) if every element of the list X is also in Y.
* Preorders are like partial orders, but without requiring antisymmetry.
View pyfft.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View dispatchingNamedTuples.jl
julia> nt_proto_a_names = (:first, :last)
(:first, :last)
julia> nt_proto_b_names = (:larger, :smaller)
(:larger, :smaller)
julia> nt_proto_a = NamedTuple{nt_proto_a_names}
NamedTuple{(:first, :last),T} where T<:Tuple
julia> nt_proto_b = NamedTuple{nt_proto_b_names}
View noise4.jl
# Perlin noise ported from:
# with the license:
Copyright (c) 2008 Casey Duncan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights