Skip to content

Instantly share code, notes, and snippets.

View edvardm's full-sized avatar

Edvard Majakari edvardm

  • Rakettitiede Oy
  • Finland
  • 03:42 (UTC +03:00)
View GitHub Profile
@edvardm
edvardm / symbolize_recursive.rb
Last active May 22, 2020 04:17
Recursively symbolize ruby hash keys in a nested structure. Uses refinements instead of monkey patching Hash.
module SymbolizeHelper
extend self
def symbolize_recursive(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_sym] = transform(value) }
end
end
private
@edvardm
edvardm / ruby-tools-install.sh
Created October 5, 2015 10:56
script to install pry and some other nice tools for Ruby
#!/usr/bin/env bash
#
# Simple script to setup friendly environment for beginning Linux/Mac Ruby users
#
echo "installing pry and awesome_print"
gem install -q --no-ri --no-rdoc \
pry pry-doc pry-coolline awesome_print
# Nifty pry config copied from https://github.com/dotphiles/dotphiles/blob/master/ruby/aprc
@edvardm
edvardm / argparse.py
Created January 16, 2020 10:07
Very simple template for creating simple python CLI tools with argparse
import argparse
def parse_args():
parser = argparse.ArgumentParser(
description="", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("-v", "--verbose", action="store_true", help="be more verbose")
return parser.parse_args()
@edvardm
edvardm / clean_code.md
Created December 18, 2019 13:52 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@edvardm
edvardm / .pylintrc_compact
Created December 5, 2019 12:38
compact pylintrc
[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 / mapply.py
Last active June 18, 2019 08:07
Just a simply utility to apply sequence of functions, applying each in turn to return value of previous application
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 / pybootstrap.sh
Last active June 17, 2019 12:22
Simple bootstrapt script intended to be used /w curl or similar
#!/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 / 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 / tenacity-simple.py
Last active June 4, 2019 11:43
Most simple tenacity usage
# 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 April 14, 2019 12:26
Toy program for playing with D'Hondt system
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"]