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
| class SummedAreaTable(object): | |
| def __init__(self, size, data): | |
| """ | |
| Just because I dislike a 2d array / list. | |
| data should be a List of Integer. | |
| """ | |
| width, height = size | |
| assert width * height == len(data), "invalid data length and or data size" | |
| self.size = size | |
| self.data = data |
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
| class Matrix(list): | |
| def __init__(self, *args): | |
| super(Matrix, self).__init__(args) | |
| def __mul__(self, other): | |
| def dotproduct(As, Bs): | |
| return sum(a * b for a, b in zip(As, Bs)) | |
| otherT = zip(*other) | |
| return Matrix(*[[dotproduct(As, Bs) for Bs in otherT] for As in self]) |
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
| class Matrix(list): | |
| def __init__(self, *args): | |
| super(Matrix, self).__init__(args) | |
| def __mul__(self, other): | |
| def dotproduct(As, Bs): | |
| return sum(a * b for a, b in zip(As, Bs)) | |
| otherT = zip(*other) | |
| return Matrix(*[[dotproduct(As, Bs) for Bs in otherT] for As in self]) |
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 re | |
| class State(): | |
| class NotValidTrigger(BaseException): pass | |
| def __init__(self, name, isEndState): | |
| self.triggers = [] | |
| self.name = name | |
| self.isEndState = isEndState | |
| def addTrigger(self, trigger, nextState): |
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
| class Field: | |
| """ | |
| custom-version of array-2d. | |
| when instatiated, each element inside will be initialized with `initial` value. | |
| e.g: | |
| >> Field(2) | |
| [[None, None], | |
| [None, None]] | |
| """ | |
| @classmethod |
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
| class CamelCase | |
| # @param original [String] | |
| def initialize(original) | |
| @original = original | |
| end | |
| # @return [String] | |
| def refactored | |
| regex = /(?:(?:\.)|(?:\:)|(?:\()|(?:\{)|(?:\[)| )[a-z_]+(?:[A-Z][a-z]+)+/ |
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 os | |
| import operator as op | |
| from memoized_property import memoized_property | |
| import re | |
| # credit to: | |
| # http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size | |
| def sizeof_fmt(num, suffix='B'): | |
| for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: | |
| if abs(num) < 1024.0: |
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 operator as op | |
| import re | |
| class PatternLocation: | |
| def __init__(self, pattern, start): | |
| self._pattern = pattern | |
| self._start = start | |
| @property | |
| def stop(self): |
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
| module DNAEncoder where | |
| import qualified Data.Algorithms.KMP as KMP | |
| import qualified Data.List as DL | |
| import qualified Control.Monad as CM | |
| data PLoc a = PLoc { | |
| pattern :: [a], | |
| start :: Int | |
| } deriving (Show) |
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 flask import Flask, request, send_from_directory | |
| import json | |
| import os | |
| app = Flask(__name__) | |
| @app.route('/<path:path>') | |
| def send_result(path): | |
| print(path) | |
| return send_from_directory("./", path) |
OlderNewer