Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Vftdan / minecraft-keycodes.tsv
Last active Sep 13, 2021
Minecraft old (1.12) & new (1.16) keycodes
View minecraft-keycodes.tsv
Key Old Code New Code
BUTTON0 -100 key.mouse.left
BUTTON1 -99 key.mouse.right
BUTTON2 -98 key.mouse.middle
BUTTON3 -97 key.mouse.4
BUTTON4 -96 key.mouse.5
BUTTON5 -95 key.mouse.6
BUTTON6 -94 key.mouse.7
BUTTON7 -93 key.mouse.8
NONE 0 key.keyboard.unknown
@Vftdan
Vftdan / alglib.py
Created Sep 3, 2021
Some algebraic types for making calculations
View alglib.py
from fractions import Fraction, gcd
from itertools import product as cartprod
def memo(f):
cache = {}
def g(*argv, **kwargs):
args = (argv, tuple(sorted(kwargs.items())))
if args in cache:
#print("Using {0} |-> {1}".format(args, cache[args]))
return cache[args]
else:
@Vftdan
Vftdan / catcolored.vim
Last active Aug 7, 2021
NeoVim script to pretty print the file to terminal
View catcolored.vim
function! s:color_to_ansi(cstr, is_bg)
let l:car=a:is_bg ? 40 : 30
let l:cdr=[]
if a:cstr[0] == '#'
let l:car+=8
let l:cdr=[2] + map(split(a:cstr[1:], '\v..\zs'), 'str2nr(v:val, 16)')
elseif a:cstr > 15
let l:car+=8
let l:cdr=[5, a:cstr]
else
@Vftdan
Vftdan / gemini_protocol.vim
Last active Feb 9, 2021
Vim gemini:// protocol plugin
View gemini_protocol.vim
function! s:read_gemini(url)
call s:init_go_url()
function! s:init_go_url()
endfunction
let l:svpos = winsaveview()
setlocal bl ro noswapfile
if &ft == ''
setlocal ft=gmi
else
let &ft=&ft
@Vftdan
Vftdan / lambda.vim
Last active Feb 9, 2021
Lambda expression vim syntax
View lambda.vim
" Vim syntax file
if !exists("main_syntax")
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'lambda'
endif
@Vftdan
Vftdan / aliases.vim
Created Oct 17, 2020
Aliases for vim command mode. (Function is not mine.)
View aliases.vim
" Command mode aliases
function! SetupCommandAlias(from, to)
exec 'cnoreabbrev <expr> ' . a:from
\ . ' ((getcmdtype() is# ":" && getcmdline() is# "' . a:from . '")'
\ . '? ("' . a:to . '") : ("' . a:from . '"))'
endfunction
command! -nargs=* Calias call SetupCommandAlias([<f-args>][0], join([<f-args>][1:]))
Calias calias Calias
Calias nvim visual
Calias W! w!
@Vftdan
Vftdan / wrap-lines.sh
Created Jul 17, 2020
Break each line that is longer than 80 characters with sed. One line can be broken more than once.
View wrap-lines.sh
sed 's/.\{80\}/\0\n/g'
@Vftdan
Vftdan / bindump.sh
Created Apr 8, 2020
Like hexdump, but with base 2. Bit & byte order is little-endian.
View bindump.sh
#! /bin/sh
for i in $( (echo 'ibase=16;obase=2;'; hexdump -v -e '/1 "%02X\n"' $@) | bc); do \
printf '%08i\n' $i | rev
done
@Vftdan
Vftdan / bspwm-unminimize-event.sh
Last active Mar 1, 2020
Minimize windows while using bspwm
View bspwm-unminimize-event.sh
#! /bin/sh
xev -root | grep '(_NET_ACTIVE_WINDOW)' -B 1 --line-buffered | \
grep '^ClientMessage' --line-buffered | sed -u -e 's/^.*window //; s/,//' | \
while read w; do \
if [ -n "$(bspc query -N -n $w.hidden)" ]; then \
bspc node "$w" -g hidden=off
bspc node $w.fullscreen -t tiled
bspc node $w -l normal
bspc node -a $w
fi
@Vftdan
Vftdan / pal2gpl.py
Created Aug 9, 2019
Convert pal to gpl palette
View pal2gpl.py
#! /usr/bin/env python3
input() #header
input() #version
cnt = int(input()) #number of colors
print("GIMP Palette")
print("Columns: {0}".format(cnt))
print("#")
for i in range(cnt):
print("{0} {1} {2}\tUntitled".format(*(input().split())) + str(i + 1))