Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile
@wojtha
wojtha / getdeep.py
Created April 28, 2022 08:22 — forked from av1m/getdeep.py
Crosses a list or dictionary in an elegant way using list or str as key
"""Utility functions"""
from functools import reduce
from operator import getitem
from typing import Any, Mapping, Union
def getdeep(data: Mapping, map_list: Union[list, str], default: Any = None) -> Any:
"""Iterate nested dictionary|list and can return default value if key not found
@wojtha
wojtha / .gitattributes
Created October 22, 2020 21:45 — forked from tekin/.gitattributes
An example .gitattributes file that will configure custom hunk header patterns for some common languages and file formats. See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details.
*.c diff=cpp
*.h diff=cpp
*.c++ diff=cpp
*.h++ diff=cpp
*.cpp diff=cpp
*.hpp diff=cpp
*.cc diff=cpp
*.hh diff=cpp
*.m diff=objc
*.mm diff=objc
@wojtha
wojtha / jobs_retry.rb
Created April 14, 2020 19:00
Collection of background jobs retry strategies
# This module collects various background job retry schedule strategies including the helper functions for the rendering
# of the retry table schedule to give better idea in which time frame the jobs are going to be run again.
#
# Inspired by https://github.com/isaacseymour/activejob-retry and
# https://github.com/mperham/sidekiq/wiki/Error-Handling#automatic-job-retry
#
module JobRetry
module_function
# Builtin default Sidekiq retry strategy.
@wojtha
wojtha / fakturuj.rb
Created April 7, 2020 08:25
Script for easy CZK-USD invoicing
#!/usr/bin/env ruby
require 'net/http'
require 'ostruct'
require 'optparse'
module Fakturuj
class Application
# https://github.com/honzajavorek/cs-apis/wiki/Kurzy-devizov%C3%A9ho-trhu-%C4%8CNB
CNB_DENNI_KURZ_TXT = URI('https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt').freeze
@wojtha
wojtha / status_factory.rb
Created March 31, 2020 09:43
Ruby: Class StatusFactory is module factory to generate Status classes
# Class StatusFactory is module factory to generate Status classes
#
# @example Status class definition
#
# class Result
# include StatusFactory.new(:success, :failure, query: true, callbacks: true, factory: true, equality: true)
# end
#
# # is equivalent of:
#
@wojtha
wojtha / rmbr
Created February 20, 2020 11:02
Remove local git branch when it is linked to non-existing remote branch
#!/usr/bin/env bash
# Based on https://stackoverflow.com/a/33548037
# Maybe we can add this: https://stackoverflow.com/a/32166469
echo "*** Local tracking branches with removed remote branches:"
# List files
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }'
@wojtha
wojtha / keybase.md
Created December 16, 2019 12:32
Verification of https://keybase.io/

Keybase proof

I hereby claim:

  • I am wojtha on github.
  • I am wojtha (https://keybase.io/wojtha) on keybase.
  • I have a public key ASDFVo3o5gk9RM2nqCuwdyrOR3w4ODkzQaJ7U2Wn410ksQo

To claim this, I am signing this object:

@wojtha
wojtha / _example_finder.rb
Last active October 30, 2019 18:10
An ActiveRecord::Finder implementation to extract query methods from the ApplicationRecord classes.
class ExampleFinder < ApplicationRecordFinder
finder_for ::Example
def list_examples_active_at(time)
active_at(time).all
end
def list_past_examples
where('end_at < ?', Time.current).all
@wojtha
wojtha / interactor.rb
Created October 30, 2019 17:57
Interactor based on Hanami::Interactor, adapted for Rails/ActiveSupport.
# Interactor based on Hanami::Interactor, adapted for Rails/ActiveSupport.
#
# @see https://github.com/hanami/utils/blob/master/lib/hanami/interactor.rb
#
module Interactor
# Result of an operation
#
class Result
# Concrete methods
#
@wojtha
wojtha / micro_timer.rb
Last active October 30, 2019 17:47
Ruby library to measure time using the Process::CLOCK_MONOTONIC.
# Library to measure time using the Process::CLOCK_MONOTONIC.
#
# @example Usage
# timer = MicroTimer.start
# sleep 0.1 # some process to measure
# puts timer.duration.milliseconds
# sleep 0.1 # another process to measure
# puts timer.duration.seconds
#
# @example Usage with block