Skip to content

Instantly share code, notes, and snippets.

View numToStr's full-sized avatar
🍵
Just wandering around...

numToStr

🍵
Just wandering around...
View GitHub Profile
const fs = require("fs").promises;
const buff = Buffer.alloc(100);
const header = Buffer.from("mvhd");
async function length() {
const file = await fs.open("video.mp4", "r");
const { buffer } = await file.read(buff, 0, 100, 0);
await file.close();
const useDebounce = () => {
let timeout = useRef<NodeJS.Timeout | null>(null);
return useCallback(
(fn: Function, wait: number) => (e: FormEvent) => {
e.preventDefault();
timeout.current && clearTimeout(timeout.current);
timeout.current = setTimeout(() => {
fn();
# This tmux statusbar config was created by tmuxline.vim
# on Sun, 09 Feb 2020
set -g default-terminal "screen-256color"
set-option -ga terminal-overrides ",xterm-256color:Tc"
set -g status-justify "left"
set -g status "on"
set -g status-left-style "none"
set -g message-command-style "fg=#a89984,bg=#504945"
" For Plugins to work, copy this file into
" [For vim] --> ~/.vimrc
" [For neovim] --> ~/.config/nvim/init.vim
"
" Generating config with GUI
" https://vimconfig.com
" --- Required fonts ---
" powerline-fonts
" ttf-nerd-fonts-symbols
@numToStr
numToStr / .bashrc
Created January 3, 2020 15:57 — forked from avesus/.bashrc
Vim with NERDTree Adequate Defaults
# I love super fast keyboard. Most of my friends and colleagues can't follow
# I use `atkbd.softrepeat=1` on the kernel command line.
# Even Visual Assist plugin in Visual Studio doubles keyboard repeat rate with _a reason_.
# I'm working on my laptop without X installed to avoid procrastination.
# I've spend a working day googling how to make `kbdrate` using slower delay than 250.
# Add this to your /etc/profile.d/kbdrate.sh: sudo kbdrate -r 82 -d 150 if you want it in console.
# Note that it will force you type password twice. I didn't find any workarounds.
xset r rate 150 82
# When exiting from Vim, just type
@numToStr
numToStr / init.vim
Created January 1, 2020 11:42 — forked from benawad/init.vim
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree'
"Plug 'tsony-tsonev/nerdtree-git-plugin'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
@numToStr
numToStr / joi_objectId.js
Last active December 3, 2019 07:11
Mongodb/Mongoose ObjectId custom validation using @hapi/joi
const { Types } = require("mongoose");
const Joi = require("@hapi/joi");
// custom validator
const customJoi = Joi.extend(joi => ({
type: "objectId",
base: joi.string(),
messages: {
objectId: '"{{#label}}" must be a valid _id',
},
@numToStr
numToStr / error-handling.js
Created November 14, 2019 06:05
Node.js interruptions
const errorHandler = (error, event) => {
if (error) {
throw error;
}
throw new Error(`${event} caught`);
};
process.on("beforeExit", () => errorHandler(null, "beforeExit"));
@numToStr
numToStr / task.json
Created October 25, 2019 07:30
Sample vscode task for building and deploy docker images to elastic beanstalk
{
"version": "2.0.0",
"tasks": [
{
"label": "Build React",
"type": "shell",
"command": "npm run build",
"presentation": {
"showReuseMessage": false
}
@numToStr
numToStr / node-bin.js
Created July 23, 2019 07:14
Node server build with core http module
#!/usr/bin/env node
const http = require("http");
// Port Environment variable
const PORT = process.env.PORT || 5000;
// Creating the node server
const SERVER = http.createServer();