Skip to content

Instantly share code, notes, and snippets.

View leemour's full-sized avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@leemour
leemour / rails_new.sh
Last active January 2, 2024 21:26
Rails new template generation
rails _5.2.8_ new dummy \
--skip-action-text --skip-active-storage --skip-action-cable --skip-active-job --skip-active-record --skip-git \
--skip-sprockets --database=mysql --skip-javascript --skip-coffee --skip-turbolinks --skip-test --skip-system-test --no-skip-active-record
@leemour
leemour / basic_query_stats.sql
Last active May 1, 2024 14:04
PostgreSQL pg_stat_statements detailed output for query performance analysis and optimization
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 August 10, 2021 09:33 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@leemour
leemour / clean_code.md
Created March 29, 2021 18:19 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

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 August 2, 2019 07:43
Rubocop run on only changed files
git diff --staged --name-only | xargs rubocop -a
@leemour
leemour / workspace_ubuntu_install.md
Last active November 20, 2023 16:55
Install and Uninstall (remove) Amazon Workspaces on Linux (Ubuntu 18.04 LTS 64-bit) Wine (Wine64)
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 January 16, 2019 15:12
Monit with Puma, Sidekiq, Nginx, PostgreSQL, Disk space and Memory limits, using rbenv and nvm
# /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 January 16, 2019 12:47 — forked from jcdarwin/monit-and-gmail
How to allow monit to use gmail as a smtp relay to send out alert emails
# 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 January 15, 2019 18:48
Spree Carrierwave replacement
# 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 January 11, 2019 14:22
Format Ruby hash with left indent and awesome print
# 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/