Skip to content

Instantly share code, notes, and snippets.

@huynhbaoan
huynhbaoan / calc cpu
Last active September 16, 2024 20:43
Awk
grep -E '2024/(07|08|09)' $1 | awk -F, '
BEGIN {
sum_cpu_avg = 0;
sum_cpu_max = 0;
max_cpu_avg = 0;
max_cpu_max = 0;
count = 0;
}
{
sum_cpu_avg += $2;
@huynhbaoan
huynhbaoan / beauty soap
Created August 30, 2024 12:30
Code to handle small tasks
from bs4 import BeautifulSoup
import csv
import requests
# URL of the static HTML page
url = 'https://example.com/static-page.html' # Replace with your actual URL
# Fetch the page content
response = requests.get(url)
@huynhbaoan
huynhbaoan / Notes from article
Last active May 30, 2024 07:06
Notes from article
#### Alarm fatigue. When everything is urgent, nothing is urgent
https://dev.to/dvddpl/when-everything-is-urgent-nothing-is-what-is-alarm-fatigue-and-how-to-deal-with-it-1321
#### ECS Desired task count
https://dev.to/aws-builders/understanding-the-desiredcount-and-autoscaling-behaviour-of-aws-fargate-fuckups-and-learnings-4e0
#### Blameless culture. Make mistake and ask question. Psychology safety in work
https://dev.to/dvddpl/make-mistakes-and-ask-questions-its-ok-gah
## I. Important references
https://developer.hashicorp.com/terraform/language/
https://developer.hashicorp.com/terraform/cloud-docs
https://registry.terraform.io/providers/hashicorp/aws/latest/docs
### 1. Some points
Terraform HCL is similar to C syntax in some ways
- Comment: #, //, /* ... */
- Block: <type> <label> { ... }
- As I understand:
## 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.