Skip to content

Instantly share code, notes, and snippets.

View rogerluo410's full-sized avatar
🏠
Working at home

Roger Luo rogerluo410

🏠
Working at home
View GitHub Profile
@rogerluo410
rogerluo410 / rails_binding_pry_on_docker.md
Created October 13, 2022 05:33 — forked from aloucas/rails_binding_pry_on_docker.md
Rails binding.pry usage with docker
  1. Initially install your pry-rails to group development on your apps Gemfile
group :development do
  # ..
  gem 'pry-rails'
  # ..
end
@rogerluo410
rogerluo410 / gist:457bc9122a4c779e7703ec909d71c3d1
Created May 17, 2022 02:13 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@rogerluo410
rogerluo410 / vue.md
Created November 21, 2018 13:22 — forked from DawidMyslak/vue.md
Vue.js and Vuex - best practices for managing your state

Vue.js and Vuex - best practices for managing your state

Modyfing state object

Example

If you have to extend an existing object with additional property, always prefer Vue.set() over Object.assing() (or spread operator).

Example below explains implications for different implementations.

@rogerluo410
rogerluo410 / docker-cleanup-resources.md
Created November 13, 2018 08:30 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@rogerluo410
rogerluo410 / gist:ea3f7f36b5702139354028b66ad57d88
Last active March 29, 2021 06:07 — forked from dshaw/gist:378192
JS - window & document
// everyone's new favorite closure pattern:
(function(window,document,undefined){ ... })(this,this.document);
// when minified:
(function(w,d,u){ ... })(this,this.document);
// which means all uses of window/document/undefined inside the closure
// will be single-lettered, so big gains in minification.
// it also will speed up scope chain traversal a tiny tiny little bit.
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@rogerluo410
rogerluo410 / ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: could not identify an equality operator for type json
Created May 2, 2018 12:51
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: could not identify an equality operator for type json
Explanation:
```
The reason behind this, is that in PostgreSQL (up to 9.3) there is no equality operator defined for json (i.e. val1::json = val2::json will always throw this exception) -- in 9.4 there will be one for the jsonb type.
One workaround is, you can cast your json field to text. But that won't cover all json equalitions. f.ex. {"a":1,"b":2} should be equal to {"b":2,"a":1}, but won't be equal if casted to text.
```
Possible ways to fix:
1) Migrate to Postgresql 9.4 and use .jsonb type
@rogerluo410
rogerluo410 / db.rake
Created April 17, 2018 08:11 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@rogerluo410
rogerluo410 / 0_reuse_code.js
Created August 1, 2016 05:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console