Skip to content

Instantly share code, notes, and snippets.

View letam's full-sized avatar
🐢
vibing

Tam Le letam

🐢
vibing
View GitHub Profile
@letam
letam / install-git.plugin.zsh
Created December 14, 2021 17:46
Install Git Plugin for Zsh
#!/usr/bin/env bash
# Install git.plugin.zsh from Oh My Zsh framework (https://github.com/ohmyzsh/ohmyzsh)
mkdir -p ~/.config/zsh
cd ~/.config/zsh
curl -O https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/plugins/git/git.plugin.zsh
if ! grep -q 'source ~/.config/zsh/git.plugin.zsh' ~/.zshrc; then
echo -e '\n# Load git plugin from Oh My Zsh framework (https://github.com/ohmyzsh/ohmyzsh)' >> ~/.zshrc
@letam
letam / print-twin-filenames.py
Last active May 12, 2021 18:23
Print out cases of matching filenames but with different extension
#!/usr/bin/env python
# Get all js and jsx files in project and print out the situations
# in which there is a file named *.js beside an identically-named *.jsx file
import subprocess
# Get sorted list of paths of all {js,jsx} files in project, excluding node_modules dir
command = "find -L . \
@letam
letam / nginx.conf
Created May 2, 2021 23:49
nginx.conf for node/vite dev server with hot module replacement HMR
location / {
index index.html index.htm;
#try_files $uri $uri/ =404;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:3000;
@letam
letam / nginx.conf
Created May 2, 2021 22:39 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@letam
letam / escape-regex-replacement-string.sh
Last active June 12, 2020 13:55
escape regex replacement string
#!/usr/bin/env bash
# Return a string that's escaped and ready to be used as
# the replacement string in a basic regular expression.
# Reference: https://unix.stackexchange.com/questions/32907/what-characters-do-i-need-to-escape-when-using-sed-in-a-sh-script/33005#33005
escape_regex_replacement_string() {
# Reference: https://github.com/koalaman/shellcheck/wiki/SC2001
string=$1
if [[ $string =~ \\ ]]; then
@letam
letam / php-pools.md
Created June 10, 2020 02:00 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@letam
letam / zen-timer.sh
Created May 14, 2020 02:33
Break Timer using Zenity (requires Linux and GTK)
#!/usr/bin/env bash
# Break Timer using Zenity (requires Linux and GTK)
[[ $# != 1 ]] && >&2 echo "Usage: $0 MINUTES" && exit 1
minutes=$1
pyp() { python -c "print($1)"; }
if grep -q '\.' <<<$minutes; then
@letam
letam / .ctags
Created May 7, 2020 18:16 — forked from romainl/.ctags
My ctags config
--langdef=less
--langmap=less:.less
--regex-less=/^[ \t&]*#([A-Za-z0-9_-]+)/\1/i,id,ids/
--regex-less=/^[ \t&]*\.([A-Za-z0-9_-]+)/\1/c,class,classes/
--regex-less=/^[ \t]*(([A-Za-z0-9_-]+[ \t\n,]+)+)\{/\1/t,tag,tags/
--regex-less=/^[ \t]*@media\s+([A-Za-z0-9_-]+)/\1/m,media,medias/
--regex-less=/^[ \t]*(@[A-Za-z0-9_-]+):/\1/v,variable,variables/
--regex-less=/\/\/[ \t]*(FIXME|TODO)[ \t]*\:*(.*)/\1/T,Tag,Tags/
--langdef=scss
@letam
letam / dump-table-data.sh
Created May 5, 2020 22:09
Dump data from PostgreSQL table
#!/usr/bin/env bash
db_user=postgres
db_name=postgres
db_table=users_user
pg_dump -U $db_user $db_name --column-inserts -a -t $db_table
@letam
letam / install-neovim-ubuntu.sh
Created March 22, 2020 18:31
Install Neovim on Ubuntu
#!/usr/bin/env bash
# Setup neovim on Ubuntu
# Install neovim
sudo snap install nvim --beta --classic
if ! echo "$PATH" | grep -q "/snap/bin"; then
file=~/.profile
cp -p $file $file.bak.$(date -u +%Y-%m-%d-%H%M%S)