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
# mock objects print assertion failures in a way that is hard to read. | |
# | |
# Example: | |
# | |
# AssertionError: Expected call: <mock assertion failure: 1122331 ...> | |
# Actual call: <mock assertion failure: 112331 ...> | |
# | |
# After the patch: | |
# | |
# AssertionError: |
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
-- Credits to awesome Haskell Master Sami Hangaslammi (shangaslammi) who told to learn unfoldr, which | |
-- leads IMO to very elegant solution. | |
-- | |
-- 2012: original version, Hspec outdated, no longer available | |
-- 2018-03-19: Updated to recent Hspec | |
-- Running: cabal install hspec-2.4.4 && runhaskell bowling.hs | |
import Test.Hspec | |
import Data.List (unfoldr) |
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 statistics import mean, median_low, stdev, mode | |
def stat(lst): | |
if not lst: | |
return None | |
_min = min(lst) | |
_max = max(lst) | |
_mean = mean(lst) |
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
# Simple stats module. For large sets of data, check Numpy instead | |
from statistics import mean, median_low, stdev, mode | |
def stat(lst): | |
if not lst: | |
return None | |
_min = min(lst) |
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 contextlib | |
import os | |
import progressbar | |
@contextlib.contextmanager | |
def build_updater(**kwargs): | |
kwargs['max_value'] = kwargs.get('max_value', progressbar.UnknownLength) | |
update_interval = kwargs.get('update_interval', 1) |
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
#!/bin/bash | |
# Script originally by bobmcn, taken from | |
# https://stackoverflow.com/questions/17601539/calculate-the-average-of-several-time-commands-in-linux | |
# Changelog: added NSAMPLES to run given script only given number of times (defaults to 3) | |
NSAMPLES=${NSAMPLES-3} | |
rm -f /tmp/mtime.$$ |
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 cProfile, pstats, io | |
class MyProfiler: | |
def __init__(self): | |
self.pr = cProfile.Profile() | |
self.pr.enable() | |
def __enter__(self): | |
return self.pr |
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
# need to install by running `pip install git-pylint-commit-hook` | |
# in .git/hooks/pre-commit: | |
git-pylint-commit-hook --limit=9.5 --pylint-params="-j4 -rn" |
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 typing import TypeVar, List, Callable | |
import logging | |
from datetime import datetime | |
T = TypeVar('T') | |
Inserter = Callable[[List[T]], None] | |
class Buffer: | |
"""Buffer items until either max_size or max_time has been reached. |
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 ubuntu:trusty | |
MAINTAINER [email protected] | |
ENV REVISION 0.1 | |
ENV DEBIAN_FRONTEND noninteractive | |
# system installation / dependencies | |
RUN apt-get -q -y update && \ | |
apt-get install -y git npm redis-server |