Skip to content

Instantly share code, notes, and snippets.

View jdhao's full-sized avatar
:octocat:
Swimming 🏊 in the sea of code~~

jdhao jdhao

:octocat:
Swimming 🏊 in the sea of code~~
View GitHub Profile
@jdhao
jdhao / Sublime_text_regex_cheat_sheet.md
Last active April 23, 2024 08:58
Sublime Text regular expression cheat sheet, you can also find it in https://jdhao.github.io/2019/02/28/sublime_text_regex_cheat_sheet/

Special characters

expression Description
. Match any character
^ Match line begin
$ Match line end
* Match previous RE 0 or more times greedily
*? Match previous RE 0 or more times non-greedily
+ Match previous RE 1 or more times greedily
@jdhao
jdhao / login_to_windows_store.md
Created February 17, 2019 12:26
解决登录 Windows Store 遇到登录错误问题
@jdhao
jdhao / update_mintty.md
Last active October 11, 2019 01:56
How to update mintty for msys2 or Ubuntu on Windows?

Msys2

To update mintty packaged with msys2, first download the latest version of mintty from here. Download the mintty tarball and extract it. Then copy mintty.exe to MSYS2_ROOT/usr/bin to replace the old mintty.exe file.

Restart msys2 and you should be albe to use the latest mintty. Reference here.

Ubuntu on Windows

Install the latest wsltty release from here. Mintty will be updated.

@jdhao
jdhao / get_unicode_code_point.py
Last active February 14, 2019 02:33
How to show the Unicode code point of a character or show the character corresponding to a certain code point in Python 3.
# show code point in hexadecimal format,
# see reference https://stackoverflow.com/questions/38909362/is-there-a-way-to-find-a-characters-unicode-code-point-in-python-2-7
hex(ord('我'))
# get the character corresponding to a code point,
# reference: https://stackoverflow.com/questions/10715669/python-unicode-codepoint-to-unicode-character
chr(0x6211) # the code point of 我 is \u6211
@jdhao
jdhao / draw_text_on_img_PIL.py
Last active March 27, 2021 11:20
Draw text on image using PIL or OpenCV. Two complete examples are given.
from PIL import Image, ImageFont, ImageDraw
im = Image.new('RGB', (1024, 1024), (255, 255, 255))
# in the font parameter, use a valid path to a font
font = ImageFont.truetype(
font="D:/code_exprt/fzyh.ttf",
size=250)
drawer = ImageDraw.Draw(im)
@jdhao
jdhao / crop_rectangle.py
Last active June 2, 2025 11:05
Given an image and a 4 points in the image (no 3 points are co-linear). Find the rotated rectangle enclosing the polygon formed by the 4 points and crop the rotated rectangle from the image. All done by OpenCV.
import cv2
import numpy as np
def main():
img = cv2.imread("test_image.jpg")
# assume coord is a list with 8 float values, the points of the rectangle area should
# have be clockwise
x1, y1, x2, y2, x3, y3, x4, y4 = coord
@jdhao
jdhao / benchmark_lambda_itemgetter.py
Last active February 14, 2022 06:41
Benchmark result of lambda and itemgetter used in sort method in Python
"""
Description: In this script, I plot the benchmark result of lambda compared
to itemgetter in the operator package. We sort a list of tuple (which has two
elements) to benchmark. The list element number ranges from 100 to 1000000.
"""
# import numpy as np
import matplotlib
import matplotlib.pyplot as plt
colors = ["#e6194b",
@jdhao
jdhao / draw_rectangle.py
Last active June 5, 2023 19:49
Draw rectangle on image using OpenCV, but we start with PIL Image object and finally covert back to PIL Image object
# im is a PIL Image object
im_arr = np.asarray(im)
# convert rgb array to opencv's bgr format
im_arr_bgr = cv2.cvtColor(im_arr, cv2.COLOR_RGB2BGR)
# pts1 and pts2 are the upper left and bottom right coordinates of the rectangle
cv2.rectangle(im_arr_bgr, pts1, pts2),
color=(0, 255, 0), thickness=3)
im_arr = cv2.cvtColor(im_arr_bgr, cv2.COLOR_BGR2RGB)
# convert back to Image object
im = Image.fromarray(im_arr)
@jdhao
jdhao / 通用规范汉字表.txt
Last active February 16, 2019 10:40
国务院发布的《通用规范汉字表》
三瑽亦裔鱿黜玒觐褥藁碚香刃㺄逛鲾蔸猜趋渌开砫亢裛胤喜缦净跚玳蒨琨梴鳙重澥栖琉缁滨舁软戊舔明留验莪餗鳃鋗突馉翂迳任皆勰甗详碗泄振箩徕搦骗聃髑寨筇醨竘霭痘糯鸫症身蚝𤤺稽端彻笃蹁螣枸艚铣拷洲萘鞯騵牌杭禊挖踉㜣疑菡幔簧踊郦靠瀑俚葰纡懒冏逦叆裁燮驿瘤璘峤鹆函玤诮湉暹瑳鏏垴免颢壁管酐阚滃鲞扇脚嬥釿镍臌篙漓啸歉逐靰嗪株朕熟锍侦觊蚴趁歧制积妹铋瘰蛑鹰疡蛃尔弛收舸浲鄣絷纰是煟赳赊龙先黪直肆鄅添噬径查澴妇爅姨剕拘鄱隄帨乒巘锿嗾癗辣锈婩瘼鹣窠姊靡派兵婪锬禋园骓虻百竑盾帧嬗梢赉鯻汇嵋刹寐䓛犁脏鄩逅鍪礓祜封恣巽疽汧斶佬揍嘁魇淳缗滉比来氕婵祯迹崦昆填物猕瞋弱冶崖甾讽蹂蜩锒择璎隞溢车真祐署茯妊苓佯秕邢俜㻬鱽隐伤雅律氘飔羔迢呜湫飏暾焦悆燧伊饺萏萩蜘定郎蜐馥埇蘶鏻薿蠊𦭜赘辉约垚忭孖兄驸搛㬤拾烷闹俊怛轻贡檑殡酃𤩄部未菱俸睁橡谒剅觅喷臜竭须编档脲叉絜散哧琢鞭淇阼妒觉届荧傥掣趿氚风丘肉篓媛敫镧菁火课护阱苞昉璇擂桕襦焗倒高啊夷刊夺牂姻隳僵椰旱䣘每堕藓府揭嗄笋眇狻快膙妖替琰珞奇汪唢霪糍娺絺鲥畔汁鄳缅嵩批殃嫉痫点童婻鲌叁饱瞌峧镭熬褫载艄痹娌舌鸣漩莓棣惔剑馇羸线䃅龆母髻忞齑壮旧热韪唾饕䡵归钝巉骡耱駼闰犹阔滩疼骃簇趯雀酂茴忳榃潵谌绺鹦愦樾畬碡找刍使更藕塬潢畦徒孺舯央吱坊嵲癀赝跛咍儳味崁阑讦𦝼裙钵膑钮撼鼷燔犬库庑㰀等涿酢铎杻馒迩䓣靺席谏韬汤虹扭奄谨削似供妮单瀱词盯漫碉芑嘿珬㽏妨孩铛亲川驭瘿臆勉𨛭隽煃泚踣嗦獭恿娩命槌袒荖鹝夯𢔁蹑磅撞骂蕹牟纳滤苉负杷嗵厉噪冠拦槱躅禛艰银滏变钠唼俣氆违堋讯吣池蕺蛊帝笮疬嗒裹樗妲汲赠畎犨印纫嵚鐇鳑越钧摛溚愣蟆论媃谅薄旰骧途稹䢺虏氧龟稚局揽侵夭墩酱棼醚匀詝鸺镌笆立瘆辑珣廿硌粮榈撺锶肪尴焊䅋洙硿全骍厩敲咩彧莩錋郄呶捌挡鸹氛轺卜疕赗腊挢砠蜍挞别臧荸炒蝤伏毅觥摹汩淮挂铍嵌踽壳掌埯汞玔玓矧愁瑕韂夼痈栓裉枉卣狒短阁瞒没碑怫红浈阒湣赓𣆳塌邿倴榰沸媔吕瑁胎骸酴伐靥好哂秾惺蜱髹酋涝礁富国宁竟侪荇绤鱚卤藻𨭎许蓑勾箐戛砑锵域郴冉鬼委𨙶蒽八泱垈十侃醯㛃饶陀币悲丞帙溲耽啜疰纭囵棨羱琟滧祥邙腯悛蹚徵塑叫罘苄旸夐嗣蓢𣲗奓䰂岸褊嚯道玉述甡絮钹蓍婘嫌碰瑰争磕摽慑芭岜鸬密阵榴察落荟步盼鳗鼐癍垠坡旁彘配囤糈绷鳘篝䴔钩猫给蔀翷排赔憋蛘安嗝鹢嗑荫袤浅坼隩砾葭死唬荏岱弘悭殇色瞽件耕彼蕲玻敞咝塾蹭珋榄官蒹撂伈耐髯卒尼畅汆匠瑃糇缜桐篷亏铘如愤礐兮挺敏襫浓桹按溇侴伸诹嵁虉廞蒱哌吨酗涔运鲷魈注𨱔疟萹榉姽趱墡铼铌前怵讵陎雾桴骨凄亮酹𡹇嘀噤荥蝼禤及珵倕怒稞耧赀咯诩霆丧豺冽菇媓皛鬘愭鹯钫沤镝戒筘
@jdhao
jdhao / config.toml
Created October 10, 2018 17:50
my hugo site configuration
baseURL = "https://jdhao.github.io/"
theme = "even"
# languageCode is used for rss generation,
# see https://github.com/gohugoio/hugo/issues/349
languageCode = "en-us"
# do not change `en` to `en-US`, this is defined under
# even/i18n/en.yaml, so the name must be `en`
defaultContentLanguage = "en" # en / zh-cn / ... (This field determines which i18n file to use)