Skip to content

Instantly share code, notes, and snippets.

View pioz's full-sized avatar
🧙‍♂️
[object Object]

Enrico pioz

🧙‍♂️
[object Object]
View GitHub Profile
@pioz
pioz / tenants.rb
Last active April 23, 2024 07:49
Tenants
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'mysql2'
end
require 'active_record'
@pioz
pioz / caffe.py
Last active February 9, 2024 15:50
Run caffeinate from Mac OS X menu bar
import rumps
import subprocess
class CaffeinateApp(rumps.App):
def __init__(self):
super(CaffeinateApp, self).__init__("Caffeinate")
self.icon = "inactive_icon.png"
self.caffeinate_process = None
self.menu = ["Run Caffeinate"]
@pioz
pioz / amazon.rb
Last active February 6, 2024 11:51
Ruby script to get Amazon expenses
require 'date'
regexp = /(\d{1,2} \w+ \d{4})|(?:-EUR (\d+,\d{2}))/
results = DATA.read.scan(regexp)
expenses = Hash.new { 0 }
date = nil
results.each do |str_date, str_amount|
date = Date.parse("0#{str_date}").strftime("%B-%Y") if str_date
if str_amount
@pioz
pioz / one_piece_downloader.rb
Last active September 6, 2023 18:45
One Piece Downloader
require 'open-uri'
require 'tty-progressbar'
CONCURRENCY = 8
FIRST_EPISODE_NUMBER = 1
LAST_EPISODE_NUMBER = 628
def get_bounds(episode_number)
episode_number = 1 if episode_number < 1
lower_bound = ((episode_number - 1) / 100) * 100 + 1
@pioz
pioz / edit_rails.md
Created March 21, 2023 09:46
Inflections on rails new
nano ~/.rbenv/versions/3.2.0/bin/rails

Add these lines before load Gem...:

require 'active_support'
ActiveSupport::Inflector.inflections { |inflect| inflect.acronym 'CT' }
@pioz
pioz / painting_height.md
Last active November 22, 2022 13:01
Perfect height to hang a painting

For hanging pictures I really like to follow the midline style. In practice an imaginary line is drawn on the wall which is at 5/8 the height of the wall itself. Once we have this line in mind the paintings must be hung with 3/8 of their height above the median line.

h = (H*5 + q*3) / 8

where H is the height of the wall and q is the height of the painting itself.

@pioz
pioz / query.sql
Created September 29, 2022 08:20
Select records by ids and order by ids order
SELECT id FROM products WHERE id IN (2,1) ORDER BY array_position(array[2,1], id);
@pioz
pioz / populate.rb
Last active September 19, 2022 07:25
Active Record in script
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'pg'
end
require 'active_record'
@pioz
pioz / install_ortools.sh
Last active September 12, 2022 08:35
Install ortools on OSX M1
git clone https://github.com/google/or-tools.git
cd ./or-tools
cmake -S. -Bbuild -DBUILD_PYTHON=ON -DPython3_ROOT_DIR="/opt/homebrew/Cellar/python@3.9/3.9.10/"
cmake --build build -j8 -v
pip3 install ./build/python/dist/ortools-9.2.9974-cp39-cp39-macosx_12_0_arm64.whl
@pioz
pioz / query.md
Created May 4, 2022 13:50
Select products and order by converted price currency
SELECT price_cents FROM products ORDER BY price_cents * ('{"EUR": 2.0}'::jsonb->'EUR')::jsonb::numeric;