Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Vftdan / bindump.sh
Created April 8, 2020 07:16
Like hexdump, but with base 2. Bit & byte order is little-endian.
#! /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 / wrap-lines.sh
Created July 17, 2020 14:52
Break each line that is longer than 80 characters with sed. One line can be broken more than once.
sed 's/.\{80\}/\0\n/g'
@Vftdan
Vftdan / aliases.vim
Created October 17, 2020 08:23
Aliases for vim command mode. (Function is not mine.)
" 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 / lambda.vim
Last active February 9, 2021 22:09
Lambda expression vim syntax
" 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 / gemini_protocol.vim
Last active February 9, 2021 22:50
Vim gemini:// protocol plugin
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 / catcolored.vim
Last active August 7, 2021 18:27
NeoVim script to pretty print the file to terminal
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 / alglib.py
Created September 3, 2021 14:42
Some algebraic types for making calculations
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 / minecraft-keycodes.tsv
Last active September 13, 2021 13:19
Minecraft old (1.12) & new (1.16) keycodes
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 / mcskin
Last active January 2, 2022 14:10
Scripts for fetching minecraft skins
#! /bin/bash
curl `mcskinurl $1` --create-dirs -o ~/mcskins/$1.png
@Vftdan
Vftdan / hide-nixbuild-accounts.sh
Created January 15, 2022 14:18
Hide nixbuild accounts from lighdm in Linux Mint / Ubuntu Bionic.
#! /bin/sh
for i in $(seq 32); do \
cat > /var/lib/AccountsService/users/nixbld"$i" <<EOF
[User]
SystemAccount=true
EOF
done