Skip to content

Instantly share code, notes, and snippets.

@mshRoR
mshRoR / filterable.rb
Created January 11, 2024 07:28 — forked from justinweiss/filterable.rb
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@mshRoR
mshRoR / upgrade-postgresql-with-docker-compose.txt
Last active January 2, 2024 07:39
upgrade-postgresql-with-docker-compose
# spin up our new (empty) database
docker compose up -d db_postgres_151
# login to postgres
$ psql -U postgres
$ CREATE DATABASE database_name
# dump our existing database
docker compose exec -it db_postgres_146 /bin/bash -c 'pg_dumpall -U $POSTGRES_USER > /backup/20230127.sql'
# Check server process is using jemalloc
# ref. [Japanese] https://tech.studyplus.co.jp/entry/2019/09/09/094140
class AppController < ActionController::Base
def show
r = `strings /proc/#{Process.pid}/maps | grep jemalloc`
render plain: "<h1>#{ENV['LD_PRELOAD'].presence || 'empty'}</h1><pre>#{r}</pre>"
end
end
@mshRoR
mshRoR / ubuntu-command.txt
Last active April 27, 2020 11:08
Important ubuntu comamnds
# Refresh ubuntu keys server
$ sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com
# Group permission change
$ sudo chgrp -R root esdata
# Add current login User ID to .bashrc or .zshrc file
$ echo "export UID=$UID" >> ~/.bashrc
or
$ echo "export UID=$UID" >> ~/.zshrc
@mshRoR
mshRoR / docker-permission.txt
Created April 8, 2020 08:04
How to fix docker: Got permission denied issue
If you want to run docker as non-root user then you need to add it to the docker group.
1. Create the docker group if it does not exist
$ sudo groupadd docker
2. Add your user to the docker group.
$ sudo usermod -aG docker $USER
3. Run the following command or Logout and login again and run (that doesn't work you may need to reboot your machine first)
$ newgrp docker
4. Check if docker can be run without root
$ docker run hello-world
@mshRoR
mshRoR / important-git-repo-link.txt
Last active January 18, 2020 07:54
important-git-repo-link
MiniKube Setup:
1. https://kubernetes.io/docs/tasks/tools/install-minikube/
2. https://kubernetes.io/docs/tasks/tools/install-kubectl/
KOPS Setup for production:
http://github.com/kubernetes/kops
@mshRoR
mshRoR / code-quality.md
Last active May 8, 2019 05:44
writing code quality behavior key notes.

Then the code you write should have the following qualities. Code should be

  • Transparent The consequences of change should be obvious in the code that is changing and in distant code that relies upon it
  • Reasonable The cost of any change should be proportional to the benefits the change achieves
  • Usable Existing code should be usable in new and unexpected contexts
  • Exemplary The code itself should encourage those who change it to perpetuate these qualities

Code that is Transparent, Reasonable, Usable, and Exemplary (TRUE) not only meets today’s needs but can also be changed to meet the needs of the future. The first step in creating code that is TRUE is to ensure that each class has a single, well-defined responsibility.

@mshRoR
mshRoR / django2.1-python3.7-pipenv-installing-command.txt
Last active May 13, 2020 07:38
python 3.7 | pip3 | pipenv | django 2.1 installing commands in ubuntu 16.04
## python 3.7 install
-> sudo apt update
-> sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
-> sudo apt install software-properties-common
-> sudo add-apt-repository ppa:deadsnakes/ppa
-> sudo apt update
-> sudo apt install python3.7
-> python3.7 --version
## pip3 install