
Last active
November 10, 2025 01:37
-
-
Save timm/a3fb877e33079680322315d4b39a8bdd to your computer and use it in GitHub Desktop.
Rep grid : represent and cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Copyright (c) 2025 Tim Menzies, MIT License | |
| # https://opensource.org/licenses/MIT | |
| export BASH_SILENCE_DEPRECATION_WARNING=1 | |
| export PATH="$Here:$PATH" | |
| export HISTSIZE=10000 | |
| export HISTFILESIZE=20000 | |
| export HISTCONTROL=ignoredups:erasedups | |
| Here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| branch() { git branch 2>/dev/null | awk '/^\*/ {print $2}'; } | |
| dirty() { [[ -n $(git status -s 2>/dev/null) ]] && echo "*"; } | |
| bold=$(tput bold) col0=$(tput sgr0) col1=$(tput setaf 6) col2=$(tput setaf 3) | |
| PROMPT_COMMAND='PS1="${bold}${col1}$(basename "$(dirname "$PWD")")/$(basename "$PWD")${col0} ${col2}$(branch)$(dirty)${col0} ▶ "' | |
| alias ls="\ls --color" | |
| alias reload="source '$Here/ell' && echo ✅" | |
| alias grep='grep --color=auto' | |
| vi() { | |
| nvim --clean \ | |
| --cmd "let g:netrw_banner=0 | let g:netrw_liststyle=3 | let g:netrw_browse_split=4 | let g:netrw_winsize=15" \ | |
| --cmd "set number relativenumber cursorline mouse=a clipboard=unnamedplus ignorecase smartcase" \ | |
| --cmd "set statusline=%#StatusLine#\ ▶\ %f\ %m%r%=%y\ ❖\ %l:%c\ ❖\ %p%%\ " \ | |
| --cmd "set expandtab tabstop=2 shiftwidth=2 splitright splitbelow" \ | |
| --cmd "set undofile undodir=~/.vim/undo" \ | |
| --cmd "nnoremap Q :quitall<CR>" \ | |
| --cmd "colorscheme zaibatsu" \ | |
| --cmd "set laststatus=2" \ | |
| "$@" | |
| } | |
| hi() { | |
| clear | |
| echo "${col1}" | |
| cat<<'EOF' | |
| ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ██╗ ██████╗ | |
| ██╔══██╗ ██╔════╝ ██╔══██╗ ██╔════╝ ██╔══██╗ ██║ ██╔══██╗ | |
| ██████╔╝ █████╗ ██████╔╝ ██║ ███╗ ██████╔╝ ██║ ██║ ██║ | |
| ██╔══██╗ ██╔══╝ ██╔═══╝ ██║ ██║ ██╔══██╗ ██║ ██║ ██║ | |
| ██║ ██║ ███████╗ ██║ ╚██████╔╝ ██║ ██║ ██║ ██████╔╝ | |
| ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ | |
| (cause experts know stuff} | |
| EOF | |
| echo "${col0}" | |
| } | |
| inst() { | |
| local m="" | |
| for p in $1; do command -v "$p" &>/dev/null || m+="$p "; done | |
| [ "$m" ] && case "$(uname -s)" in | |
| Darwin*) brew install $m ;; | |
| Linux*) sudo apt install -y $m ;; | |
| MINGW*) winget install $m ;; | |
| esac | |
| } | |
| # only run slow or verbose command at initial startup, not on reload | |
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | |
| inst git nvim gawk tree | |
| hi | |
| exec bash --init-file "${BASH_SOURCE[0]}" -i | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # vim: ts=2 sw=2 noet | |
| # Copyright (c) 2025 Tim Menzies, MIT License | |
| # https://opensource.org/licenses/MIT | |
| #------------------------------------------------------ | |
| SHELL=/bin/bash | |
| export PATH := $(CURDIR):$(PATH) | |
| .SILENT: | |
| .PHONY: help egs ok eg-nbc eg-abcd eg-soybean eg-globals pull push | |
| help: ## show this help | |
| @gawk 'BEGIN { FS=":.*?## ";c="\033[1;3"; r="\033[0m"; \ | |
| printf "\n%s6mmake%s [%s3moptions%s]:\n\n",c,r,c,r} \ | |
| NF==2 && $$1~/^[a-z0-9A-Z_-]+/{ \ | |
| printf " %s2m%-15s%s %s\n",c,$$1,r,$$2}' $(MAKEFILE_LIST) | |
| #------------------------------------------------------ | |
| sh: ## run a customized shell | |
| sh ell | |
| pull: ## update from main | |
| git pull | |
| push: ## commit to main | |
| git commit -am saving; git push; git status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import random,sys,re | |
| class o(dict): __getattr__=dict.__getitem__; __setattr__=dict.__setitem__ | |
| the = o(p=2, hi=10, file="qmatric.csv", seed=1234567891) | |
| def load(src): | |
| egs,rows = [],[] | |
| for row in src: | |
| if egs: rows += [o(dim=row[0], cells=row[1:])] | |
| else : egs = row[1:] | |
| return o(rows=rows, egs=egs) | |
| def dist(row1,row2): | |
| n,d = 0,0 | |
| for x,y in zip(row1.cells,row2.cells): n,d = n+1, (x-y)**2 | |
| return (d/n)**.5 | |
| def z(x): print(x); return x | |
| def far(rows): | |
| print(rows) | |
| return max((z(dist(row1,row2)),row1,row2) | |
| for i,row1 in enumerate(rows) | |
| for j,row2 in enumerate(rows) if j>i)[1:] | |
| def halve(rows): | |
| a,b = far(rows) | |
| c = dist(a,b) | |
| x = lambda r: (dist(r,a)**2 + c**2 - dist(r,b)**2) / (2*c + 1e-32) | |
| rows = sorted(rows, key=x) | |
| mid = len(rows)//2 | |
| return rows[:mid], rows[mid:] | |
| def tree(rows): | |
| kids = [] | |
| if len(rows) > 2: | |
| l,r = halve(rows) | |
| kids = [tree(l), tree(r)] | |
| return o(rows=rows, kids=kids) | |
| def show(t,lvl=0): | |
| print(("|.."*lvl) + f"{len(t.rows)}") | |
| [show(u, lvl+1) for u in t.kids] | |
| if not t.kids: | |
| print(("|.."*lvl) + f"{len(t.rows)}") | |
| #------------------------------------------------------------------------------- | |
| def coerce(x): | |
| for f in (int,float): | |
| try: return f(x) | |
| except: pass | |
| return x | |
| def csv(path): | |
| with open(path, encoding="utf-8") as f: | |
| for s in f: | |
| if (s := re.sub(r"\s+|#.*", "", s)): | |
| yield [coerce(s1) for s1 in s.split(",")] | |
| def eg__the(_): print(the) | |
| def eg__seed(s): the.seed=coerce(s); random.seed(the.seed) | |
| random.seed(the.seed) | |
| if __name__ == "__main__": | |
| for i,s in enumerate(sys.argv): | |
| if "eg__"+s[1:] in vars(): | |
| vars()["eg__"+s[1:]]( sys.argv[i+1] if i>len(sys.argv) else None ) | |
| show(tree(load(csv(the.file)).rows)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
