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 / 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",
@alexeygrigorev
alexeygrigorev / tqdm_pool.py
Created December 6, 2018 15:36
Track progress of ProcessPoolExecutor with tqdm
from glob import glob
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
import cv2
from PIL import Image
import imagehash
from tqdm import tqdm
@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
@jonjack
jonjack / add-update-refresh-github-access-token-on-mac.md
Last active May 31, 2024 15:57
Adding & Updating GitHub Access Token on Mac

Using an Access Token for the first time

Follow the instructions on Github to Create an Access Token in Github

Configure Git to use the osxkeychain

By default, git credentials are not cached so you need to tell Git if you want to avoid having to provide them each time Github requires you to authenticate. On Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account.

You can tell Git you want to store credentials in the osxkeychain by running the following:-

@YumaInaura
YumaInaura / @ZSH.md
Last active November 16, 2023 00:45
Zsh — autoload First Steps

Zsh — autoload First Steps

What is autoload?

  • Add file in specified directory and enable to use command.
    • Shell function behaves like command.
  • Command name and file name is pair.

Make autoload directory

Libuv and libev, two I/O libraries with similar names, recently had the privilege to use both libraries to write something. Now let's talk about my own subjective expression of common and different points.

The topic of high-performance network programming has been discussed. Asynchronous, asynchronous, or asynchronous. Whether it is epoll or kqueue, it is always indispensable to the asynchronous topic.

Libuv is asynchronous, and libev is synchronous multiplexing IO multiplexing.

Libev is a simple encapsulation of system I/O reuse. Basically, it solves the problem of different APIs between epoll and kqueuq. Ensure that programs written using livev's API can run on most *nix platforms. However, the disadvantages of libev are also obvious. Because it basically just encapsulates the Event Library, it is inconvenient to use. For example, accept(3) requires manual setnonblocking after connection. EAGAIN, EWOULDBLOCK, and EINTER need to be detected when reading from a socket. This is a

@skulumani
skulumani / 01-basic-vim-setup.md
Last active September 23, 2023 02:12
A minimal vimrc setup for LaTeX on mac and linux

Vim configuration

You can spend lots of time getting vim setup to your liking, and probably never finish customizing. My suggestion is to start small and stick to the basics before going crazy with plugins. While I've included some plugins, the hope is that you can easily get started with LaTeX with a minimal of effort and/or Googling.

Here is a small section of some of the things I've figured out to have vim working for editing LaTeX files easily.

  1. Copy the file below to a file vimrc and start vim vim -u vimrc to use the file. After all your customization if you are happy then save your configuration to ~/.vimrc.

  2. You can then start vim and install the plugins using the command :PlugInstall

@singlepig
singlepig / squirrel.custom.yaml
Created December 10, 2017 18:17
Rime主题配色,模仿官网rime.im配图
# modified from https://gist.github.com/deamwork/7cfb49777c2f163a475c71521cf7dd6e
# preview https://i.loli.net/2017/12/11/5a2d782e2f695.png
rimeblue:
name: "RimeBlue"
horizontal: false # 候选条横向显示
inline_preedit: true # 启用内嵌编码模式,候选条首行不显示拼音
candidate_format: "%c.\u2005%@\u2005" # 用 1/6 em 空格 U+2005 来控制编号 %c 和候选词 %@ 前后的空间。
corner_radius: 10 # 候选条圆角半径
border_height: 0 # 窗口边界高度,大于圆角半径才生效
@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 / 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)