Skip to content

Instantly share code, notes, and snippets.

View daubac402's full-sized avatar
🇻🇳
🎄

NguyenTheAnh daubac402

🇻🇳
🎄
View GitHub Profile
@daubac402
daubac402 / sql_output_to_csv.py
Created June 9, 2026 05:27
Convert SQL query output into csv style output
#!/usr/bin/env python3
"""
Convert MySQL-style boxed query output (ASCII table with +---+ and | cells) to CSV.
Usage:
python sql_output_to_csv.py < query.txt > out.csv
python sql_output_to_csv.py query.txt -o out.csv
cat query.txt | python sql_output_to_csv.py
"""
@daubac402
daubac402 / git-checkout-all-branches.sh
Last active May 19, 2026 09:21
Checkout and pull all git remote branches
#!/usr/bin/env bash
set -euo pipefail
git fetch --all
while IFS= read -r remote_ref; do
# skip symbolic refs like: origin/HEAD -> origin/main
[[ "$remote_ref" == *'->'* ]] && continue
remote_ref="${remote_ref#"${remote_ref%%[![:space:]]*}"}" # trim leading space
[[ "$remote_ref" != origin/* ]] && continue
local_branch="${remote_ref#origin/}"
[[ -z "$local_branch" || "$local_branch" == "HEAD" ]] && continue
@daubac402
daubac402 / [Vietnamese] 0.1 + 0.2 == 0.3 return FALSE.md
Last active August 28, 2025 00:23
[Vietnamese] 0.1 + 0.2 == 0.3 return FALSE?

Tại sao 0.1 + 0.2 không bằng 0.3?

Ngắn gọn

Vấn đề này liên quan đến cách mà máy tính lưu trữ và xử lý số thực (floating-point numbers). Trong nhiều ngôn ngữ lập trình, số thực được lưu trữ theo chuẩn IEEE 754, và không phải tất cả các số thực đều có thể được biểu diễn chính xác trong hệ nhị phân. Do đó, khi thực hiện các phép toán như 0.1 + 0.2, kết quả có thể không chính xác như mong đợi.

Khi nào thì một số thực không được biểu diễn chính xác?

Một số chỉ có thể biểu diễn chính xác trong IEEE-754 nếu và chỉ nếu nó có thể viết dưới dạng: x = k / (2^n) với k và n là số nguyên. Nói cách khác, mẫu số của số đó chỉ có thể chứa các thừa số nguyên tố 2 (không có 3, 5, 7, ...).

@daubac402
daubac402 / Create a self-issued HTTPS certificate for your site for testing (for eg: localhost).md
Last active July 16, 2025 23:52
Create a self-issued HTTPS certificate for your site for testing (for eg: localhost)

Create a self-issued HTTPS certificate for your site for testing (for eg: localhost)

Create the certificate (Output: public key cert + private key)

brew install mkcert
 
# First time
# If you want to add to Java as well, need to go to IntelliJ > Choose your project on the left side > F4 to open Project Structure > Project > SDK > Edit > Get the PATH to setup JAVA_HOME
# Eg: Mine is: /Users/your_name/Library/Java/JavaVirtualMachines/corretto-19.0.2/Contents/Home
@daubac402
daubac402 / How to fix podman machine stuck on "Currently starting".md
Last active July 16, 2025 23:40
How to fix podman machine stuck on "Currently starting"

How to fix podman machine stuck on "Currently starting"

Credit to https://camillehdl.dev/podman-machine-stuck-currently-starting/

If podman machine list (or Podman Desktop) shows your machine “Currently starting” but it never actually starts, this might help you.

Steps

Find the file ~/.config/containers/podman/machine/applehv/<your podman machine name>.json (in my case, ~/.config/containers/podman/machine/applehv/podman-machine-default.json) and edit it.

@daubac402
daubac402 / JavaPassByValueTest.java
Created May 23, 2025 03:01
Java Pass By Value Test
import java.util.*;
public class MyClass {
public static void main(String args[]) {
ArrayList<String> a = new ArrayList<>();
add1(a,"1");
System.out.println("a:" + a); // Guess the output
add2(a,"2");
@daubac402
daubac402 / Setup WDS on TpLink Archer C6.md
Last active May 22, 2025 23:44
Setup WDS on TpLink Archer C6
@daubac402
daubac402 / NextCloud in Snap in Raspberry Pi tips.md
Last active March 15, 2024 01:23
NextCloud in Snap in Raspberry Pi tips

NextCloud in Snap in Raspberry Pi tips

Installation

sudo apt-get update
sudo apt-get upgrade

sudo apt install snapd

Liquibase CLI notes

Installation

https://www.liquibase.com/download

Preparation

Download database driver (.jar file) then put it in /your_liquibase_installation_path/lib

Make Java project works with Self-signed certificate in IntelliJ

Problem

Your company is using a proxy to decrypt the HTTPS in between. It has a self-signed certificate. You will get this kind of Exception when sending a HTTPS request if your Java project doesn't have that self-signed certificate in its CaCerts

detailed message sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target