Skip to content

Instantly share code, notes, and snippets.

@TorvaldsDB
TorvaldsDB / sample.js
Created November 10, 2019 07:07
JS how to return a sample of an array?
arr = [1, 2, 3, 4 , 5]
arr[Math.floor(Math.random() * arr.length)]
@TorvaldsDB
TorvaldsDB / alias_for_tmux_sessions.markdown
Created November 14, 2019 01:27
tmux alias config in .bashrc OR .bash_profile OR .zshrc to conveniently handle tmux sessions
  alias tnew='tmux new -s' # new a session
  alias tls='tmux ls'      # list all sessions
  alias topen='tmux a -t'  # open one of sessions with session number
  alias tlast='tmux a'     # resume last used session
  alias tkill='tmux kill-session -t' # kill one of sessions with session number
  alias tkillall='tmux kill-server'  # kill all sessions
@TorvaldsDB
TorvaldsDB / image_validate.rb
Last active November 26, 2019 09:30
How to validate whether an image url is valid or not
module ImgageValidate
module_function
def url_exist?(url)
uri = URI.parse(url)
Net::HTTP.start(uri.host, uri.port) do |http|
Net::HTTP.start(uri.host, uri.port) do |http|
response = http.head(uri.path)
case response
when Net::HTTPSuccess, Net::HTTPRedirection
@TorvaldsDB
TorvaldsDB / webpack.config.md
Last active June 28, 2021 05:42
Webpack Basic Configuration

Webpack

Webpack 配置文件放置在webpack.config.js中,

代码源码在 src/, 文件分布结构图(使用tree ./

├── src
│   ├── css
│   │   ├── iconfont.css
│ │ └── index.less
@TorvaldsDB
TorvaldsDB / NERDTree.mkd
Created February 19, 2022 14:59 — forked from m3nd3s/NERDTree.mkd
My Vim Cheat Sheet

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|

O.......Recursively open the selected directory..................|NERDTree-O|

/*
This hook allows reading and setting url query params.
Usage example:
const [query, setQuery] = useQueryParam({
name: 'q',
});
*/
import { useState, useEffect, useCallback } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
function debounce(func, delay) {
let timerId;
return function (...args) {
clearTimeout(timerId);
timerId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
function throttle(func, delay) {
let isThrottled = false;
return function (...args) {
if (!isThrottled) {
func.apply(this, args);
isThrottled = true;