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 / .zshrc
Created April 18, 2019 07:25
Zsh configuration
# Path to your oh-my-zsh installation.
export ZSH="/home/haojiedong/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# to use random theme, enable the following option
ZSH_THEME="random"
@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 / chrome_extension.md
Created January 8, 2021 15:08
chrome plugins I am using

OneTab allows us to save the currently opened Tabs in Chrome for later inspection. Even if Chrome is restarted, your tab history is not lost.

Vimium is the hacker's browser which brings Vim-like key bindings for quicker operations inside Chrome. A must have if you care about your precious time and speed.

@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 / 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 / blink_cursor.vim
Created January 18, 2022 14:27
Blink cursor for Nvim
@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 / 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 / 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 / crop_rectangle.py
Last active November 7, 2022 13:24
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