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
@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 / download
Created April 27, 2016 22:36 — forked from guzart/download
bash: Download and Compress Rails API
#!/bin/bash
rm -rf api.rubyonrails.org/
wget -r -k -p http://api.rubyonrails.org/
rm rails_api.rar
rar a -r rails_api.rar api.rubyonrails.org/
@dawidof
dawidof / osx-10.11-setup.md
Created March 17, 2016 23:12 — forked from kevinelliott/osx-10.11-setup.md
Mac OS X 10.11 El Capitan Setup

Mac OS X 10.11 El Capitan

Custom recipe to get OS X 10.11 El Capitan running from scratch, setup applications and developer environment. This is very similar (and currently mostly the same) as my 10.10 Yosemite setup recipe (as found on this gist https://gist.github.com/kevinelliott/0726211d17020a6abc1f). Note that I expect this to change significantly as I install El Capitan several times.

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.