Skip to content

Instantly share code, notes, and snippets.

View rafaltrojanowski's full-sized avatar
🛰️

Rafał Trojanowski rafaltrojanowski

🛰️
View GitHub Profile
Local fix of type:
index = "answers"
{:ok, response} = Domain.Env.get(:elasticsearch_url) |> URI.merge("/#{index}/_mapping?pretty") |> URI.to_string() |> Elastix.HTTP.get()
body = response.body
Map.keys(body["answers"]["mappings"]["properties"]["label_ids_with_keywords"]["properties"]) |> Enum.count
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 / gist:9752bc936d36f2de0a5338abb8e092fb
Last active September 26, 2018 04:46
component-refractor.js
import Component from '@ember/component'; // modern syntax
export default Component.extend({ // redundant Ember, that has been already imported.
count: 1, // it will start from 2, imho it should be 0
// Use didInsertElement hook instead of init.
// I assume that we want to start updating counter begining from the moment when the element was inserted to the DOM.
// `init` is called before didInsertElement() and would lead to some
// init() does several things behind the scenes.
@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.*