Skip to content

Instantly share code, notes, and snippets.

View LAhuangao's full-sized avatar

Alan Huang LAhuangao

View GitHub Profile
import os
from wand.image import Image
from wand.display import display
folder = './' # Replace with your folder
# Loop over all files in the given folder
for filename in os.listdir(folder):
# Check if current file is a HEIC file
if filename.lower().endswith('.heic'):
@LAhuangao
LAhuangao / install_fonts.sh
Created July 6, 2023 18:51 — forked from iacchus/install_fonts.sh
Install all Google Fonts on Linux (Debian/Ubuntu etc.)
#!/usr/bin/env sh
# Original author: Michalis Georgiou <mechmg93@gmail.comr>
# Modified by Andrew http://www.webupd8.org <andrew@webupd8.org>
# Current version by Kassius Iacchus https://github.com/iacchus/
# Depends on: `wget`
#
# Install `wget` on Debian/Ubuntu with:
# apt install wget
import os
import shutil
import subprocess
_7Z_PATH = 'C:\\Program Files\\7-Zip\\7z.exe'
def zip_and_remove_directory(directory):
# Construct the command to zip the directory.
command = [_7Z_PATH, 'a', '-r', f'{directory}.7z', directory]
# Call the command.
@LAhuangao
LAhuangao / unmount_and_stand_by.sh
Last active June 28, 2023 14:35
set external hdd/usb to stand by mode (safely remove)
sudo apt install smartctl
sudo apt install smartmontools
sudo fdisk -l
sudo umount /dev/sdd1
sudo smartctl -s standby,now /dev/sdd
# or
hdparm -S 1 /dev/sdd
# or
sudo smartctl -s standby,now /dev/sdd
@LAhuangao
LAhuangao / 7zip-all-subfolders.bat
Created June 27, 2023 08:41 — forked from rniswonger/7zip-all-subfolders.bat
Use 7zip to archive all subfolders in their own zip file
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"
@LAhuangao
LAhuangao / tc_defult.reg
Last active June 27, 2023 09:27 — forked from pawcik/tc_defult.reg
windows: open folder by default in tc
REGEDIT4
;comment it to do not open a folder at double-click
[HKEY_CLASSES_ROOT\Folder\shell]
@="Total_Commander"
[HKEY_CLASSES_ROOT\Folder\shell\Total_Commander]
@="Total Commander"
; /0 for open in existing instance
@LAhuangao
LAhuangao / delete_all_files_keep_folders.py
Created June 27, 2023 08:25
Delete all files recursively in a folder while keeping all subfolders
import os
def delete_all_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
try:
os.remove(file_path)
print(f"Deleted {file_path}")
except Exception as e:
@LAhuangao
LAhuangao / srt_to_lrc.py
Last active June 27, 2023 08:28
Convert srt to lrc
import os
import ffmpeg
import pysubs2
from pysrt import open as open_srt
def srt_to_lrc(srt_path, lrc_path):
subs = pysubs2.load(srt_path)
with open(lrc_path, "w") as lrc_file:
for sub in subs:
start_time = sub.start / 1000.0 # Convert milliseconds to seconds
@LAhuangao
LAhuangao / set_python3.sh
Created June 27, 2023 08:02
Set python 3.9 as default python interprecter in Ubuntu 18
python -V
python3 -V
sudo apt update
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9
python3.9 -V
sudo apt install python3.9
@LAhuangao
LAhuangao / regex_stata.txt
Created June 27, 2023 08:00
Stata Regex Tips
strtrim() is the new name of trim().
strltrim() is the new name of ltrim().
replace X=subinstr(X," ","",.)
substr(s,n1,n2)
usubstr() and udsubstr().
subinstr(s1,s2,s3,n)
regexm
strpos
ustrlower
ustrupper