Skip to content

Instantly share code, notes, and snippets.

barahilia / json-pattern-matcher
Last active Aug 29, 2015
JSON pattern matching
View json-pattern-matcher
Allows match JSON objects by pattern. Intended for APIs comparison and verification.
{ a: 1, b: ['x', 'y'] }, // pattern
{ a: 42, b: ['first', 'second', 'any', 'last'] } // object for check
barahilia / tdd-trees-comp-c++
Last active Aug 29, 2015
TDD for trees comparison in C++
View tdd-trees-comp-c++
Build with: `g++ test.cpp && ./a.out`
For editing two files in `vim` run command `:vsplit tree.h`.
barahilia /
Created Oct 12, 2014
Kramdown yellow highlight
Fill details here...
barahilia /
Last active Aug 29, 2015
Points compression algo

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.

"""Find exit from the fractal maze.
from unittest import TestCase
from Queue import PriorityQueue
from collections import defaultdict
from itertools import count, product
barahilia /
Last active Jul 28, 2016
Tampering class method in python (temporarily replacing/mocking/faking for unit test)
import functools
def tamper(target, attr_name, mock_obj):
def decor(func):
def worker(*args, **kwargs):
backup = getattr(target, attr_name)
setattr(target, attr_name, mock_obj)
from unittest import TestLoader, TextTestRunner
def discover_and_run(verbose=False, names=None):
# names is None or a list [name, ...]
# name is test_suite[.class[.name]]
verbosity = 2 if verbose else 1
loader = TestLoader()
if names:
from unittest import TestSuite
def print_tests(tests):
if isinstance(tests, TestSuite):
for child in tests:
print # package.module.TestClass.test_name
barahilia / run-jasmine.js
Last active Mar 2, 2017 — forked from dlidstrom/run-jasmine.js
Runs Jasmine tests using PhantomJS. Adapted for use within TeamCity..Compatible with Jasmine 2.0.
View run-jasmine.js
var system = require('system'),
env = system.env;
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
* @param testFx javascript condition that evaluates to a boolean,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.