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 qualified Data.Char as Char | |
data Things t = Things {thing :: t, quantity :: Int} | |
instance (Show t) => Show (Things t) | |
where | |
show t = if quantity t == 1 then get t else get t ++ "s" | |
where | |
get = filter (not . (`elem` "\"")) . show . thing | |
makeSentence :: (Show t) => [Things t -> String] -> t -> Int -> String |
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 math | |
def parse(expression, variables=None, context=vars(math)): | |
variables = ','.join(variables) if variables is not None else '' | |
context = dict(context) if context is not None else {} | |
return eval('lambda {}: {}'.format(variables, expression), None, context) |
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 weakref | |
class memoized_property(property): | |
def __init__(self, *args, **kwargs): | |
super(memoized_property, self).__init__(*args, **kwargs) | |
self.data = weakref.WeakKeyDictionary() | |
def __get__(self, instance, owner=None): |
NewerOlder