This file contains 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
class LMComputer: | |
class Memory: | |
def __init__(self): | |
self.__cells = [0] * 100 | |
def __getitem__(self, key): | |
return self.__cells[key] | |
def __setitem__(self, key, value): | |
if isinstance(key, int) and 0 <= key <= 99: |
This file contains 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 operator | |
__all__ = ['weak'] | |
def apply_operator(op, a, b): | |
types = lambda x: x, float, int, complex | |
for a_type in types: | |
for b_type in types: | |
try: | |
return op(a_type(a), b_type(b)) |
This file contains 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 functools, itertools | |
class StreamIterator: | |
""" | |
Iterator class for a Stream | |
This class manages the cache for a regular Stream; it is unnecessary for a | |
ContainerStream. | |
""" | |
This file contains 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
#include <functional> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
template <typename InputIt> class From; | |
template <typename InputIt, typename OutType, typename InType> class Select; | |
template <typename InputIt, typename ItemType> class Where; | |
template <typename InputIt, typename OutType, typename InType> |
This file contains 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 inspect | |
def name_of_type (t): | |
if "__class__" in dir(t): | |
return t.__class__.__name__ | |
else: | |
return type(args[i]).__name__ | |
def argtypes(*__argtypes_types__, **__argtypes_kwtypes__): |
This file contains 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
class Heading (set): | |
def __init__(self, *attributes): | |
if len(attributes) == 1 \ | |
and isinstance(attributes[0], (list, tuple, set)): | |
attributes = attributes[0] | |
for att in attributes: | |
if not isinstance(att, str): | |
print(att) | |
raise TypeError("Attribute name must be string.") | |
if att == "": |
This file contains 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 functools | |
from inspect import _empty, signature | |
class Function: | |
"""Decorator class for callables, making them curried and composable.""" | |
class Recursor: | |
"""Wrapper class for identifying tail recursive calls to trampoline them.""" | |
def __init__(self, fn): |
This file contains 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
# Functional-paradigm decorators | |
def curried (function): | |
argc = function.__code__.co_argcount | |
# Subtract the defaults from the minimum arity | |
if function.__defaults__: | |
argc -= len(function.__defaults__) | |
# Pointless to curry a function that can take no arguments |
This file contains 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
// Damerau-Levenshtein edit distance implementation in C99 | |
// | |
// Based on pseudocode from Wikipedia: <https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance> | |
// and on my Python implementation: <https://gist.github.com/badocelot/5327337> | |
int damerau_levenshtein_distance (const char *source, const char *target) | |
{ | |
// Size of the strings and dimensions of the matrix | |
int m = 0; | |
if (source != NULL) | |
m = strlen(source); |
This file contains 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
# Damerau-Levenshtein edit distane implementation | |
# Based on pseudocode from Wikipedia: https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance | |
# Copyright © 2013 James Jensen | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the “Software”), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
NewerOlder