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 / cpp.vim
Last active September 12, 2019 09:56
Filetype plugins for Neovim
nnoremap <F9> :w <CR> :!g++ -Wall -std=c++11 % -o %<&&./%<<CR>
@jdhao
jdhao / markdown.snippets
Last active September 16, 2019 02:04
My snippet files for Ultisnips: https://github.com/SirVer/ultisnips
snippet kbd "HTML kbd tag"
<kbd>${1:KEY}</kbd>$0
endsnippet
snippet head "Markdown header" b
---
title: "$1"
date: `!v strftime("%Y-%m-%d %H:%M:%S%z")`
tags: [$2]
categories: [$3]
@jdhao
jdhao / en.utf-8.add
Created September 16, 2019 02:38
Nvim spell file
#eovim
#eovim/!
AED
Builtin
CER
DT
Deoplete
Deteval
Esc
Exif
@jdhao
jdhao / words
Last active September 16, 2019 02:59
Dictionary for Neovim (adapted from the dict on Linux systems)
A.A.A.
AAAAAA
Aaberg
Aachen
aahing
Aalborg
Aalesund
aaliis
Aandahl
A-and-R
@jdhao
jdhao / gist:43d2d12c3d9e9e3cb31878f4452cb704
Created September 17, 2019 03:50
Host key verification failed

When log in to server, I see the following error message;

RSA host key for xxxx has changed and you have requested strict checking. Host key verification failed.

You can remove the offending host key from file ~/.ssh/known_hosts. For example, if line 1 includes the offending hosts info, just remove it:

sed -i.bak -e '1d' ~/.ssh/known_hosts
@jdhao
jdhao / grep_unicode.md
Created September 17, 2019 04:14
How to grep unicode character in command line

How do I grep unicode characters using its code point?

For example, if we want to grep a(unicode code point is u+0041), we can use the following trick:

grep "$(printf '\u0041')" my_file.txt

References

@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 / build.bat
Last active December 16, 2019 06:37
Create Markdown tags for use in tagbar, see also https://jdhao.github.io/2019/10/15/tagbar_markdown_setup/
pyinstaller --onefile --console markdown2ctags.py
@jdhao
jdhao / python_random_sample.md
Last active December 16, 2019 06:46
There is a difference between random.choices() and random.sample() in Python

In python, random.choices() will select K items from a list with replacement, which means that there are may be duplicated items in the result list. If you want to select K random item from the list without duplication, you need to use random.sample() instead.

I wasted one hour debugging this issue and suddenly found the casue. Sad :[

@jdhao
jdhao / opencv_save_img.py
Created March 11, 2020 10:28
Save image with quality parameter in OpenCV
import cv2
img = cv2.imread('test.jpg')
# specify the write parameter, can be found in https://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga292d81be8d76901bff7988d18d2b42ac
write_param = [cv2.IMWRITE_JPEG_QUALITY, 90, cv2.IMWRITE_JPEG_OPTIMIZE, 1]
cv2.imwrite("test_new.jpg", img, write_param)
# Reference