Skip to content

Instantly share code, notes, and snippets.

@blazs
blazs / test_topological_ordering.py
Last active May 8, 2018 11:52
Using hypothesis, a property-based testing Python library, to test topological ordering algorithm by randomly sampling the space of directed graphs
@given(
st.lists(st.tuples(st.integers(min_value=0, max_value=10), st.integers(min_value=0, max_value=10)), min_size=1,
max_size=90))
def test_resolve_dependencies(self, edges):
dag = DirectedGraph.from_edges(edges)
if DirectedGraph.is_cyclic(dag):
with self.assertRaises(CyclicDependencyError):
_ = EOWorkflow._resolve_dependencies(dag)
else:
ver2pos = {u: i for i, u in enumerate(EOWorkflow._resolve_dependencies(dag))}
@blazs
blazs / wget.go
Last active April 26, 2018 19:48
A very primitive wget in Go
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
@blazs
blazs / test_selection_sort_with_hypothesis.py
Created April 25, 2018 12:38
Playing around with Hypothesis package for property-based testing in Python
import functools
from hypothesis import given, strategies as st
def selection_sort(items):
items = list(items)
for idx, _ in enumerate(items, 0):
min_idx = idx
for jdx, item in enumerate(items[idx+1:], idx+1):
@blazs
blazs / words.py
Last active February 19, 2018 14:38
Shortest path via BFS on implicit graph of words, induced by the dictionary of words, with an edge between each pair of words that differ by a single character.
import sys
import collections
import string
import logging
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
@blazs
blazs / trie.py
Last active February 18, 2018 09:43
A quick-and-dirty trie
""" A simple trie implementation """
class Node:
def __init__(self, value=None, count=0):
self.value = value
self.count = count
self.children = {}
def __contains__(self, value):
@blazs
blazs / entropy_holder.py
Last active June 29, 2022 08:07
A proof-of-concept implementation of algorithms and formulas for maintaining entropy of elements over a data stream.
"""
A proof-of-concept implementation of algorithms and formulas described in [1].
[1] https://arxiv.org/abs/1403.6348
Blaz Sovdat ([email protected])
"""
import collections
import math
@blazs
blazs / Earley.java
Created January 13, 2018 18:10
An old Java implementation of the Earley parser from student days.
// -- Description --
// Assume 'S' is always the start symbol
// You may assume that your method will be tested in the following setting:
// - grammar will contain between 1 and 100 strings,
// - each string will represent one production (possibly with multiple right
// hand sides, separated by | (see examples)),
// - word can be empty or up to 10000 terminal symbols (characters) long.
// -- References --
// [1] Jay Earley. An Efficient Context-Free Parsing Algorithm. Communications of the ACM, 1970.
// [2] John Aycock and Nigel Horspool. Practical Earley Parsing. Computer Journal, 2002.
@blazs
blazs / huffman.py
Last active January 11, 2018 07:48
Quick&dirty implementation of the Huffman encoding.
"""
Quick and dirty prototypical implementation of the Huffman encoding.
Blaz Sovdat ([email protected]), December 20th 2017
"""
import collections
import enum
import heapq
@blazs
blazs / main.py
Last active November 10, 2017 10:00
Quick and dirty implementation of the sinusoidal projection.
#!/usr/bin/env python
import sys
import math
import itertools as it
import numpy as np
import scipy.misc
@blazs
blazs / example_hist_response.json
Created January 9, 2017 12:27
Example of a response for GetFeatureInfo using StreamingHistogram.
// 20170109132547
// http://localhost:8086/v1/fis/b7b5e3ef-5a40-4e2a-9fd3-75ca2b81cb32?showLogo=false&SERVICE=WCS&LAYERS=B04,B03,B02&FORMAT=image%2Fjpeg&TRANSPARENT=FALSE&VERSION=1.1.1&HEIGHT=512&WIDTH=512&SRS=EPSG%3A4326&MAXCC=20&TIME=2015-01-01%2F2017-01-09&BBOX=29.02587890625,30.80791068136646,29.0478515625,30.826780904779774
[
{
"time": "2017-01-04",
"data": [
{
"layer": "B04",
"min": 102.0,