Skip to content

Instantly share code, notes, and snippets.

View miharekar's full-sized avatar

Miha Rekar miharekar

View GitHub Profile
@miharekar
miharekar / .rubocop.yml
Last active January 4, 2024 14:31
My RuboCop standard
inherit_gem:
rubocop-rails-omakase: rubocop.yml
require:
- rubocop-performance
- rubocop-rails
AllCops:
NewCops: enable
TargetRubyVersion: 3.3
@miharekar
miharekar / Stripe Webhook Upgrader
Last active October 23, 2023 13:10
Stripe Webhook Upgrader
Since you can't update Stripe API version on a webhook, the only way to do it, is to disable one, and create a new one.
@miharekar
miharekar / Enable Rails cache for one unit test.md
Created March 24, 2023 11:09
Enable Rails cache for one unit test.md

#rails #minitest #testing

Add to test/test_helper.rb

    def with_cache
      @original_cache_store = Rails.cache
      Rails.cache = ActiveSupport::Cache::MemoryStore.new
      yield
    ensure
 Rails.cache = @original_cache_store
@miharekar
miharekar / Prevent email sending in Rails.md
Last active February 24, 2023 14:33
Prevent email sending in Rails.md

#rails #actionmailer #callbacks

Callbacks for mailers are implemented using AbstractController::Callbacks.

This has a terminator lambda: https://github.com/rails/rails/blob/6af9cba73db6296ab9aec7dbeae1e193ea69f09f/actionpack/lib/abstract_controller/callbacks.rb#L34

AbstractController::Base defines performed? as: return response_body https://github.com/rails/rails/blob/6af9cba73db6296ab9aec7dbeae1e193ea69f09f/actionpack/lib/abstract_controller/base.rb#L188

So - as soon as we set any response body, no other callbacks or actions will occur.

@miharekar
miharekar / obsidian-web-clipper.js
Last active November 9, 2022 08:00 — forked from kepano/obsidian-web-clipper.js
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([
import("https://unpkg.com/turndown@7.0?module"),
import("https://unpkg.com/@tehshrike/readability@0.2"),
]).then(([{ default: Turndown }, { default: Readability }]) => {
const vault = "";
const folder = "quick";
const tags = "#clippings";
function getSelectionHtml() {
var html = "";
@miharekar
miharekar / gps.rb
Created August 24, 2021 10:07
Copy GPS coordinates of a dropped in photo to clipboard
loop do
puts "Gimme photo\n"
path = gets
exifdata = value = `exiftool -c "%+.10f" #{path} `
line = exifdata.split("\n").find{|l| l.include?("GPS Position")}
if line.nil?
puts exifdata
puts "\nNO GPS 🤷‍♂️"
else
@miharekar
miharekar / benchmark.rb
Last active September 22, 2020 06:20
Starts with benchmark
require 'benchmark/ips'
Benchmark.ips do |x|
records = []
10_000.times do |i|
records << "#{['abc', 'rec', 'air'].sample}-#{i}-#{['abc', 'rec', 'air'].sample}-#{i}"
end
AIRTABLE_ID_REGEX = /rec(?!_)/.freeze
@miharekar
miharekar / quotes.json
Last active November 29, 2023 09:34
Stoic Quotes JSON
This file has been truncated, but you can view the full file.
{"quotes":[{"text":"We have two ears and one mouth, so we should listen more than we say.","author":"Zeno of Citium, as quoted by Diogenes Laërtius"},{"text":"Man conquers the world by conquering himself.","author":"Zeno of Citium"},{"text":"The goal of life is living in agreement with Nature.","author":"Zeno"},{"text":"if being is many, it must be both like and unlike, and this is impossible, for neither can the like be unlike, nor the unlike like","author":"Zeno"},{"text":"Well-being is attained little by little, and nevertheless is no little thing itself.","author":"Zeno of Citium"},{"text":"The reason why we have two ears and only one mouth is that we may listen the more and talk the less.","author":"Zeno"},{"text":"When a dog is tied to a cart, if it wants to follow, it is pulled and follows, making its spontaneous act coincide with necessity. But if the dog does not follow, it will be compelled in any case. So it is with men too: even if they don't want to, they will be compelled to follow what is desti
@miharekar
miharekar / .gitignore
Last active September 9, 2023 06:08
Stoic quotes from Goodreads
.DS_Store
@miharekar
miharekar / Gemfile
Last active January 28, 2019 14:49
UPN QR to N26 and Toshl
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'sinatra'
gem 'twentysix'