Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile

Description

Changes

@wojtha
wojtha / download.rb
Last active February 3, 2023 14:06
Download binary file with 'open-uri' and 'IO.copy_stream'
require 'open-uri'
# Net::HTTP.get(uri) does't work for binary files. File gets corrupted.
#
# File is opended in binary write mode "wb". The "open" method is provided
# by open-uri and is considered unsafe for user input! The "rb" stands for
# binary read mode.
#
# IO.copy_stream does not load the whole file in memory.
#
@wojtha
wojtha / gist:1034262
Created June 19, 2011 13:16
PHP Syntax Check for Git pre-commit hook for Windows PowerShell
###############################################################################
#
# PHP Syntax Check for Git pre-commit hook for Windows PowerShell
#
# Author: Vojtech Kusy <wojtha@gmail.com>
#
###############################################################################
### INSTRUCTIONS ###
@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 / Locales.yaml
Created January 15, 2014 10:13 — forked from s-andringa/Locales.yml
config.exceptions_app and ExceptionController
# config/locales/en.yml
en:
exception:
show:
not_found:
title: "Not Found"
description: "The page you were looking for does not exists."
internal_server_error:
title: "Internal Server Error"
@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 / CaseConverter.php
Last active September 4, 2020 08:51
CaseConverter an static class for conversions betweenn camelCase <--> StudlyCase <--> snake_case.
<?php
/**
* Class CaseConverter
*
* Library for camelCase/StudlyCase/snake_case conversions.
*/
class CaseConverter {
/**
@wojtha
wojtha / bench_boolean.rb
Last active April 12, 2020 17:49
Seeking for the fastest "to boolean" implementation in ruby. See https://coderwall.com/p/inziba
require 'benchmark'
require 'set'
def to_boolean_eq(value)
value == true || value == 'true' || value == 1 || value == '1' || value == 't'
end
def to_boolean_equal(value)
value === true || value === 'true' || value === 1 || value === '1' || value === 't'
end
@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