Skip to content

Instantly share code, notes, and snippets.

Avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@leemour
leemour / basic_query_stats.sql
Last active Jan 12, 2022
PostgreSQL pg_stat_statements detailed output for query performance analysis and optimization
View basic_query_stats.sql
SELECT
t.tablename,
foo.indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
pg_relation_size(quote_ident(indexrelname)) as index_size_bytes,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
@leemour
leemour / sidekiq_monitoring
Created Aug 10, 2021 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
View sidekiq_monitoring
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@leemour
leemour / clean_code.md
Created Mar 29, 2021 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin
View clean_code.md

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@leemour
leemour / rubocop.sh
Created Aug 2, 2019
Rubocop run on only changed files
View rubocop.sh
git diff --staged --name-only | xargs rubocop -a
@leemour
leemour / workspace_ubuntu_install.md
Last active Oct 16, 2020
Install and Uninstall (remove) Amazon Workspaces on Linux (Ubuntu 18.04 LTS 64-bit) Wine (Wine64)
View workspace_ubuntu_install.md
sudo apt-get --purge remove wine
sudo apt-get purge wine* ; sudo dpkg --purge wine*
sudo apt-get purge wine64 ; sudo dpkg --purge wine64
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get autoremove
cd $HOME
rm -r .wine
@leemour
leemour / app.conf
Last active Jan 16, 2019
Monit with Puma, Sidekiq, Nginx, PostgreSQL, Disk space and Memory limits, using rbenv and nvm
View app.conf
# /etc/monit/conf.d/app
set daemon 30 with start delay 60
set log "/srv/www/app/shared/log/monit.log" # syslog facility log_daemon
set httpd port 2812
allow localhost
allow login:password
# with ssl {
# pemfile: /etc/ssl/certs/app_com.pem
# }
@leemour
leemour / monit-and-gmail
Last active Jan 16, 2019 — forked from jcdarwin/monit-and-gmail
How to allow monit to use gmail as a smtp relay to send out alert emails
View monit-and-gmail
# visit https://accounts.google.com/DisplayUnlockCaptcha and click to allow access
# edit /etc/monit/monitrc to include the following
set mailserver smtp.gmail.com port 587
username "whoever@gmail.com" password "whatever"
using tls
with timeout 30 seconds
# run the following to validate access
@leemour
leemour / spree_carrierwave.rb
Created Jan 15, 2019
Spree Carrierwave replacement
View spree_carrierwave.rb
# app/models/spree/image.rb
module Spree
class Image < Asset
mount_uploader :attachment, Spree::ImageUploader,
mount_on: :attachment_file_name
validates :attachment, presence: true
end
end
@leemour
leemour / format_ruby_hash.rb
Last active Jan 11, 2019
Format Ruby hash with left indent and awesome print
View format_ruby_hash.rb
# add `gem 'awesome_print` to Gemfile
rails c
# cl = Scryfaller::Client.new
# hash = cl.cards.search(q: "Aberrant Researcher // Perfected Form").body[:data].first
ap hash, ruby19_syntax: true, index: false, indent: 2
# Copy and paste output into https://www.cleancss.com/ruby-beautify/
@leemour
leemour / listen_ports.sh
Created Dec 14, 2018
Ubuntu network stat check ports listen
View listen_ports.sh
# sudo apt install net-tools
sudo netstat -ntlp | grep LISTEN