Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Tam Nguyen ntamvl

🏠
Working from home
Block or report user

Report or block ntamvl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ntamvl
ntamvl / tip-upgrade-ruby-to-new-version.md
Last active Dec 26, 2018
Tip upgrade Ruby to new version
View tip-upgrade-ruby-to-new-version.md

First, install latest Ruby Example:

rbenv install 2.6.0
rbenv global 2.6.0
rbenv rehash

After that I redid the following:

View [ReactJS] Detect Scrolls To Bottom.md
constructor(props) {
    super(props);
    this.state = {
        height: window.innerHeight,
        message: 'not at bottom'
    };
    this.handleScroll = this.handleScroll.bind(this);
}
@ntamvl
ntamvl / postgresql-show-size-of-all-databases.md
Last active Dec 24, 2018
PostgreSQL: Show size of all databases
View postgresql-show-size-of-all-databases.md

PostgreSQL: Show size of all databases

SELECT pg_database.datname as "database_name", pg_database_size(pg_database.datname)/1024/1024 AS size_in_mb FROM pg_database ORDER by size_in_mb DESC;
SELECT
    pg_database.datname,
    pg_size_pretty(pg_database_size(pg_database.datname)) AS size
@ntamvl
ntamvl / rabbit_publisher.rb
Last active Oct 8, 2018
RabbitMQ Ruby Example
View rabbit_publisher.rb
# an initializer
# gem install bunny
# written by: Tam Nguyen (twitter: @nguyentamvn)
require 'bunny'
require 'json'
class RabbitPublisher
def initialize(options = {})
bunny_config = {
@ntamvl
ntamvl / how_to_install_gem_idn-ruby.md
Created Sep 13, 2018
How to install gem idn-ruby
View how_to_install_gem_idn-ruby.md

How to install gem idn-ruby

Ubuntu*

$ sudo apt -y install libidn11-dev
$ gem install idn-ruby  # Rails で使用する場合はプロジェクトディレクトリ内で bundle install

macOS

@ntamvl
ntamvl / fixed_kernal_task_high_cpu_on_macos.md
Last active Mar 10, 2019
Fixed the fan running high, kernel task taking up 500% cpu (high cpu) on macOS
View fixed_kernal_task_high_cpu_on_macos.md

Fixed the fan running high, kernel task taking up 500% cpu (high cpu)

Step 1: Disable SIP

Enter recovery mode

  • Shutdown your macbook
  • Press keys: Command + R
  • Press power button
  • Release keys Command + R when see Apple logo appear
  • Open Terminal app on recovery screen, then run below command:
@ntamvl
ntamvl / rails-sql-injection-like.md
Last active Jul 17, 2018
Rails SQL Injection with LIKE
View rails-sql-injection-like.md

Rails SQL Injection with LIKE

SQL ‘LIKE’ injection is a form of denial-of-service attack where an end-user adds wildcards to a SQL query that uses the ‘LIKE’ keyword. This greatly increases the time it takes to run the query. If your Rails application allows user searching using email:

users = User.includes(:profile).where("profiles.email LIKE ?", "#{term}%“).all

A user can include percent signs in their search and vastly increase the query duration, slowing down the database.

What are the risks?

@ntamvl
ntamvl / change-wordpress-permalink-structure.md
Last active Jul 14, 2018
How to change Wordpress permalink structure
View change-wordpress-permalink-structure.md
@ntamvl
ntamvl / SOCKS-5-proxy-tunnel.md
Last active Mar 10, 2019
SOCKS 5 proxy tunnel
View SOCKS-5-proxy-tunnel.md

SOCKS 5 proxy tunnel

Open a terminal program on your computer. On Mac OS X, this is Terminal in Applications > Utilities.

Set up the tunnel with this command:

ssh -D 8123 -f -C -q -N ubuntu@example.com

Explanation of arguments

@ntamvl
ntamvl / run_react_native_application_on_ios_device_directly_from_command_line.md
Created Jul 5, 2018
Run react-native application on iOS device directly from command line
View run_react_native_application_on_ios_device_directly_from_command_line.md

Run react-native application on iOS device directly from command line

The following worked for me (tested on react native 0.38 and 0.40):

npm install -g ios-deploy
# Run on a connected device, e.g. Max's iPhone:
react-native run-ios --device "Max's iPhone"

This is the proper way to do this according to fb. If you try to run just the run-ios command, you will find that the script recommends that you npm install -g ios-deploy when it comes to the install step after building.

You can’t perform that action at this time.