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 PGArrayField(models.Field): | |
""" Custom field for mapping between postgresql array and python list.""" | |
def __init__(self, element_field, **kwargs): | |
self.element_field = element_field | |
models.Field.__init__(self, **kwargs) | |
def db_type(self, *connection): | |
return '%s[]' % self.element_field.db_type(*connection) |
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 TestModel(models.Model): | |
f = models.TextField() | |
a = PGArrayField(models.IntegerField(), null=True) |
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
""" Contract2.""" | |
class ValidationError(TypeError): | |
pass | |
class Type(object): | |
def validate(self, value): | |
raise NotImplementedError() |
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
""" Validating Python data structures.""" | |
__all__ = ( | |
"ValidationError", | |
"Type", "Or", "And", "Optional", "NullType", "Nullable", "Null", | |
"IntType", "StringType", "BoolType", | |
"Int", "String", "Bool", | |
"Sequence", "Mapping") | |
class ValidationError(TypeError): |
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
Prelude> let ngrams n seq@(_:tail) | length seq >= n = (take n seq):(ngrams n tail); ngrams _ _ = [] | |
Prelude> ngrams 1 [1,2,3] | |
[[1],[2],[3]] | |
Prelude> ngrams 2 [1,2,3] | |
[[1,2],[2,3]] | |
Prelude> ngrams 3 [1,2,3] | |
[[1,2,3]] |
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 S[A, B, C] { | |
def apply[A, B, C](f: A => (B => C), g: A => B, x: A): C = | |
(f(x))(g(x)) | |
} |
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
mpb % python -m timeit -s 'from peg import expr, parse' "parse(expr, '1+1+3+123-12*(1212+2)')" | |
1000 loops, best of 3: 231 usec per loop | |
mpb % pypy -m timeit -s 'from peg import expr, parse' "parse(expr, '1+1+3+123-12*(1212+2)')" | |
1000 loops, best of 3: 30.6 usec per loop |
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
from peg import * | |
from collections import namedtuple | |
Select = namedtuple("Select", | |
["select_list", "from_clause", "where_clause", "offset_clause", "limit_clause"]) | |
From = namedtuple("From", ["table", "joins"]) | |
_Ref = namedtuple("Ref", ["parts"]) | |
Join = namedtuple("Join", ["table", "condition"]) | |
AllColumns = namedtuple("AllColumns", []) | |
UsingJoinCond = namedtuple("UsingJoinCond", ["columns"]) |
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
#!/usr/bin/env python | |
"""usage: bte file | |
arguments: | |
file filename or - to read from stdin | |
options: | |
-h, --help show this message and exit |
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
"" We don't like plain vi | |
set nocompatible | |
filetype off | |
"" Initialize pathogen | |
call pathogen#helptags() | |
call pathogen#runtime_append_all_bundles() | |
"" Preferences | |
let mapleader="," |