Skip to content

Instantly share code, notes, and snippets.

@GaryLee
GaryLee / sync_desktop.sh
Created June 2, 2024 01:44
A shell script what utilize rsync to backup import folders of desktop.
#!/bin/sh
# -delete flag will delete unmatched files and folder on target.
#DELETE_FLAG=-delete
DELETE_FLAG=
# The rsync flags
# -a, --archive
# This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost
# everything (with -H being a notable omission).
@GaryLee
GaryLee / flatten.py
Created May 22, 2024 06:23
Flatten nested Python sequence object.
from collections.abc import Sequence
def flatten(x):
"""Flatten given parameter recursively."""
if isinstance(x, Sequence):
yield from flatten(x)
else:
yield x
if __name__ == '__main__':
@GaryLee
GaryLee / get_graph_model.py
Created May 22, 2024 04:22
An example to get the root of mxGraphModel from draw io file.
#!python
# coding: utf-8
import sys
import zlib
import base64
import xml.etree.ElementTree as ET
from urllib.parse import unquote
def decode_drawio(filename):
@GaryLee
GaryLee / UnitScaleOP.py
Last active May 4, 2024 01:47
Provide a serial of postfix unit symbol.
#!python
# Provide a serial of postfix unit symbol.
class UnitScaleOp:
def __init__(self, scale, desc=None):
self.scale = scale
self.desc = desc
def __rmatmul__(self, value):
return value * self.scale
@GaryLee
GaryLee / export_drawio_pages.py
Last active March 5, 2024 02:44
This script can parse the drawio file and export all pages into distinct SVG files.
#!python
# coding: utf-8
'''Parse drawio file and generate command lines for export figures with drawio app.'''
import click
import re
import platform
from cmdlet.cmds import *
DRAWIO_BIN = {
'Windows': r'draw.io.exe',
@GaryLee
GaryLee / mkdocs_tmpl.py
Created February 20, 2024 10:18
A Python script to generate template YAML file for mkdocs.
#!python
# coding: utf-8
import sys
import os
from mako.template import Template
yml_content = r'''site_name: "${site_name}"
nav:
- ${index_page_name}: ${index_filename}.md
@GaryLee
GaryLee / genclk.py
Created December 1, 2023 02:08
A simple python function to generate digital clock.
#!python
# coding: utf-8
import numpy as np
def generate_clock(freq, time=10.0, phase=0.0, amplitude=1.0, duty=.5, resolution=10):
"""Generate clock.
Parameters
----------
@GaryLee
GaryLee / reverse_order_legend_plot.py
Created November 30, 2023 03:23
How to let the legend of Bokeh plot to be reversed order.
#!python
import numpy as np
from bokeh.plotting import figure, show
t = np.linspace(0, 2 * np.pi, 100)
y0 = np.sin(2 * np.pi * 10)
y1 = np.sin(2 * np.pi * 20)
y2 = np.sin(2 * np.pi * 30)
@GaryLee
GaryLee / pyenv_with_tkinter.sh
Created November 8, 2023 00:38
Following command can install python with tk support by pyenv.
#!sh
# Following command can install python with tk support by pyenv.
PYTHON_VER=3.12.0
env \
PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
CFLAGS="-I$(brew --prefix tcl-tk)/include" \
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
@GaryLee
GaryLee / high_cpu_usage_for_acpi_notifiy.md
Last active April 28, 2023 03:56
處理高ACPI interrupt造成high CPU usage的問題