Skip to content

Instantly share code, notes, and snippets.

Avatar
💨

Lance Pollard lancejpollard

💨
View GitHub Profile
@lancejpollard
lancejpollard / model.js
Created May 8, 2022
How your code ends up without a framework (SQL without a good model layer)
View model.js
const { uniq, omit } = require('lodash')
const serialization = require('./serialization')
const knex = require('../../knex')
const toneText = require('../../../../../../drumwork/deck/tone')
const callText = require('../../../../../../drumwork/deck/call')
let objectKeyToIdMap
let objectIdToKeyMap
let languageMap
@lancejpollard
lancejpollard / sequences.csv
Created Apr 29, 2022
Complete List of N=5 Binary de Bruijn Sequences
View sequences.csv
sequence
00000100011001010011101011011111
00000100011001010011101101011111
00000100011001010011111010110111
00000100011001010011111011010111
00000100011001010110100111011111
00000100011001010110100111110111
00000100011001010110111010011111
00000100011001010110111110100111
00000100011001010111011010011111
@lancejpollard
lancejpollard / debruijn-graph.js
Last active Apr 21, 2022
Attempt at generating debruijn sequences from traversing debruijn graphs.
View debruijn-graph.js
// http://web.mnstate.edu/goytadam/talks/DBS.pdf
const SIZE = 8
const vertices = getEveryBitPermutation(SIZE).reduce((m, x) => {
m.set(x.toString(2).padStart(SIZE, 0), new Array)
return m
}, new Map)
for (let [v, edges] of vertices) {
@lancejpollard
lancejpollard / debruijin-dynamic.js
Created Apr 21, 2022
Quick attempt at dynamically iterating over de Bruijn sequences.
View debruijin-dynamic.js
class Iterator {
constructor(k, n) {
this.k = k // alphabetSize
this.n = n // wordSize
this.power = new Uint32Array(n + 1)
this.power[0] = 1;
for (let i = 1; i <= n; i++) {
this.power[i] = k * this.power[i - 1];
}
View debruijn-sequence.js
// ported from C from http://debruijnsequence.org/db/home
const MAX = 100
function isZeroes(a, n) {
for (let i = 1; i <= n; i++) {
if (a[i] === 1) {
return false;
}
}
View generateDeBruijnSequence.java
// from https://www.klittlepage.com/2013/12/21/twelve-days-2013-de-bruijn-sequences/
import java.util.Random;
/**
* @author Kelly Littlepage
*/
public class DeBruijn {
/***
* Generate a De Bruijn Sequence using the recursive FKM algorithm as given
View magin-debruijn-generator.js
#include <Frigo/all>
#include <Frigo/all.cpp>
// from https://stackoverflow.com/questions/7365562/de-bruijn-like-sequence-for-2n-1-how-is-it-constructed/7369288#7369288
using namespace Frigo::Lang;
using namespace std;
class MagicNumberGenerator
{
View leading-trailing-zeroes.js
const BINARY_LEADING_ZERO_TABLE = makeLeadingZeroTable()
const BINARY_TRAILING_ZERO_CONSTANT = 0x077cb531
const BINARY_TRAILING_ZERO_TABLE = makeDeBruijnTrailingZeroTable(5, BINARY_TRAILING_ZERO_CONSTANT)
function countTrailingZeroes32(n) {
return BINARY_TRAILING_ZERO_TABLE[((n & -n) * BINARY_TRAILING_ZERO_CONSTANT) >>> 27];
}
function countTrailingZeroes16(n) {
@lancejpollard
lancejpollard / debruijn.py
Created Apr 20, 2022 — forked from rgov/debruijn.py
de Bruijn sequence generator
View debruijn.py
def deBruijn(n, k):
'''
An implementation of the FKM algorithm for generating the de Bruijn
sequence containing all k-ary strings of length n, as described in
"Combinatorial Generation" by Frank Ruskey.
'''
a = [ 0 ] * (n + 1)
def gen(t, p):
@lancejpollard
lancejpollard / generate.js
Last active Apr 20, 2022
Generate count leading zeroes table
View generate.js
function makeLeadingZeroTable() {
let i = 0
const table = new Uint8Array(256)
while (i < 256) {
let count = 8
let index = i
while (index > 0) {
index = (index / 2) | 0
count--
}