Skip to content

Instantly share code, notes, and snippets.

@khanhtran3005
khanhtran3005 / php - nodejs
Last active Sep 14, 2021
Share session between PHP and NodeJS
View php - 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 Jul 20, 2021
Some useful configurations
View sublime_setup.md

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 Jul 16, 2021
Install and configure SchemaSpy to generate Postgres schema
View install-schema-spy.md
@khanhtran3005
khanhtran3005 / _sqlite3-error.md
Created Feb 4, 2020
ModuleNotFoundError: No module named '_sqlite3'
View _sqlite3-error.md

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

@khanhtran3005
khanhtran3005 / delete-branches.md
Created Nov 20, 2019
Delete remote branches from local
View delete-branches.md

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

@khanhtran3005
khanhtran3005 / pt-kill.md
Last active Jun 28, 2019
pt-kill example
View pt-kill.md

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 Sep 15, 2018
Learning Python's notes
View python-journey.md

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 Jun 26, 2018
Quote the right way
View quote.md

Proper Quotes

glyph named entity numeric entity escaped unicode
“ “ \201C
” ” \201D
‘ ‘ \2018
’ ’ \2019
@khanhtran3005
khanhtran3005 / unix-commands.md
Last active Jun 26, 2018
Some useful Unix commands for SysAd
View unix-commands.md
  • 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
Manage Linux users and groups
View users-groups.md
  • 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)