Skip to content

Instantly share code, notes, and snippets.

View encoreshao's full-sized avatar

Encore Shao encoreshao

View GitHub Profile
@encoreshao
encoreshao / cp-config-files
Created February 28, 2020 13:30
[Ruby] - Quickly copy all config files for the project from the .example file
#!/usr/bin/env ruby
#
# If you are the first clone of this Project
# Please run `ruby cp_config_files` at your command line, Add all config files
# Finally, modify the database.yml file parameters (username & password)
require "fileutils"
def cp_files(yml_files)
files = Dir["config/#{yml_files}"]
@encoreshao
encoreshao / sync-files
Created February 28, 2020 13:25
[Ruby] - Download the config files from the server and upload it to another server
#!/usr/bin/env ruby
#
# Download the configuration file from the server and upload it to another server
#
# How to run it
#
# ruby sync-files.rb source_server target_server config_folder
require 'fileutils'
@encoreshao
encoreshao / tmux-cheatsheet.markdown
Created July 5, 2019 07:31 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@encoreshao
encoreshao / delete_queue_from_sidekiq.rb
Created June 4, 2019 11:25
删除sidekiq中一个Queue
require 'sidekiq/api'
stats = Sidekiq::Stats.new
stats.queues
=> { "mailers"=>80 }
queue = Sidekiq::Queue.new('mailers')
queue.count
queue.clear
@encoreshao
encoreshao / gc.bash
Last active May 22, 2019 01:42
rbenv - warning: RUBY_HEAP_MIN_SLOTS is obsolete. Use RUBY_GC_HEAP_INIT_SLOTS instead.
Warning on ruby 2.6.3 after you upgrade rbenv
/Users/encore/.rbenv/versions/2.6.1/bin/ruby: warning: RUBY_FREE_MIN is obsolete. Use RUBY_GC_HEAP_FREE_SLOTS instead.
/Users/encore/.rbenv/versions/2.6.1/bin/ruby: warning: RUBY_HEAP_MIN_SLOTS is obsolete. Use RUBY_GC_HEAP_INIT_SLOTS instead.
/Users/encore/.rbenv/versions/2.6.1/bin/ruby: warning: RUBY_FREE_MIN is obsolete. Use RUBY_GC_HEAP_FREE_SLOTS instead.
/Users/encore/.rbenv/versions/2.6.1/bin/ruby: warning: RUBY_HEAP_MIN_SLOTS is obsolete. Use RUBY_GC_HEAP_INIT_SLOTS instead.
=> Booting WEBrick
=> Rails 5.2.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[2019-05-21 20:03:34] INFO WEBrick 1.4.2
@encoreshao
encoreshao / read-access.sql
Created March 13, 2019 03:32 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@encoreshao
encoreshao / postgres_queries_and_commands.sql
Created August 31, 2018 05:49 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@encoreshao
encoreshao / rubocop_pre_commit_hook
Created July 22, 2018 11:47 — forked from mpeteuil/rubocop_pre_commit_hook
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@encoreshao
encoreshao / .vimrc
Created May 12, 2018 15:36 — forked from millermedeiros/.vimrc
My VIM settings (.vimrc)
" =============================================================================
" Miller Medeiros .vimrc file
" -----------------------------------------------------------------------------
" heavily inspired by: @factorylabs, @scrooloose, @nvie, @gf3, @bit-theory.
" =============================================================================
" -----------------------------------------------------------------------------
" BEHAVIOR
" -----------------------------------------------------------------------------
@encoreshao
encoreshao / blog.conf
Created April 7, 2018 10:43
Create a puma conf for your blog
upstream puma {
server unix:///var/www/production/icmoc.com/shared/tmp/sockets/blog-puma.sock;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /var/www/production/icmoc.com/current/public;
access_log /var/www/production/icmoc.com/current/log/nginx.access.log;