Demonstration of phenomenon, when caller cumulative time can be less than the callee, given it's the only caller. This may happen if callee is generator and caller returns callee object as is. Then profiler sees a lot of time spent in callee and almost no time at caller.
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 | |
def tamper(target, attr_name, mock_obj): | |
def decor(func): | |
@functools.wraps(func) | |
def worker(*args, **kwargs): | |
backup = getattr(target, attr_name) | |
try: | |
setattr(target, attr_name, mock_obj) |
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
"""Find exit from the fractal maze. | |
See http://puzzling.stackexchange.com/questions/37675/alice-and-the-fractal-hedge-maze | |
""" | |
from unittest import TestCase | |
from Queue import PriorityQueue | |
from collections import defaultdict | |
from itertools import count, product |
Implementation of algorithm for points compression. For more details see the post: http://barahilia.github.io/blog/computers/2014/10/11/points-on-plane-compression.html.
Given an array of 2D points, each coordinate a 16-bit integer, split them all to squares on 256x256 grid and encode each coordinate with one byte only.
This gits features encoding functions, unit tests and a sample file.
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
Build with: `g++ test.cpp && ./a.out` | |
For editing two files in `vim` run command `:vsplit tree.h`. | |
http://www.cs.swarthmore.edu/help/vim/windows.html |
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
Allows match JSON objects by pattern. Intended for APIs comparison and verification. | |
E.g.: | |
compare( | |
{ a: 1, b: ['x', 'y'] }, // pattern | |
{ a: 42, b: ['first', 'second', 'any', 'last'] } // object for check | |
); |
NewerOlder