Skip to content

Instantly share code, notes, and snippets.

@fogmoon
fogmoon / iterm2.zsh
Created October 12, 2020 18:44 — forked from wadey/iterm2.zsh
Change iTerm2 tab color when using SSH
# Usage:
# source iterm2.zsh
# iTerm2 tab color commands
# https://iterm2.com/documentation-escape-codes.html
if [[ -n "$ITERM_SESSION_ID" ]]; then
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
@fogmoon
fogmoon / nginxproxy.md
Created August 23, 2020 17:49 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@fogmoon
fogmoon / .gitignore
Created June 5, 2020 12:55 — forked from gregplaysguitar/.gitignore
Some simple Ubuntu server monitoring tools
*.pyc
conf.py
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | awk -v OFS='\t' '{"host " $2 | getline ip; print $0, ip}'
# get top requesters by user agent
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requests by URL
@fogmoon
fogmoon / test_kill.ini
Created April 21, 2020 14:38 — forked from ultrabug/test_kill.ini
uwsgi-2.0.x emperor not killing spooler processes example code and ini
[uwsgi]
plugins = python27
socket = 127.0.0.1:3090
master = true
enable-threads = true
log-syslog = uwsgi.test
disable-logging = true
@fogmoon
fogmoon / test_kill.ini
Created April 21, 2020 14:38 — forked from ultrabug/test_kill.ini
uwsgi-2.0.x emperor not killing spooler processes example code and ini
[uwsgi]
plugins = python27
socket = 127.0.0.1:3090
master = true
enable-threads = true
log-syslog = uwsgi.test
disable-logging = true
@fogmoon
fogmoon / update-geoip-databases.sh
Created February 4, 2020 14:50 — forked from theel0ja/update-geoip-databases.sh
updates GeoLite2 databases
rm -rf dist/ *.tar.gz GeoLite2-*/
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
tar -xzvf GeoLite2-City.tar.gz
tar -xzvf GeoLite2-Country.tar.gz
tar -xzvf GeoLite2-ASN.tar.gz
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change example.com (server_name) to your website url
# Change /path/to/your/root to the correct value
# Generate $prerender_ua bool value based on user agent
# indexation bots will get this as 1,
# prerender user agent will always get 0 (avoid loops)
map $http_user_agent $prerender_ua {
default 0;
@fogmoon
fogmoon / tmux-cheatsheet.markdown
Created September 10, 2019 15:48 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
--
-- This example shows how bad MySQL is when handling foreign key locks.
-- Deadlock happens when multiple transactions are inserting child records
-- pointing to the same parent and then try to update the parent record.
--
-- The solution is to always try to update the parent record first
-- but it could be hard to track the when database schema is more complex.
--
-- Based on: https://bugs.mysql.com/bug.php?id=48652
--