Skip to content

Instantly share code, notes, and snippets.

Avatar

Terry Wang terrywang

View GitHub Profile
@terrywang
terrywang / .bashrc
Last active Sep 25, 2022
Bash 4.2.x dot files for Linux and OS X, extracted from Ubuntu which by default does NOT use $HOME/.bash_profile for interactive login shells.
View .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
# [ -z "$PS1" ] && return
case $- in
*i*) ;;
*) return;;
esac
@terrywang
terrywang / nginx.conf
Last active Jul 28, 2022
Nginx config file template for self-hosted personal site on Fedora, Ubuntu, Debian and Arch Linux
View nginx.conf
# User and group used by worker processes
# ubuntu
# user www-data;
# fedora
user nginx;
# Ideally # of worker processes = # of CPUs or cores
# Set to auto to autodetect
# max_clients = worker_processes * worker_connections
worker_processes auto;
@terrywang
terrywang / nginx.conf
Created Jul 28, 2022
Nginx config for log.terry.im
View nginx.conf
server {
listen 80;
# listen [::]:80 default ipv6only=on;
server_name log.terry.im;
# redirect all HTTP requests to HTTPS with a 301 Moved Permanently response
location / {
return 301 https://$host$request_uri;
}
}
@terrywang
terrywang / nginx.conf
Created Jul 28, 2022
Nginx Configuration for Pi-hole
View nginx.conf
server {
listen 80 default_server;
# listen [::]:80 default_server;
root /var/www/html;
server_name _;
autoindex off;
index pihole/index.php index.php index.html index.htm;
error_page 404 pihole/index.php;
@terrywang
terrywang / ssh_config
Created Mar 6, 2022
Using AWS SSM for SSH Dynamic Forwarding so as to access services in private subnet
View ssh_config
Host ssm-tatooine
ProxyCommand sh -c "aws ssm start-session --target <instance id> --region <region> --document-name AWS-StartPortForwardingSession --parameters '{\"portNumber\":[\"22\"],\"localPortNumber\":[\"22222\"]}'"
Host dynamic-forwarding
Hostname localhost
user terry
IdentityFile ~/.ssh/r2d2_ed25519
Port 22222
UserKnownHostsFile /dev/null
DynamicForward 1080
@terrywang
terrywang / config
Last active Feb 1, 2022
~/.ssh/config behind firewall (ssh via HTTP proxy) and faster session creation by reusing already established connection
View config
# User ssh configuration file ~/.ssh/config
# Gist https://gist.github.com/terrywang/3997931
# man ssh_config for more information
# Inspired by the blog post below to fight the NSA
# https://stribika.github.io/2015/01/04/secure-secure-shell.html
# Outside of the firewall, with HTTPS proxy
# Package connect-proxy is required.
# Amazon EC2
@terrywang
terrywang / .tmux.conf
Last active Jan 26, 2022
~/.tmux.conf
View .tmux.conf
# /home/terrywang/.tmux.conf
# Based on tmux book written by Brian P. Hogan
# c-a o to switch to another panel
# c-d to close shell
# c-a ! to close panel
# c-a w to list windows
# c-a " split pane horizontally
# c-a % split pane vertically
# Setting the prefix from C-b to C-a
@terrywang
terrywang / vimcasts.sh
Last active May 19, 2021
Vimcasts screencasts download bash one-liner - please support Drew Neil if possible e.g. buy Practical Vim ;-D
View vimcasts.sh
for (( i=1; i<=76; i++ )); do file=$(curl -s http://media.vimcasts.org/videos/$i/ | grep m4v | awk '{ print $5 }' | cut -d'>' -f2 | cut -d'<' -f1); url=http://media.vimcasts.org/videos/$i/$file; echo $url; wget -c -S -O "$c-$file" "$url"; done
@terrywang
terrywang / gist:74d1617600dfc7c2fb4c6365c60b09db
Created Apr 10, 2021
Bash history HISTFILE deduplication while preserving order
View gist:74d1617600dfc7c2fb4c6365c60b09db
# backup HISTFILE
cp ~/.bash_history{,.bak}
# deduplicate
nl ~/.bash_history.bak | sort -k2,2 -k1,1nr | uniq -f1 | sort -k1,1n | cut -f2 > ~/.bash_history
View gist:50230273cf93d24eae363ab36584150b
BEGIN MESSAGE.
kb9gwzCN54guTDZ nRzTyPdnlMNA3qX NsJya3Xx0fUvqrX Vd90YV82h6Y7GJF
sumxMqfA9HmjTij JlQ2T8y8HjaTCKq 6Xr2MZHgg6Sdxkm kC9iG2QUd2xL5A8
Xos3qZmbvQqWVLB WyGeiAPgJWM8t0K LkygSwAlkXDHrTJ QbGfAXkSywRXkTZ
CNpuUkfztYMa2Jo hZIjTbpdxMb4cIj 3E2iO29HFxl.
END MESSAGE.