Skip to content

Instantly share code, notes, and snippets.

@nuffin
nuffin / delete-unused-buffers.vim
Last active November 30, 2024 08:08
DeleteAllBuffersExceptCurrent() and key bindings for VIM9.1
" Check if the function is already defined, then delete it before redefining it
if exists('*DeleteAllBuffersExceptCurrent')
delfunction DeleteAllBuffersExceptCurrent
endif
" Define a function in Vim 9.1 to delete all buffers except the current one
def DeleteAllBuffersExceptCurrent(check_empty: bool)
var current_buffer = bufnr('%')
for buffer in getbufinfo()
# echomsg buffer
if buffer.bufnr != current_buffer && buffer.listed && !buffer.changed && (!check_empty || (empty(buffer.windows) && empty(buffer.popups)))
@nuffin
nuffin / git-alias.gitconfig
Last active December 18, 2024 04:34
git alias
[alias]
adog = log --all --decorate --oneline --graph
adogf = log --all --decorate --oneline --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
## fetch origin main and merge into local main
fmain = "!f() { git fetch --all --prune && git fetch . origin/main:main; }; f"
ff = "!f() { branch=${1:-main}; git fetch --all --prune && git fetch . origin/$branch:$branch; }; f"
## rebase main with stash
rbmain = "!f() { git stash && git rebase main && git stash pop; }; f"
rb = "!f() { branch=${1:-main}; git stash && git rebase $branch && git stash pop; }; f"
## pull with stash
@nuffin
nuffin / vim-key-bindings-for-grep-with-fzf-plugin.vim
Created October 25, 2024 14:58
VIM: grep in a popup and select for open, with fzf plugin
" the key bindings are just as examples, for personal prefer
let fzf_installed = 0
call plug#begin('~/.vim/plugged')
" NOTICE: you should add this part into your plugin#begin() .. plug#end() block
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
@nuffin
nuffin / vim-floaterm-key-bindings.vim
Last active October 20, 2024 17:22
key bindings for vim plugin "voldikss/vim-floaterm"
call plug#begin('~/.vim/plugged')
Plug 'voldikss/vim-floaterm'
nnoremap <silent> <C-T>c :FloatermNew<CR>
tnoremap <silent> <C-T>c <C-\><C-n>:FloatermNew<CR>
inoremap <silent> <C-T>c <Esc>:FloatermNew<CR>
nnoremap <silent> <C-T>p :FloatermPrev<CR>
tnoremap <silent> <C-T>p <C-\><C-n>:FloatermPrev<CR>
inoremap <silent> <C-T>p <Esc>:FloatermPrev<CR>
nnoremap <silent> <C-T><C-P> :FloatermPrev<CR>
tnoremap <silent> <C-T><C-P> <C-\><C-n>:FloatermPrev<CR>
@nuffin
nuffin / clonegit.ps1
Created June 1, 2024 14:16
clonegit command for PowerShell, to clone git repositories in a structured directory
`@
Usage:
Clone-Git git-repo-url
Clone-Git -SshKeyFilePath C:\path\to\private-ssh-key git-repo-url
to clone the repository with a specified ssh key
add this function to $PROFILE file, and then re-open PowerShell to use it.
@`
function Clone-Git
@nuffin
nuffin / clonegit.sh
Created June 1, 2024 14:11
clonegit command, to clone git repositories in a structured directory
# Usage:
# clonegit git-repo-url
# clonegit -c git-repo-url
# to clone and change into the cloned directory
# clonegit -k /path/to/private-ssh-key git-repo-url
# to clone the repository with a specified ssh key
#
# tested in bash and zsh, in Linux and macOS
@nuffin
nuffin / GitCommitEmoji.md
Created May 11, 2024 01:41 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@nuffin
nuffin / .config
Created April 23, 2024 15:50 — forked from jbeard4/.config
Setup jslinux
#
# Automatically generated file; DO NOT EDIT.
# Buildroot 2017.02 Configuration
#
BR2_HAVE_DOT_CONFIG=y
BR2_HOST_GCC_AT_LEAST_4_5=y
BR2_HOST_GCC_AT_LEAST_4_6=y
BR2_HOST_GCC_AT_LEAST_4_7=y
BR2_HOST_GCC_AT_LEAST_4_8=y
BR2_HOST_GCC_AT_LEAST_4_9=y
@nuffin
nuffin / md5.ts
Created February 20, 2024 00:57 — forked from basarat/md5.ts
Create md5 using TypeScript / JavaScript / NodeJS
import * as crypto from 'crypto';
export const md5 = (contents: string) => crypto.createHash('md5').update(contents).digest("hex");
@nuffin
nuffin / build-centos7-docker-image.sh
Created April 25, 2021 06:26 — forked from keithchambers/build-centos7-docker-image.sh
Build a CentOS 7 docker image.
#!/bin/bash -e
DIST="centos7"
TAG="$(date +%Y%m%d)"
IMG_DIR="${PWD}/buildroot-${DIST}"
REPO_DIR="${IMG_DIR}/etc/yum.repos.d"
RPMS=(
bind-utils
bash