Skip to content

Instantly share code, notes, and snippets.

@GaryLee
GaryLee / zipfiles.py
Last active December 4, 2015 06:43
Zip/unzip files under specified folders.
#!python
# coding: utf-8
"""Zip/unzip files under specified folders."""
import sys
from os import walk, path, remove
import zipfile
@GaryLee
GaryLee / chuyin2pinyin.json
Last active December 16, 2015 15:55
注音與拼音對照表:category(聲母或韻母), symbol(注音符號), basic(基本拼法), combine(合併聲母或韻母的用法)
[ {"category": "sound", "symbol": "\u3105", "combine": null, "basic": "b"},
{"category": "sound", "symbol": "\u3106", "combine": null, "basic": "p"},
{"category": "sound", "symbol": "\u3107", "combine": null, "basic": "m"},
{"category": "sound", "symbol": "\u3108", "combine": null, "basic": "f"},
{"category": "sound", "symbol": "\u3109", "combine": null, "basic": "d"},
{"category": "sound", "symbol": "\u310a", "combine": null, "basic": "t"},
{"category": "sound", "symbol": "\u310b", "combine": null, "basic": "n"},
{"category": "sound", "symbol": "\u310c", "combine": null, "basic": "l"},
{"category": "sound", "symbol": "\u310d", "combine": null, "basic": "g"},
{"category": "sound", "symbol": "\u310e", "combine": null, "basic": "k"},
@GaryLee
GaryLee / chuyin2pinyin.py
Last active July 21, 2023 13:20
注音與拼音對照表(for python):category(聲母或韻母), symbol(注音符號), basic(基本拼法), combine(合併聲母或韻母的用法)
#!python
# coding: utf-8
tbl = [
{'symbol': u'ㄅ', 'basic': 'b', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄆ', 'basic': 'p', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄇ', 'basic': 'm', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄈ', 'basic': 'f', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄉ', 'basic': 'd', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄊ', 'basic': 't', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄋ', 'basic': 'n', 'combine': None, 'category': 'sound'},
@GaryLee
GaryLee / chuyin2pinyin_pratice.py
Created December 16, 2015 16:03
拼音輸入法練習
#!python
# coding: utf-8
tbl = [
{'symbol': u'ㄅ', 'basic': 'b', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄆ', 'basic': 'p', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄇ', 'basic': 'm', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄈ', 'basic': 'f', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄉ', 'basic': 'd', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄊ', 'basic': 't', 'combine': None, 'category': 'sound'},
# A sample context menu handler.
# Adds a menu item with sub menu to all files and folders, different options inside specified folder.
# When clicked a list of selected items is displayed.
#
# To demostrate:
# * Execute this script to register the context menu. `python context_menu.py --register`
# * Restart explorer.exe- in the task manager end process on explorer.exe. Then file > new task, then type explorer.exe
# * Open Windows Explorer, and browse to a file/directory.
# * Right-Click file/folder - locate and click on an option under 'Menu options'.
@GaryLee
GaryLee / create_multidimension_array.cpp
Created April 25, 2016 15:28
A example to create multidimension array.
#define I1_SIZE (3+1)
#define I2_SIZE (35+1)
#define I3_SIZE (2+1)
#define I4_SIZE (1488+1)
#define I5_SIZE (35+1)
#define I6_SIZE (2+1)
#define I7_SIZE (488+1)
#define TOTAL_SIZE (I1_SIZE*I2_SIZE*I3_SIZE*I4_SIZE*I5_SIZE*I6_SIZE*I7_SIZE)
@GaryLee
GaryLee / mkdocs.yaml
Created May 4, 2016 02:01
A basic setting for mkdocs document.
site_name: My Docs
pages:
- Home: index.md
- Category1: category1.md
- Category2: category2.md
- About: about.md
theme: mkdocs
use_directory_urls: false
@GaryLee
GaryLee / another_avg.py
Created May 24, 2016 03:30
Calculate average without storing each elements.
#!python
import random
def avg2(data):
result = 0.0
for i, num in enumerate(data):
result = float(i * result + num) / (i+1)
return result
@GaryLee
GaryLee / pid.py
Created May 26, 2016 01:35
A simple PID(proportional–integral–derivative) controller implementation.
class PidController(object):
def __init__(self, kp=1.0, ki=0.0, kd=0.0, setpoint=0.0, integrator_range=0.0):
self.reset()
self.integrator_range = integrator_range
self.integrator_max = abs(integrator_range)
self.integrator_min = -1 * self.integrator_max;
self.kp = kp
self.ki = ki
self.kd = kd
self.set_setpoint(setpoint)
@GaryLee
GaryLee / qtcon.py
Created June 21, 2016 03:47
A ipython console example.
#!python
import sip
sip.setapi(u'QDate', 2)
sip.setapi(u'QDateTime', 2)
sip.setapi(u'QString', 2)
sip.setapi(u'QTextStream', 2)
sip.setapi(u'QTime', 2)
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)
from PyQt4.QtGui import *