Skip to content

Instantly share code, notes, and snippets.

Edvard Majakari EdvardM

Block or report user

Report or block EdvardM

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .pylintrc_compact
[MASTER]
extension-pkg-whitelist=
ignore=CVS
ignore-patterns=
jobs=4
limit-inference-results=100
persistent=yes
suggestion-mode=yes
unsafe-load-any-extension=no
[MESSAGES CONTROL]
@EdvardM
EdvardM / pybootstrap.sh
Last active Jun 17, 2019
Simple bootstrapt script intended to be used /w curl or similar
View pybootstrap.sh
#!/usr/bin/env bash
# This script is intended to setup things so that more advanced project commands (doit, poetry) can be easily used
set -eu
VENV_DIR=".venv"
echo "Creating venv to ${VENV_DIR} unless present"
test -d ${VENV_DIR} || python3 -m venv ${VENV_DIR}
echo "Activate venv and install poetry"
@EdvardM
EdvardM / tenacity-simple.py
Last active Jun 4, 2019
Most simple tenacity usage
View tenacity-simple.py
# Just a simple one-liner to quickly make a thing retrieable
import tenacity as tn
@tn.retry(wait=tn.wait_exponential(multiplier=1, min=10), stop=tn.stop_after_attempt(5))
@EdvardM
EdvardM / dhontd.py
Last active Apr 14, 2019
Toy program for playing with D'Hondt system
View dhontd.py
import argparse
import logging
import random
import string
from itertools import groupby
from operator import itemgetter
PARTIES = ["Kesk", "Kok", "SDP", "Sin", "PS", "Vihr", "Vas", "RKP", "KD", "TL", "EOP", "FP", "IPU", "KP", "KTP", "Lib",
"PP", "SKE", "SKP"]
@EdvardM
EdvardM / mapply.py
Last active Jun 18, 2019
Just a simply utility to apply sequence of functions, applying each in turn to return value of previous application
View mapply.py
def mapply(init, *funs, stop=lambda x: x is None):
"""
Apply list of funs from first to last, stopping when encountering first
return value of None.
Args:
init (Any): initial value
*funs (*Callable[..., Any]): List of functions to apply
Keyword args:
@EdvardM
EdvardM / pattern_to_seq.py
Last active Jul 14, 2018
Just a simple tool to remap long regular patterns with shorter ones, useful for comparing two sets of data for equality
View pattern_to_seq.py
import re
import sys
import string
def _get_fh(has_fname):
if has_fname:
return open(sys.argv[1])
else:
return sys.stdin
@EdvardM
EdvardM / pre-commit.sh
Created Apr 24, 2018
Simple pre-commit hook for checking python files with pycodestyle before committing
View pre-commit.sh
#!/bin/sh
set -u
FILES=$(git diff --cached --name-only --diff-filter=ACM)
pycodestyle ${FILES}
@EdvardM
EdvardM / better_mock_error_messages.py
Last active Mar 27, 2018
Make mock assertion failures readable
View better_mock_error_messages.py
# 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:
@EdvardM
EdvardM / bowling.hs
Last active Mar 19, 2018
Bowling kata, haskell version
View bowling.hs
-- 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 Feb 21, 2018
Simple stats module
View stats.py
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)
You can’t perform that action at this time.