Skip to content

Instantly share code, notes, and snippets.

@numToStr
numToStr / au.lua
Last active Oct 17, 2021
Neovim autocmd in lua
View au.lua
--
-- Move this file to your neovim lua runtime path ie. ~/.config/nvim/lua/au.lua
--
local cmd = vim.api.nvim_command
local function autocmd(this, event, spec)
local is_table = type(spec) == 'table'
local pattern = is_table and spec[1] or '*'
local action = is_table and spec[2] or spec
if type(action) == 'function' then
View pseudo-text-objects.vim
" 24 simple pseudo-text objects
" -----------------------------
" i_ i. i: i, i; i| i/ i\ i* i+ i- i#
" a_ a. a: a, a; a| a/ a\ a* a+ a- a#
for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' ]
execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
endfor
View tmux.plugin.zsh
if ! (( $+commands[tmux] )); then
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2
return 1
fi
# ALIASES
alias ta='tmux attach -t'
alias tad='tmux attach -d -t'
alias ts='tmux new-session -s'
View fterm.lua
local api = vim.api
local cmd = vim.cmd
local fn = vim.fn
local W = {}
local base_opt = {
relative = 'editor',
style = 'minimal'
}
View .zshrc.zinit
#!/bin/zsh
### Added by Zinit's installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma/zinit%F{220})…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
View .zshrc
# Source manjaro-zsh-configuration
#if [[ -e /usr/share/zsh/manjaro-zsh-config ]]; then
# source /usr/share/zsh/manjaro-zsh-config
#fi
# Use manjaro zsh prompt
#if [[ -e /usr/share/zsh/manjaro-zsh-prompt ]]; then
# source /usr/share/zsh/manjaro-zsh-prompt
#fi
[[ -d ~/.zplug ]] || {
View cool_terminal_apps.md
View whats_my_ip.sh
#!/bin/bash
set -e
# IP Address Utilities
function ipInternal() {
# echo "Ethernet :: IP => $( ip -4 -o a show wlan1 | awk '{ print $4 }' )"
echo "Wireless :: IP => $( ip -4 -o a show wlo1 | awk '{ print $4 }' )"
}
function ipExternal() {
View getVideoDuration.js
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();
View useDebounce.ts
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();