Skip to content

Instantly share code, notes, and snippets.

View DimaSamodurov's full-sized avatar
🇺🇦
Stand With Ukraine

Dmytro Samodurov DimaSamodurov

🇺🇦
Stand With Ukraine
  • EPAM
  • Lviv, Ukraine
View GitHub Profile
@DimaSamodurov
DimaSamodurov / colorize.rb
Last active September 17, 2024 14:43
List nested branches down to the master branch based on PR sequence (using GitHub command line)
module Colors
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 34
end
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
@DimaSamodurov
DimaSamodurov / .sqlfluff
Last active May 24, 2024 13:38
Linter configs
[sqlfluff]
dialect = clickhouse
templater = jinja
sql_file_exts = .sql,.sql.j2,.dml,.ddl
max_line_length = 140
; exclude CO03 capitalisation.functions as sqlfluff does not have camelCase option used by ClickHouse.
; https://docs.sqlfluff.com/en/stable/rules.html#rule-CP03
; exclude LT01 layout.spacing as it removes space alignment and adds space to `Nullable ()` call in some cases.
@DimaSamodurov
DimaSamodurov / test_gc.rb
Created June 11, 2023 23:01
measuring Ruby GC
require 'benchmark'
def show_memory_consumption
puts `pmap #{Process.pid} | tail -n 1`
end
#GC.disable
result = Benchmark.measure do
200.times { |i|
"a"*100_000_000
module A
def foo
:a
end
end
module B
def foo
:b
end
@DimaSamodurov
DimaSamodurov / git_rename_master.sh
Created November 22, 2019 13:05
How to rename to master branch
git checkout master2
# delete local master
git branch -D master
# rename master2 to master
git branch -m master2 master
# Push master with force option to overwrite existing remote branch.
git push --set-upstream -f origin master
class Receipt
def initialize(user:)
@user = user
end
def payments
# Imagine you get payments like Payment.where(user: @user). So payments are actually retrieved, `get`.
[
{name: 'Shoes', price: 5.2 },
{name: 'Book', price: 3.5 }
module TimeUtils
def self.wait_for(title: '', max_wait_time: 5, wait_interval: 0.1,
raise_timeout_error: false,
debug: false,
&block)
puts "Waiting for #{title}" if debug
waiting_time = 0
@DimaSamodurov
DimaSamodurov / http_logger.rb
Last active February 1, 2019 13:21
Simple logger for Ruby Net::HTTP requests.
require 'net/http'
# The simplified version of logger can be copypasted into Rails initializer.
module HttpLogger
def request(req, body = nil, &block)
start_time = Time.current
super.tap do |resp|
log_request(http: self, request: req, response: resp, start_time: start_time) rescue nil
end
end
@DimaSamodurov
DimaSamodurov / csv_export.rb
Created January 18, 2019 14:01
Quick export ActiveRecord to CSV.
CSV.open("tmp/records.csv", "wb") do |csv|
csv << ConnectRequest.attribute_names
ConnectRequest.where('created_at > ?', 2.day.ago).each do |record|
csv << record.attributes.values
end
end
@DimaSamodurov
DimaSamodurov / _ga.html.erb
Created September 13, 2018 10:06
Using gtag with Turbolinks
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
document.addEventListener('turbolinks:load', function (event) {
if (typeof gtag === 'function') {