Skip to content

Instantly share code, notes, and snippets.

View moofkit's full-sized avatar
💭
(/¯◡ ‿ ◡)/¯ ~ ┻━┻

Dmitriy Ivliev moofkit

💭
(/¯◡ ‿ ◡)/¯ ~ ┻━┻
View GitHub Profile
@moofkit
moofkit / delete_line_from_file.rb
Created March 2, 2023 14:21
Delete matched line from file
#!/usr/bin/env ruby
# frozen_string_literal: true
files = Dir.glob("app/jobs/**/*.rb")
puts "Found #{files.count} files"
files.each do |file|
content = File.read(file).split("\n")
content.each_with_index do |line, index|
if match = line.match(/Worker/)
@moofkit
moofkit / rename.bash
Created February 9, 2023 15:19
Rename files with patterns in bash
$find . -depth -name "*old.txt" -exec sh -c 'f="{}"; mv -- "$f" "${f%old.txt}new.csv"' \;
@moofkit
moofkit / rename.rb
Created February 3, 2023 16:33
Rename Worker Class to Job
#!/usr/bin/env ruby
# frozen_string_literal: true
# https://juanitofatas.com/series/sidekiq/rename
files = Dir.glob("app/workers/**/*.rb")
puts "Found #{files.count} files"
files.each do |file|
content = File.read(file)
if match = content.match(/class (\S+)Worker/)
@moofkit
moofkit / main.rs
Created May 15, 2022 09:59
Rust mutex deadlock example
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
fn main() {
let counter = Arc::new(Mutex::new(0));
let counter2 = Arc::new(Mutex::new(0));
let mut handles = vec![];
for _ in 0..10 {
@moofkit
moofkit / errors.en.yml
Created June 8, 2021 19:29
Error message path for rule with nested params reproducing bug
en:
dry_validation:
errors:
rules:
data:
attributes:
phone_number:
invalid_format: 'is of invalid format'
@moofkit
moofkit / Makefile
Created January 12, 2021 16:26
sentry-havy-serialize-reproduce
start:
rackup config.ru -p 9292
test:
time curl 'http://localhost:9292/exception'

After a bit of digging, I believe the issue was that the 9.6 install setup a cluster for the new instance which was interrupting the pg_upgrade. I ended up getting it working by dropping the new cluster and upgrading the 9.3 cluster using pg_upgradecluster from the following gist: https://gist.github.com/delameko/bd3aa2a54a15c50c723f0eef8f583a44

Install packages

sudo apt-get install postgresql-9.6 postgresql-server-dev-9.6 postgresql-contrib-9.6 -y

List clusters. Should show existing (9.3) and newly installed (9.6)

pg_lsclusters

@moofkit
moofkit / gist:2146f18953be9053ae372c063d28912b
Created September 30, 2016 12:21
lock monitor. postgresql
CREATE VIEW lock_monitor AS
SELECT COALESCE(((blockingl.relation)::regclass)::text, blockingl.locktype) AS locked_item,
(now() - blockeda.query_start) AS waiting_duration,
blockeda.pid AS blocked_pid,
blockeda.query AS blocked_query,
blockedl.mode AS blocked_mode,
blockinga.pid AS blocking_pid,
blockinga.query AS blocking_query,
blockingl.mode AS blocking_mode
FROM (((pg_locks blockedl
module ApplicationType
extend ActiveSupport::Concern
module ClassMethods
def model_name
superclass.model_name
end
def name
superclass.name
@moofkit
moofkit / time_vs_datatime.md
Created October 15, 2015 05:09 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000