Skip to content

Instantly share code, notes, and snippets.

View edvardm's full-sized avatar

Edvard Majakari edvardm

  • Rakettitiede Oy
  • Finland
  • 02:12 (UTC +03:00)
View GitHub Profile
@edvardm
edvardm / bowling.hs
Last active March 19, 2018 15:17
Bowling kata, haskell version
-- 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)
@edvardm
edvardm / stats.py
Created February 21, 2018 14:57
Simple stats module
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)
@edvardm
edvardm / stats.py
Last active June 5, 2019 13:17
Simple statistics module
# 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)
@edvardm
edvardm / progress_bar.py
Created January 26, 2018 15:38
Simple python progress bar updater, using progressbar2
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)
@edvardm
edvardm / avgtime.sh
Created September 26, 2017 13:22
Script to run command multiple times and return averages
#!/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.$$
@edvardm
edvardm / context_manager_profiler.py
Created September 13, 2017 15:49
Simple context manager for python cProfiler
import cProfile, pstats, io
class MyProfiler:
def __init__(self):
self.pr = cProfile.Profile()
self.pr.enable()
def __enter__(self):
return self.pr
@edvardm
edvardm / pre-commit.sh
Created September 6, 2017 07:34
python pre-commit lint hook
# 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"
@edvardm
edvardm / buffer.fy
Last active July 18, 2017 14:10
Simple buffer for running arbitrary operations in batches
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.
FROM ubuntu:trusty
MAINTAINER edvard@rakettitiede.com
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
s = filterM (const [True, False])