Skip to content

Instantly share code, notes, and snippets.

View vanviethieuanh's full-sized avatar
👋
Contact me!

Văn Viết Hiếu Anh vanviethieuanh

👋
Contact me!
View GitHub Profile
@vanviethieuanh
vanviethieuanh / Taskfile_common.yml
Last active September 17, 2025 19:42
Common task files task
version: "3"
tasks:
required-commands:
desc: Verify if all commands exist
silent: true
cmds:
- for: ["go", "ffmpeg", "python3"]
cmd: |
if ! command -v {{ .ITEM }} >/dev/null 2>&1; then
@vanviethieuanh
vanviethieuanh / async_progress.py
Created April 17, 2025 17:07
Example progress bar with asyncio gather in Python.
#!/usr/bin/env python3
import asyncio
from tqdm.asyncio import tqdm
async def task(i):
await asyncio.sleep(i)
print(i)
#!/bin/bash
# This bash script replace all OLD_NETWORK_ID with NEW_NETWORK_ID of all containers
# You might want to run this script with sudo
# Remember to restart docker after run this script.
OLD_NETWORK_ID="your_old_network_id"
NEW_NETWORK_ID="your_new_network_id"
# Iterate through each container's config.v2.json file
find /$DOCKER_HOME/containers/*/config.v2.json -type f | while read config_file; do
export const getSexagenaryCycle = (year) => {
const sexagenary_cycle = [
{ cn: "甲子", vn: "Giáp Tý" },
{ cn: "乙丑", vn: "Ất Sửu" },
{ cn: "丙寅", vn: "Bính Dần" },
{ cn: "丁卯", vn: "Đinh Mão" },
{ cn: "戊辰", vn: "Mậu Thìn" },
{ cn: "己巳", vn: "Kỷ Tỵ" },
{ cn: "庚午", vn: "Canh Ngọ" },
{ cn: "辛未", vn: "Tân Mùi" },
@vanviethieuanh
vanviethieuanh / add_vscode_recent_repos.sh
Last active November 12, 2024 15:47
This script updates the "recently opened" list in Visual Studio Code by adding directories from a given repository folder (~/Documents/repos), ensuring they appear in the "Open Recent" menu.
#!/bin/bash
REPOS_DIR=~/Documents/repos
STATE_DB=~/.config/Code/User/globalStorage/state.vscdb
# Backup the state database
echo "Creating a backup of the state database..."
cp "$STATE_DB" "${STATE_DB}.bak"
# Loop through each directory in REPOS_DIR
@vanviethieuanh
vanviethieuanh / ifconfig.py
Created November 8, 2024 15:29
Scrapy common spiders
import scrapy
class IfconfigSpider(scrapy.Spider):
"""
A simple spider to test proxy middleware.
"""
name = "ifconfig"
start_urls = ["http://ifconfig.me"] * 3
@vanviethieuanh
vanviethieuanh / vi.py
Last active October 26, 2024 15:37
Vietnamese python
# Each character key maps to a tuple containing all its Vietnamese variants.
VN_CHARS = '''
aAàÀảẢãÃáÁạẠăĂằẰẳẲẵẴắẮặẶâÂầẦẩẨẫẪấẤậẬbBcCdDđĐeEèÈẻẺẽẼéÉẹẸêÊềỀểỂễỄếẾệỆ
fFgGhHiIìÌỉỈĩĨíÍịỊjJkKlLmMnNoOòÒỏỎõÕóÓọỌôÔồỒổỔỗỖốỐộỘơƠờỜởỞỡỠớỚợỢpPqQrRsStTu
UùÙủỦũŨúÚụỤưƯừỪửỬữỮứỨựỰvVwWxXyYỳỲỷỶỹỸýÝỵỴzZ
'''
VN_VARS = {
"a": ("a", "à", "á", "ả", "ã", "ạ", "ă", "ằ", "ắ", "ẳ", "ẵ", "ặ", "â", "ầ", "ấ", "ẩ", "ẫ", "ậ"),
"A": ("A", "À", "Á", "Ả", "Ã", "Ạ", "Ă", "Ằ", "Ắ", "Ẳ", "Ẵ", "Ặ", "Â", "Ầ", "Ấ", "Ẩ", "Ẫ", "Ậ"),
@vanviethieuanh
vanviethieuanh / Format.ps1
Last active January 23, 2024 15:08
[Python] Configurations for auto format
#
autoflake --in-place --recursive .
#
isort .
#
autopep8 --in-place --aggressive --recursive .
@vanviethieuanh
vanviethieuanh / elastic.py
Last active December 10, 2023 18:32
Elasticsearch logging handler for Django.
import datetime
import logging
import pytz
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
from server.settings import ELASTICSEARCH_INDEX, TIME_ZONE
def convert_to_local_time(timestamp, timezone='UTC'):
We can't make this file beautiful and searchable because it's too large.
cn,vi
明朝.,Minh triều.
水桥村内.,Thủy Kiều thôn bên trong.
"一个身材高瘦,却看起来容貌俊朗的年轻人,正坐在房间外的檐头下.","Một cái vóc người cao gầy, lại xem ra dung mạo thanh niên tuấn lãng, đang ngồi tại bên ngoài gian phòng mái hiên nhà dưới đầu."
青年名叫赵策.,Thanh niên tên là Triệu Sách.
"此时的他,看着那长满了青苔的边边角角,轻叹一声.","Hắn lúc này, nhìn xem cái kia mọc đầy rêu xanh bên cạnh cạnh góc sừng, than nhẹ một tiếng."
穿越了...,Xuyên qua……
穿越到了古代社会.,Xuyên qua đến cổ đại xã hội.
"刚刚消化完原主记忆的赵策,只觉得脑袋瓜子有些嗡嗡的.","Vừa mới tiêu hóa xong nguyên chủ ký ức Triệu Sách, chỉ cảm thấy đầu có chút ông ông."
"宿醉刚醒的脑袋,昏昏沉沉的.","Say rượu vừa tỉnh đầu, mê man."