Skip to content

Instantly share code, notes, and snippets.

## Clone a running OS from SD card to USD SSD, Raspberry 4B 8G
### Main guide
https://medium.com/xster-tech/move-your-existing-raspberry-pi-4-ubuntu-install-from-sd-card-to-usb-ssd-52e99723f07b
### References:
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-boot-modes
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-boot-flow
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-boot-eeprom
@huynhbaoan
huynhbaoan / Bash shell snippet for daily use
Last active April 30, 2023 08:20
Bash shell snippet for daily use
# Generate du command to check disk
# Ignore all the mount points nfs4. Modify the "df -t nfs4" as you want
# Run with lowest CPU priority and lowest diskio priority
# extract the content from the last column and store it in an array
IFS=$'\n' read -d '' -ra MOUNT_POINTS <<< "$(df -h -t nfs4 | awk '{print $NF}')"
# construct the new du command with the excluded mount points
DU_COMMAND="nice -n 19 ionice -c 3 du -shxc /* --exclude=/proc"
for mount_point in "${MOUNT_POINTS[@]}"; do
Different from bash, PowerShell is object-orriented. Understanding objects are necessary to utilize PowerShell
Get-NetIPAddress -AddressFamily IPV4 -AddressState Preferred -IncludeAllCompartments | Get-Member
TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/StandardCimv2/MSFT_NetIPAddress
Name MemberType Definition
---- ---------- ----------
ifIndex AliasProperty ifIndex = InterfaceIndex
@huynhbaoan
huynhbaoan / lambda_function_compress_s3.py
Created August 31, 2020 02:53 — forked from psa-jforestier/lambda_function.py
AWS Lambda function to gzip compress file when upload to S3 (will replace original file with gz version)
###
### This gist contains 2 files : settings.json and lambda_function.py
###
### settings.json
{
"extensions" : ["*.hdr", "*.glb", "*.wasm"]
}
### lambda_function.py
@huynhbaoan
huynhbaoan / Bash shell notes
Last active July 29, 2020 09:18
Some common bash shell syntax for daily use
# Stack size check for HTTPD thread
ps aux | grep "[h]ttpd" | awk '{print $2}' > /tmp/httpd.list
while IFS= read -r line
do
echo "$line"
cat /proc/$line/status
ls /proc/$line/task | xargs -I % bash -c "cat /proc/$line/task/%/status" | grep VmStk
done < /tmp/httpd.list
rm -f /tmp/httpd.list
### Since on all thread of process share everything except stack, we only check VmStk here
# Create user-defined overlay network
Prerequisites:
Firewall rules for Docker daemons using overlay networks
You need the following ports open to traffic to and from each Docker host participating on an overlay network:
"TCP port 2377 for cluster management communications
TCP and UDP port 7946 for communication among nodes
UDP port 4789 for overlay network traffic"
Before you can create an overlay network, you need to either initialize your Docker daemon as a swarm manager using: docker swarm init
or join it to an existing swarm using: docker swarm join
Either of these creates the default ingress overlay network which is used by swarm services by default. You need to do this even if you never plan to use swarm services. Afterward, you can create additional user-defined overlay networks.
@huynhbaoan
huynhbaoan / nginx_assets.md
Created February 13, 2019 10:20 — forked from vishaltelangre/nginx_assets.md
Serving Static Assets via Nginx

Concept

  • People talk about two servers: a web server (e.g. Nginx, Apache, etc.) and a app server (e.g. Language specific servers like Unicorn, Node.js, Tomcat, Http-Kit, etc.). There are exceptions where app servers not required at all (as web server itself provides preprocessors for handling), but let's not talk about now.
  • Web servers are really fast and supports lot of standard and commonly used MIME-type requests. Concept of serving a file is -- forming and sending a response of bytes of data and labeling it with requested MIME-type by a client (e.g. web browser).
  • Every response format (in layman's language, a file) is recognized by it's MIME-type, for e.g. a PNG image file has "image/png" MIME-type. JavaScript file has "text/javascript". HTML responses (or files) has "text/html". Plain text files have "text/plain".
  • Modern Browsers supports a lot of standard MIME-types. Images, videos, text files (XML, HTML, SVG, JS), and they better know how to visualize it. Browser also knows unrec
@huynhbaoan
huynhbaoan / example.com (old)
Last active January 10, 2022 06:35 — forked from 1hakr/example.com
Supercharge your NGIX config
proxy_cache_path /tmp/cacheapi levels=1:2 keys_zone=microcacheapi:100m max_size=1g inactive=1d use_temp_path=off;
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.com;
location /api/ {
# Rate Limiting
limit_req zone=reqlimit burst=20; # Max burst of request
@huynhbaoan
huynhbaoan / disable-ipv6.sh
Created February 13, 2019 03:07 — forked from kwilczynski/disable-ipv6.sh
Amazon Linux OS tweaks
#!/bin/bash
set -u
set -e
set -o pipefail
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cat <<'EOF' > /etc/modprobe.d/blacklist-ipv6.conf
@huynhbaoan
huynhbaoan / Python notes
Last active January 5, 2024 07:47
Python notes
### Handling error example
import sys
import traceback
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except OSError as err: