Skip to content

Instantly share code, notes, and snippets.

@hieunguyentrung
hieunguyentrung / serve_files_and_folders.md
Created August 24, 2019 09:05
How To Quickly Serve Files And Folders Over HTTP

Ruby

ruby -run -ehttpd . -p8000

Node

npm install -g http-server
http-server -p 8000
@hieunguyentrung
hieunguyentrung / commands.sh
Last active August 1, 2019 15:24
Uninstall apps on MacOS
// Chrome
rm -rf ~/Library/Application\ Support/Google
rm -rf ~/Library/Caches/com.google.*
rm -rf ~/Library/Google
// Lastpass
rm -rf ~/Library/Application\ Support/com.lastpass.lastpassmacdesktop
rm -rf ~/Library/Caches/com.lastpass.lastpassmacdesktop
rm -rf ~/Library/Preferences/com.lastpass.lastpassmacdesktop.plist
rm -rf ~/Library/Containers/com.lastpass.LastPass
@hieunguyentrung
hieunguyentrung / useful_faker.rb
Created July 28, 2019 13:06
Usefuly faker commands
### Internet
# Optional argument name=nil
Faker::Internet.safe_email #=> "[email protected]"
# Optional arguments specifier=nil, separators=%w(. _)
Faker::Internet.username #=> "alexie"
# Optional arguments: min_length=8, max_length=16
Faker::Internet.password #=> "Vg5mSvY1UeRg7"
Faker::Internet.ip_v4_address #=> "24.29.18.175"
require 'benchmark'
class Fibonacci
def self.calculate(n)
return n if n <= 1
calculate(n - 1) + calculate(n - 2)
end
def self.calculate_with_memoization(n)
@calculate ||= {}

mongo

db.serverStatus().mem
db.serverStatus().tcmalloc.tcmalloc.formattedString

db.serverStatus().storageEngine
db.serverStatus().wiredTiger
# model
# enumerizeがlocaleされている。
extend Enumerize
enumerize :account_type, in: { normal: 0, easy: 1, hard: 2, test: 3 },scope: true

# controller
@types = User.account_type.options
@types.map.with_index { |type, index| type[1] = index }
@hieunguyentrung
hieunguyentrung / devise manual command.md
Created March 31, 2019 15:47
devise manual command
User.first.send_confirmation_instructions
@hieunguyentrung
hieunguyentrung / Rails ajax post form object.md
Last active March 23, 2019 08:59
Rails ajax post form object
$.ajax({
  type : "POST",
  url :  'http://localhost:3001/plugin/bulk_import/',
  dataType: 'json',
  contentType: 'application/json',
  data : JSON.stringify({"shared_items": [{"entity_id":"253","position":1}, {"entity_id":"823","position":2}]})
});
@hieunguyentrung
hieunguyentrung / ActionController::UnknownFormat is missing a template for this request format and variant.md
Created March 7, 2019 16:48
ActionController::UnknownFormat is missing a template for this request format and variant

ActionController::UnknownFormat is missing a template for this request format and variant

Add format: :js

put :update, params: { cart: { duration: 30 } }, format: :js

Just another way of doing it ;-)

  1. install pm2 in global

npm i -g pm2

  1. start command

pm2 start npm --name "your-app-alias" -- start