Skip to content

Instantly share code, notes, and snippets.

View ZacharyThompson's full-sized avatar

Zachary Thompson ZacharyThompson

  • Santa Maria, CA, USA
View GitHub Profile
@ZacharyThompson
ZacharyThompson / BigAllocation.c
Last active September 24, 2025 17:02
Example of reserving a very large amount of virtual address space in linux. You may want to do this when, for example, implementing an arena allocator in order to easily extend the capacity. As long as you don't reserve anything near 256 TiB (on a 64 bit system) there should be little downside afaik.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/mman.h>
#include <string.h>
#define KIBI(x) (1024LL*(x))
#define MEBI(x) (1024LL*1024LL*(x))
#define GIBI(x) (1024LL*1024LL*1024LL*(x))
@ZacharyThompson
ZacharyThompson / flactoalac.sh
Created October 2, 2024 21:25
Convert flac to alac (for apple music upload)
#!/bin/sh
mkdir -p "./output"
for x in *.flac
do
ffmpeg -i "$x" -c:v copy -c:a alac "./output/$(basename -- "$x" .flac).m4a"
done
@ZacharyThompson
ZacharyThompson / highlight.txt
Created August 27, 2024 23:16
zsh highlight
To activate the syntax highlighting, add the following at the end of your .zshrc:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
If you receive "highlighters directory not found" error message,
you may need to add the following to your .zshenv:
export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters
@ZacharyThompson
ZacharyThompson / updatenvim.sh
Created January 19, 2024 23:42
Auto update neovim from source
#!/bin/sh
git clone https://github.com/neovim/neovim.git
cd ./neovim
git checkout stable
make CMAKE_BUILD_TYPE=RelWithDebInfo
sudo make install
cd ..
rm -rf ./neovim
@ZacharyThompson
ZacharyThompson / test.zsh
Created August 28, 2023 21:05
Test coinflip
#!/bin/zsh
alias coinflip='echo "H\nT" | shuf -n 1'
list=()
repeat 1000 do
list+=$(coinflip)
# list+=$(python3 -c "import random; x=random.randint(0,1); print('H') if x==0 else print('T')")
done
typeset -A freq
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'numToStr/Comment.nvim'
// Zachary Thompson
// Idea from "The Algorithm Design Manual" by Skiena page 179
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define N 100000000
int main() {
format = '$directory$character'
right_format = '$package$git_branch$git_status'
add_newline = false
[directory]
truncation_length=0
truncate_to_repo=false
style='bold blue'
read_only=''
read_only_style='bold red'
# Based on https://github.com/morhetz/gruvbox by morhetz <morhetz@gmail.com>
# Adapted to kitty by wdomitrz <witekdomitrz@gmail.com>
cursor #928374
cursor_text_color background
url_color #83a598
visual_bell_color #8ec07c
bell_border_color #8ec07c
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_STATE_HOME="$HOME/.local/state"
export GRADLE_USER_HOME="$XDG_DATA_HOME/gradle"
export NODE_REPL_HISTORY="$XDG_DATA_HOME/node_repl_history"
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc"
export NVM_DIR="$XDG_DATA_HOME/nvm"
export TLDR_CACHE_DIR="$XDG_CACHE_HOME/tldrc"