Skip to content

Instantly share code, notes, and snippets.

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
// The following are required for implementing the Iterable and Iterator interfaces.
import java.lang.Iterable;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class SeekableList<T> {
// Pointers
int a = 3, b = 4;
int c = 1, d = 2;
int* pa = &a;
int e = *pa;
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();
<html>
<style>
//put all styles here
body {
background: brown;
}
</style>
<body>
<!-- Put all html here -->
horse
@spitz-dan-l
spitz-dan-l / multiple_dispatch.py
Last active June 8, 2017 14:34
Advanced python multiple dispatch implementation very advanced
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
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
@spitz-dan-l
spitz-dan-l / bad_monads.py
Last active February 28, 2019 17:55
Bad Monads
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.
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
@spitz-dan-l
spitz-dan-l / graph_transform_pickle.py
Last active March 16, 2019 17:07
Python Atrocity: Graph-Transformation-Oriented Programming via Pickle
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
"""
@spitz-dan-l
spitz-dan-l / matching.py
Last active April 26, 2019 06:04
Python Atrocity: Structural Pattern Matching built on Exception Handling Syntax
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