Skip to content

Instantly share code, notes, and snippets.

Avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@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
@leemour
leemour / .rubocop.yml
Last active Dec 3, 2018
Rubocop config
View .rubocop.yml
# inherit_from: .rubocop_todo.yml
AllCops:
# Default formatter will be used if no `-f/--format` option is given.
DefaultFormatter: fuubar
# Cop names are displayed in offense messages by default. Change behavior
# by overriding DisplayCopNames, or by giving the `--no-display-cop-names`
# option.
DisplayCopNames: true
# Style guide URLs are not displayed in offense messages by default. Change
@leemour
leemour / changelog.rake
Last active Nov 28, 2018 — forked from cdesch/rake task
Ruby git CHANGELOG generator
View changelog.rake
namespace :changelog do
# simple rake task to output a changelog between two commits, tags ...
# output is formatted simply, commits are grouped under each author name
#
desc "generate changelog with nice clean output"
task :generate, :since_c, :until_c do |t, args|
since_c = args[:since_c] || `git tag | head -1`.chomp
until_c = args[:until_c] || `git rev-parse --short HEAD`
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' --after=#{since_c} --before=#{until_c}`