Skip to content

Instantly share code, notes, and snippets.

View mumbleskates's full-sized avatar
🤔

Kent Ross mumbleskates

🤔
  • 🌵
View GitHub Profile
intervaltree
* storing timelines or other intervals
* sorting will not work, you have to fully search
* introducing interval trees, which allow O(log n) access and modification
* interval trees of interval trees for multi-dimensional data... most basic spatial data stuff
* intervaltree on pypi
fancy pythonic dijkstra
* finding shortest paths in a graph
* using heaps and making backpathing trees with tuples
# coding=utf-8
from collections import Counter, defaultdict
from functools import reduce
from itertools import tee
import re
LOW_PROBABILITY = 1.0 / (1 << 20)
@mumbleskates
mumbleskates / markov.sql
Last active March 22, 2017 02:05
Pure-SQL markov heaps (SQLite)
/* powers of 2 utility view for heap traversal */
CREATE VIEW IF NOT EXISTS power2 AS
WITH RECURSIVE doubling(n) AS (
VALUES (2)
UNION ALL
SELECT n*2 FROM doubling LIMIT 62
)
SELECT n twos FROM doubling;
/* generates random floating point values in interval [0, 1) */
@mumbleskates
mumbleskates / random_k.js
Last active November 28, 2016 03:45 — forked from seejohnrun/random_k.js
Select (n) random elements from a weighted set randomly
// ported from: http://stackoverflow.com/questions/2140787/select-random-k-elements-from-a-list-whose-elements-have-weights
// each node in the heap has a value, weight, and totalWeight
// the totalWeight is the weight of the node plus any children
var Node = {};
var newNode = function (value, weight, totalWeight) {
var node = Object.create(Node);
node.value = value;
node.weight = weight;
node.totalWeight = totalWeight;