Skip to content

Instantly share code, notes, and snippets.

View khanhtran3005's full-sized avatar

Khanh Tran khanhtran3005

  • Inspectorio
  • Vietnam
View GitHub Profile
@khanhtran3005
khanhtran3005 / php - nodejs
Last active September 14, 2021 04:14
Share session between PHP and NodeJS
http://stackoverflow.com/questions/24296212/php-nodejs-and-sessions#24303059
You can use memcached as your session storage handler in PHP. Memcached is a simple key value store that can be accessed via TCP; there is a memcached module available for Node.js.
PHP stores the session in memcached by using the session id as the key. The session data (value) stored in memcached is a serialized PHP object, with a slight twist. You can read more about this unusual serialization at the SO question "Parse PHP Session in Javascript". Luckily though, there is already an NPM module out there: php-unserialize.
Now for the How-To.
Assumptions
@khanhtran3005
khanhtran3005 / sublime_setup.md
Last active July 20, 2021 13:43
Some useful configurations

Preferences > Key Bindings - User

[
  { "keys": ["ctrl+t", "ctrl+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"}},
  { "keys": ["ctrl+alt+p"], "command": "prompt_select_workspace" } 
]

> Preferences > Settings - User

@khanhtran3005
khanhtran3005 / install-schema-spy.md
Last active July 16, 2021 10:14
Install and configure SchemaSpy to generate Postgres schema
@khanhtran3005
khanhtran3005 / _sqlite3-error.md
Created February 4, 2020 04:51
ModuleNotFoundError: No module named '_sqlite3'

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7.0

@khanhtran3005
khanhtran3005 / delete-branches.md
Created November 20, 2019 03:57
Delete remote branches from local

git remote show origin | grep {pattern} | awk '{print $1}' | xargs git push origin -d

@khanhtran3005
khanhtran3005 / pt-kill.md
Last active June 28, 2019 08:04
pt-kill example

pt-kill user must have SUPER PROCESS permission.

The following command intends to kill queries which have execute time greater than 30s and save terminated queries to database.

pt-kill --host=localhost --user=pt_kill_user --password=pt_kill_pass \
--busy-time=30 --interval=5s \
--log-dsn=h=localhost,D=pt_kill,t=kill_log,P=3306,u=root,p=root \
--kill --daemonize --ignore-user=backup
@khanhtran3005
khanhtran3005 / python-journey.md
Last active September 15, 2018 07:59
Learning Python's notes

String Formatting

# Basic usage
print('We are the {} who say "{}!"'.format('knights', 'Ni'))

# Using index of the passed object
print('Low limit: {0}, high limit: {1}'.format(10, 200))

# using the name of the argument.
@khanhtran3005
khanhtran3005 / quote.md
Last active June 26, 2018 01:53
Quote the right way

Proper Quotes

glyph named entity numeric entity escaped unicode
“ “ \201C
” ” \201D
‘ ‘ \2018
’ ’ \2019
@khanhtran3005
khanhtran3005 / unix-commands.md
Last active June 26, 2018 01:48
Some useful Unix commands for SysAd
  • Disable a service which starts automatically sudo update-rc.d -f nginx disable

  • Space investigation:

    • Find top biggest directories under particular partition: du -a /home/xxx | sort -n -r | head -n 5

    • To display the above result in human readable format: du -Sh /home/xxx | sort -rh | head -5

@khanhtran3005
khanhtran3005 / users-groups.md
Last active May 30, 2018 04:00
Manage Linux users and groups
  • User(s) in a group: getent group groupname
  • To add user to a group: sudo gpasswd -a username sudo | sudo usermod -aG sudo username
  • To add a new user: sudo adduser new_username
  • To remove/delete a user: sudo userdel username | Then remove user's folder if needed: sudo rm -r /home/username or sudo deluser --remove-home username
  • To remove user from a group: gpasswd -d username group
  • To modify the username: usermod -l new_username old_username
  • To change the password for a user: sudo passwd username
  • To change the shell for a user: sudo chsh username
  • To allow user to connect via SSH: add username to the line AllowUsers in /etc/ssh/sshd_config
  • To grant user to root: visudo and add username (same with root)