Skip to content

Instantly share code, notes, and snippets.

View dawidof's full-sized avatar

Dmytro Koval dawidof

View GitHub Profile
@dawidof
dawidof / optimization.rake
Created February 6, 2023 17:29 — forked from merqlove/optimization.rake
PostgreSQL optimization tasks for ActiveRecord
namespace :optimization do
desc "Provide DB vacuum for production environment"
task :vacuum => :environment do
begin
tables = ActiveRecord::Base.connection.tables
tables.each do |table|
ActiveRecord::Base.connection.execute("VACUUM FULL ANALYZE #{table};")
end
rescue Exception => exc
Rails.logger.error("Database VACUUM error: #{exc.message}")
@dawidof
dawidof / nearest_date.rb
Created June 23, 2022 07:22 — forked from codenamev/nearest_date.rb
Find the nearest Monday
# credit: http://stackoverflow.com/questions/4514988/rails-is-there-away-to-get-the-date-object-that-is-the-closest-monday-to-today
# docs: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-commercial
# Find the next Monday
Date.commercial(Date.today.year, 1+Date.today.cweek, 1)
# Find the nearest Monday
Date.commercial(Date.today.year, Date.today.cwday.modulo(4)+Date.today.cweek, 1)
# Date of writing was: 2013-12-03
@dawidof
dawidof / kill_sidekiq_job.rb
Created June 15, 2022 10:46 — forked from Chocksy/kill_sidekiq_job.rb
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# FOR BUSY JOBS
# take the process_id from the /busy page in sidekiq and kill the longest running one.
workers = Sidekiq::Workers.new
workers.each do |process_id, thread_id, work|
process = Sidekiq::Process.new('identity' => process_id)
process.stop! if process_id == 'integration.3:4:71d1d7f4ef5a'
end
# FOR SCHEDULED JOBS
# you need to know the jid to make this happen
@dawidof
dawidof / date_range_splitter.rb
Created December 21, 2021 14:52 — forked from ziaulrehman40/date_range_splitter.rb
Simple ruby date range splitter
class DateRangeSplitter
include Enumerable
def initialize(date_from, date_to, max_days, end_inclusive: true)
@date_from = date_from
@date_to = date_to
@max_days = max_days
@end_inclusive = end_inclusive
generate_split_dates
end
@dawidof
dawidof / install.md
Created September 11, 2021 08:42 — forked from floehopper/install.md
Install rtl-sdr on Raspian on Raspberry Pi
jamesmead@floehopper.local:~$ sudo dd bs=1m if=/Users/jamesmead/Downloads/2015-02-16-raspbian-wheezy.img of=/dev/disk2
pi@raspberrypi ~ $ sudo raspi-config
# Choose option 1 to "Expand Filesystem" - Ensures that all of the SD card storage is available to the OS
# Choose Finish & reboot

pi@raspberrypi ~ $ sudo apt-get update
module ChargebeeFetcher
class Subscription
attr_reader :response
delegate :has_card?, to: :customer, allow_nil: true
delegate :card_expired?, :card_will_expire_soon?, to: :card
def initialize(response)
@response = response
end
@dawidof
dawidof / docker-cleanup-resources.md
Created March 2, 2018 12:00 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@dawidof
dawidof / brew
Created November 30, 2016 17:04
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy whole content of the file gg"+yG
Файл настройки: ~/.vimrc
Можно редактировать файлы через сеть, например
:e <scp|ftp|ftps>://user@host/path/to/the/file.txt
:Ex или :e ./ - файловый менеджер
== Основы ==
hjkl перемещение в разные стороны
i режим вставки
set nocompatible
so ~/.vim/plugins.vim
syntax enable
set backspace=indent,eol,start
let mapleader = ','
set number