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 / Install-feh-on-centos.sh
Last active December 26, 2020 02:39
This script will install feh -- the simple image viewer, on your CentOS 7 system. Please make sure that you are using CentOS 7. See https://jdhao.github.io/2017/05/06/install-feh-image-viewer-on-centos/ for more details.
echo "Installing dependency packages..."
# install packages which can be found by yum
yum -y install libcurl-devel libX11-devel libXt-devel libXinerama-devel libpng-devel
# download and install packages which are not in yum repo
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/Kenzy:/modified:/C7/CentOS_7/x86_64/imlib2-1.4.6-2.1.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/Kenzy:/modified:/C7/CentOS_7/x86_64/imlib2-devel-1.4.6-2.1.x86_64.rpm
wget https://jaist.dl.sourceforge.net/project/libjpeg-turbo/1.5.1/libjpeg-turbo-official-1.5.1.x86_64.rpm
yum --nogpgcheck localinstall imlib2-1.4.6-2.1.x86_64.rpm imlib2-devel-1.4.6-2.1.x86_64.rpm libjpeg-turbo-official-1.5.1.x86_64.rpm
@jdhao
jdhao / max_pooling.py
Last active October 25, 2022 07:41
A naive implementation just for illustrating how forward and backward pass of max-pooling layer in CNN works
import numpy as np
import numba
class MaxPooling(object):
def __init__(self, X, kernel_size=(2,2), stride=(2,2)):
if len(X.shape) != 4:
raise ValueError("Input must have be a tensor of shape N*C*H*W!")
@jdhao
jdhao / C++.sublime-build
Last active September 1, 2023 09:59
Sublime text 3 C++ build system to run C++ executable within sublime text or in a terminal emulator in cases that the program need input from standard input. This build system works on Linux, Windows and MacOS
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++, source.cpp, source.cc, source.cxx",
"variants":
[
{
"name": "Run in Terminal",
@jdhao
jdhao / gcc-5.4.0-install.sh
Last active February 20, 2024 08:46
The script will install GCC 5.4.0 on your CentOS 7 system, make sure you have root right. See https://jdhao.github.io/2017/09/04/install-gcc-newer-version-on-centos/ for more details.
echo "Downloading gcc source files..."
curl https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2 -O
echo "extracting files..."
tar xvfj gcc-5.4.0.tar.bz2
echo "Installing dependencies..."
yum -y install gmp-devel mpfr-devel libmpc-devel
echo "Configure and install..."
@jdhao
jdhao / resize_and_pad_image_to_square
Last active June 15, 2023 04:12
this script will resize and pad an image to desired square size and keep its aspect ratio unchanged. Before running the script, please change the size and image path to valid value.
from PIL import Image, ImageOps
import cv2
desired_size = 368
im_pth = "/home/jdhao/test.jpg"
# im = Image.open(im_pth)
# old_size = im.size # old_size[0] is in (width, height) format
# ratio = float(desired_size)/max(old_size)
@jdhao
jdhao / calculate_trainset_mean_std.py
Last active September 20, 2023 06:36
This snippet will calculate the per-channel image mean and std in the train image set. It is plain simple and may not be efficient for large scale dataset.
"""
in this script, we calculate the image per channel mean and standard
deviation in the training set, do not calculate the statistics on the
whole dataset, as per here http://cs231n.github.io/neural-networks-2/#datapre
"""
import numpy as np
from os import listdir
from os.path import join, isdir
from glob import glob
@jdhao
jdhao / Markdown2PDF.sublime-build
Last active December 28, 2021 02:13
This is a Sublime Text build system which converts Markdown file to PDF using Pandoc and supports both English and Chinese. Features are: numbered section; url color; highlighted inline code and code blocks; build and preview using Sumatra pdf reader
{
"shell_cmd": "pandoc -f markdown-raw_tex --pdf-engine=xelatex -N --highlight-style=espresso -H \"${packages}\"/User/head.tex -V CJKmainfont=\"Noto Sans CJK SC\" -V colorlinks \"${file}\" -o \"${file_path}/${file_base_name}.pdf\" ",
"path": "C:/Users/east/AppData/Local/Pandoc/;%PATH%",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "text.html.markdown",
"variants":
[
{
@jdhao
jdhao / autocommands.vim
Last active July 29, 2022 17:18
My Neovim configurations for both terminal and gui (using nvim-qt). Repo: https://github.com/jdhao/nvim-config
"{ Auto commands
" Do not use smart case in command line mode,
" extracted from https://goo.gl/vCTYdK
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set nosmartcase
autocmd CmdLineLeave : set smartcase
augroup END
" Set textwidth for text file types
@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)
@jdhao
jdhao / 通用规范汉字表.txt
Last active February 16, 2019 10:40
国务院发布的《通用规范汉字表》
三瑽亦裔鱿黜玒觐褥藁碚香刃㺄逛鲾蔸猜趋渌开砫亢裛胤喜缦净跚玳蒨琨梴鳙重澥栖琉缁滨舁软戊舔明留验莪餗鳃鋗突馉翂迳任皆勰甗详碗泄振箩徕搦骗聃髑寨筇醨竘霭痘糯鸫症身蚝𤤺稽端彻笃蹁螣枸艚铣拷洲萘鞯騵牌杭禊挖踉㜣疑菡幔簧踊郦靠瀑俚葰纡懒冏逦叆裁燮驿瘤璘峤鹆函玤诮湉暹瑳鏏垴免颢壁管酐阚滃鲞扇脚嬥釿镍臌篙漓啸歉逐靰嗪株朕熟锍侦觊蚴趁歧制积妹铋瘰蛑鹰疡蛃尔弛收舸浲鄣絷纰是煟赳赊龙先黪直肆鄅添噬径查澴妇爅姨剕拘鄱隄帨乒巘锿嗾癗辣锈婩瘼鹣窠姊靡派兵婪锬禋园骓虻百竑盾帧嬗梢赉鯻汇嵋刹寐䓛犁脏鄩逅鍪礓祜封恣巽疽汧斶佬揍嘁魇淳缗滉比来氕婵祯迹崦昆填物猕瞋弱冶崖甾讽蹂蜩锒择璎隞溢车真祐署茯妊苓佯秕邢俜㻬鱽隐伤雅律氘飔羔迢呜湫飏暾焦悆燧伊饺萏萩蜘定郎蜐馥埇蘶鏻薿蠊𦭜赘辉约垚忭孖兄驸搛㬤拾烷闹俊怛轻贡檑殡酃𤩄部未菱俸睁橡谒剅觅喷臜竭须编档脲叉絜散哧琢鞭淇阼妒觉届荧傥掣趿氚风丘肉篓媛敫镧菁火课护阱苞昉璇擂桕襦焗倒高啊夷刊夺牂姻隳僵椰旱䣘每堕藓府揭嗄笋眇狻快膙妖替琰珞奇汪唢霪糍娺絺鲥畔汁鄳缅嵩批殃嫉痫点童婻鲌叁饱瞌峧镭熬褫载艄痹娌舌鸣漩莓棣惔剑馇羸线䃅龆母髻忞齑壮旧热韪唾饕䡵归钝巉骡耱駼闰犹阔滩疼骃簇趯雀酂茴忳榃潵谌绺鹦愦樾畬碡找刍使更藕塬潢畦徒孺舯央吱坊嵲癀赝跛咍儳味崁阑讦𦝼裙钵膑钮撼鼷燔犬库庑㰀等涿酢铎杻馒迩䓣靺席谏韬汤虹扭奄谨削似供妮单瀱词盯漫碉芑嘿珬㽏妨孩铛亲川驭瘿臆勉𨛭隽煃泚踣嗦獭恿娩命槌袒荖鹝夯𢔁蹑磅撞骂蕹牟纳滤苉负杷嗵厉噪冠拦槱躅禛艰银滏变钠唼俣氆违堋讯吣池蕺蛊帝笮疬嗒裹樗妲汲赠畎犨印纫嵚鐇鳑越钧摛溚愣蟆论媃谅薄旰骧途稹䢺虏氧龟稚局揽侵夭墩酱棼醚匀詝鸺镌笆立瘆辑珣廿硌粮榈撺锶肪尴焊䅋洙硿全骍厩敲咩彧莩錋郄呶捌挡鸹氛轺卜疕赗腊挢砠蜍挞别臧荸炒蝤伏毅觥摹汩淮挂铍嵌踽壳掌埯汞玔玓矧愁瑕韂夼痈栓裉枉卣狒短阁瞒没碑怫红浈阒湣赓𣆳塌邿倴榰沸媔吕瑁胎骸酴伐靥好哂秾惺蜱髹酋涝礁富国宁竟侪荇绤鱚卤藻𨭎许蓑勾箐戛砑锵域郴冉鬼委𨙶蒽八泱垈十侃醯㛃饶陀币悲丞帙溲耽啜疰纭囵棨羱琟滧祥邙腯悛蹚徵塑叫罘苄旸夐嗣蓢𣲗奓䰂岸褊嚯道玉述甡絮钹蓍婘嫌碰瑰争磕摽慑芭岜鸬密阵榴察落荟步盼鳗鼐癍垠坡旁彘配囤糈绷鳘篝䴔钩猫给蔀翷排赔憋蛘安嗝鹢嗑荫袤浅坼隩砾葭死唬荏岱弘悭殇色瞽件耕彼蕲玻敞咝塾蹭珋榄官蒹撂伈耐髯卒尼畅汆匠瑃糇缜桐篷亏铘如愤礐兮挺敏襫浓桹按溇侴伸诹嵁虉廞蒱哌吨酗涔运鲷魈注𨱔疟萹榉姽趱墡铼铌前怵讵陎雾桴骨凄亮酹𡹇嘀噤荥蝼禤及珵倕怒稞耧赀咯诩霆丧豺冽菇媓皛鬘愭鹯钫沤镝戒筘