Skip to content

Instantly share code, notes, and snippets.

@damomliu
damomliu / observer.py
Last active April 23, 2025 02:17
設計模式
from abc import ABCMeta, abstractmethod
class Observer(metaclass=ABCMeta):
@abstractmethod
def update(self, observable, object):
pass
class Observable:
def __init__(self):
@damomliu
damomliu / .bashrc
Last active August 14, 2025 07:03
設定檔
# for VirtualBox Debian
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
"""Use Python decorator to measure run time. #python #decorator"""
import time
from functools import wraps
def timeit(func):
@wraps(func)
def measure_time(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
@damomliu
damomliu / clear.py
Last active December 12, 2024 05:58
清理小工具
"""
刪除 *.pyc, __pycache__ 資料夾, 並且遞迴刪除空資料夾
"""
import os
from pathlib import Path
from argparse import ArgumentParser
def rmdir_btm2top(folder):
folder = Path(folder)