This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is what imperative style looks like when the parser is | |
// implemented with exceptions for control flow | |
function imperative_style_with_exceptions(p: Parser) { | |
p.consume('look at'); // could throw NoMatch | |
let who = p.split([ // could throw Split or NoMatch | |
() => p.consume('me', 'me'), | |
() => p.consume('mewtwo', 'mewtwo'), | |
() => p.consume('steven', 'steven'), | |
() => p.consume('martha', 'martha') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
update.ts - Concise, typed immutable updates to deeply-nested objects | |
Daniel Spitz | |
Use it like this: | |
import {update} from 'update'; | |
let obj = { a: 3, b: 'horse', c: { d: [1,2,3] }}; | |
let obj2 = update(obj, { a: 0, c: { d: _ => [..._, 4] } }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import functools | |
""" | |
Python Atrocity: Structural Pattern Matching built on Exception Handling Syntax | |
Daniel Spitz | |
(Python 3.7+ only) | |
The goal of this Python Atrocity is to implement extensible, composable pattern |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
import importlib | |
import pkg_resources | |
from operator import attrgetter | |
from functools import reduce | |
import io | |
from contextlib import ExitStack | |
from collections import defaultdict | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distributed import Client, Queue, Variable, get_client, secede, rejoin, wait, fire_and_forget | |
from time import sleep | |
import gc | |
from functools import partial | |
from collections import Counter, defaultdict, namedtuple | |
from tornado import gen | |
import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def do(lift_func=iter): | |
""" | |
Decorator that allows python generators to behave a bit like Haskell's do blocks. | |
The basic intuition to follow is that the Haskell "x <- y" syntax is mimicked in python by "x = yield y", | |
if it occurs inside a generator function decorated by @do(). | |
By passing different arguments to @do(), you can change which monad type is mimicked. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from chatto_transform.schema.schema_base import cat | |
from libc.string cimport memcpy | |
from cpython cimport array | |
import array | |
import numpy as np | |
cimport numpy as np | |
import pandas as pd | |
from libc.stdlib cimport malloc, free |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random #definitely a good thing to see at the top of a multiple-dispatch implementation! | |
import abc | |
import itertools | |
class ArgValidator: | |
@classmethod | |
def validate(cls, *args, mro_distances=None): | |
if mro_distances is None: | |
mro_distances = [] | |
#disqualify validation rules with the wrong number of arguments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<style> | |
//put all styles here | |
body { | |
background: brown; | |
} | |
</style> | |
<body> | |
<!-- Put all html here --> | |
horse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean compare(Grid<T> grid2) { | |
if(this.row != grid2.row || this.col != grid2.col) { | |
return false; | |
} | |
for(Grid<T>.Element tmpElem : this.elements()) { | |
Grid<T>.Element tmpElem2 = grid2.getElement(tmpElem.pos()); | |
T v1 = tmpElem.value(); | |
T v2 = tmpElem2.value(); |
NewerOlder