Skip to content

Instantly share code, notes, and snippets.

View thautwarm's full-sized avatar
🧐

Taine Zhao thautwarm

🧐
View GitHub Profile
@thautwarm
thautwarm / cuc
Created February 10, 2023 05:52
switching git users with configuration files
#!/usr/bin/env python
from __future__ import annotations
from pathlib import Path
from colorama import Fore, Style
from shutil import make_archive, unpack_archive
from contextlib import contextmanager
import io
import hashlib
import sys
@thautwarm
thautwarm / NZLists.jl
Created January 4, 2023 01:17
Non-empty & persistent linked lists
struct NZList{T}
head::T
tail::Union{NZList{T},Nothing}
end
cons(x) = NZList(x, nothing)
cons(x::T, xs::Union{NZList{T},Nothing}) where {T} = NZList(x, xs)
function Base.iterate(xs::NZList)
xs.head, xs.tail
@thautwarm
thautwarm / requirement_sort.jl
Created July 1, 2022 10:25
requirement sort
const _default_lookup = UInt64[]
function sort_required_modules(requires::Vector{Pair{Base.PkgId, Base.PkgId}}, required_modules::Vector{Pair{Base.PkgId, UInt64}})
require_orders =
let require_orders = unique!(Base.PkgId[req.second for req in requires])
@view require_orders[1:end] # make 'require_orders' type-stable
end
require_lookup = Dict{Base.PkgId, Vector{UInt64}}()
for (req, build_id) in required_modules
@thautwarm
thautwarm / forward_def.jl
Created May 25, 2022 01:42
forward_def!
using MLStyle: @switch
macro forward_def!(self_ann, expr, methods...)
@switch self_ann begin
@case :($self :: $t_base{$(t_args...)})
@case :($self :: $t_base) && let t_args = [] end
end
t = if !isempty(t_args)
:($t_base{$(t_args...)})
else
t_base
const commandCreateFile = vscode.commands.registerCommand("extension.dired.createFile", async () => {
// list files of provider.dirname
const quickPick = vscode.window.createQuickPick();
quickPick.canSelectMany = false;
quickPick.placeholder = "Filename:";
let dirname = provider.dirname ?? path.normalize(".");
quickPick.items = [{ label: dirname }];
let fileName = quickPick.value;
let disposables: vscode.Disposable[] = [];
try {
@thautwarm
thautwarm / solve_dep.cs
Created March 29, 2022 02:06
dependency ordering
var x = new S("x");
var y = new S("y");
var z = new S("z");
var k = new S("k");
y.Dep(z);
var xs = new List<S> { k, y, x, z };
var ys = new List<S>(xs);
@thautwarm
thautwarm / .bash_colors.sh
Created February 15, 2022 10:36
bashcolors
function __ {
echo "$@"
}
function __make_ansi {
next=$1; shift
echo "\[\e[$(__$next $@)m\]"
}
function __make_echo {
@thautwarm
thautwarm / .bashrc
Last active July 5, 2022 15:19
msys2 on windows
export PYTHONIOENCODING=utf8
# PROMPT_COMMAND="prompt-command"
# cache init
source activate base
if [[ -z "$my_pragma_once" ]]; then
source ~/.bashfiles/color.sh # available at https://gist.github.com/thautwarm/d43e17a6c2e48ac7d420281779e9399b
source "$(scoop prefix git)\etc\profile.d\git-prompt.sh"
source /usr/share/bash-completion/bash_completion
export PATH=$HOME/scoop/shims:$PATH
from wisepy2 import wise
def main(filename: str):
"""return a pair:
- non-empty character count
- non-empty line count
"""
l = 0
c = 0
for line in open(filename, 'r', encoding='utf8'):
@thautwarm
thautwarm / datafile
Created October 10, 2021 11:03
map polygon example
[[293, 346], [293, 343], [288, 339], [276, 351], [293, 346]] (0, 20, 28)
[[353, 342], [347, 329], [346, 328], [341, 330], [339, 331], [344, 340], [353, 342]] (0, 20, 28)
[[354, 327], [350, 327], [347, 329], [353, 342], [354, 342], [359, 342], [359, 330], [354, 327]] (0, 20, 28)
[[381, 341], [366, 324], [364, 325], [360, 327], [359, 330], [359, 342], [365, 344], [381, 341]] (0, 20, 28)
[[381, 341], [385, 341], [371, 321], [370, 321], [367, 324], [366, 324], [381, 341]] (0, 20, 28)
[[405, 315], [400, 312], [392, 316], [388, 321], [392, 341], [411, 350], [405, 315]] (0, 20, 28)
[[313, 314], [316, 311], [312, 308], [308, 311], [309, 313], [310, 314], [313, 314]] (0, 20, 28)
[[320, 307], [314, 302], [312, 305], [312, 308], [316, 311], [317, 311], [320, 309], [320, 307]] (0, 20, 28)
[[312, 305], [308, 304], [304, 307], [304, 307], [305, 309], [308, 311], [312, 308], [312, 305]] (0, 20, 28)
[[395, 310], [394, 310], [392, 316], [400, 312], [399, 311], [395, 310]] (0, 20, 28)