Skip to content

Instantly share code, notes, and snippets.

View haskel_tutorial.hs
import Data.List
import Text.Regex
import System.Random
import Data.Ord
type Point = (Float,Float)
type Color = (Int,Int,Int)
type Polygon = [Point]
type Person = [Int]
type Link = [Point]
barahilia /
Last active Jan 29, 2019
Lines on image
#!/usr/bin/env python
import cv2
import numpy as np
from rectangles import Line, line_frequencies, rectangles
def lines_to_file(lines):
barahilia /
Created Feb 8, 2017
A defaultdict that can be frozen after which it will not add new missing keys but still return a default object
from collections import defaultdict
class freezable_defaultdict(dict):
def __init__(self, default_factory, *args, **kwargs):
self.frozen = False
self.default_factory = default_factory
super(freezable_defaultdict, self).__init__(*args, **kwargs)
def __missing__(self, key):
barahilia / workaround.js
Created Sep 9, 2014
Workaround for R# complaining on use of an implicitly declared global variable
View workaround.js
// This is a workaround for R# complaining on undefined global variables.
// In practice they come from and are defined by Jasmine and Protractor
// frameworks, so are not a real issues.
// Jasmine
var describe = function () { };
var beforeEach = function () { };
var afterEach = function () { };
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.
from unittest import TestSuite
def print_tests(tests):
if isinstance(tests, TestSuite):
for child in tests:
print # package.module.TestClass.test_name
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:
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)