Skip to content

Instantly share code, notes, and snippets.

View rafaltrojanowski's full-sized avatar
🛰️
KISS (BUZI), DRY, SOLID, YAGNI

Rafał Trojanowski rafaltrojanowski

🛰️
KISS (BUZI), DRY, SOLID, YAGNI
View GitHub Profile
require 'date'
def daily_cost(start_date, end_date, time_period_costs)
daily_cost = {}
if start_date > end_date
raise "Wrong time period given."
end
(start_date..end_date).each do |date|
@rafaltrojanowski
rafaltrojanowski / VSCode
Last active September 26, 2019 07:37
Vim -> VSCode migration
1. Install vscodevim
2. Run from terminal:
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false # Key repeat
3. jj:
Add to settings.json:
"vim.insertModeKeyBindings": [
{
@rafaltrojanowski
rafaltrojanowski / whiteboardCleaner.md
Created March 13, 2019 08:49 — forked from lelandbatey/whiteboardCleaner.md
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

# Source:
# https://macpaw.com/how-to/startup-disk-full-on-mac-os-x
#!/usr/bin/env bash
rm -rf ~/Library/Caches/*
rm -rf /Library/Caches/*
rm -rf ~/Music/iTunes/Previous\ iTunes\ Libraries/*
rm -rf ~/Library/Application\ Support/MobileSync/Backup/*
rm -rf ~/Library/iTunes/iPhone\ Software\ Updates/*
@rafaltrojanowski
rafaltrojanowski / money_best_practices.md
Created November 9, 2018 09:50 — forked from abhinavmsra/money_best_practices.md
Tips for Money Related Arithmetic in Ruby

Tips for Money Related Arithmetic in Ruby

  1. Never use float for performing arithmetic calculations relating to money.

    Floating numbers can sometimes show funky behaviour. It is not Ruby’s fault but the very implementation of floating numbers raises precision issues.

Examples of odd behaviour:

import Component from '@ember/component'
export default Component.extend({
// Note: I do believe that counter should start couting from 0
// that has been fixed with following implementation.
// Previous implemention updated counter on component initialization, so in fact it resulted with counting from 1
count: 0,
interval: 1000, // I would extract that property to be able to modify it quickly without jumping into details of implementation.
@rafaltrojanowski
rafaltrojanowski / rotate.md
Created August 16, 2018 09:51 — forked from abhinavmsra/rotate.md
Rotating Server Logs

#Rotating Server Logs with LogRotate

Logrotate is a UNIX utility that does following operations:

  1. Rotates the log file when file size reaches a specific size or after a specified duration
  2. Continues to write the log information to the newly created file after rotating the old log file
  3. Compresses the rotated log files
  4. Specifies compression option for the rotated log files
@rafaltrojanowski
rafaltrojanowski / .gitignore
Created August 6, 2018 16:24 — forked from zilkey/.gitignore
curry example - a way to do dependency injection using lambdas
Gemfile.lock
junk.*
@rafaltrojanowski
rafaltrojanowski / weather_o_rama.rb
Created August 6, 2018 10:45 — forked from wulab/weather_o_rama.rb
Weather-O-Rama Inc.’s next generation, Internet-based Weather Monitoring Station
module Subject
def register_observer()
raise NotImplementedError
end
def remove_observer()
raise NotImplementedError
end
def notify_observers()
sample_input_0 = """
10
2
"""
sample_input_1 = """
100
2
"""
sample_input_2 = """