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 / .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
@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 / 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
module type TNT = sig
type 'a typed_name
val inj : string -> 'a typed_name
val prj : 'a typed_name -> string
end
module TN : TNT = struct
type 'a typed_name = string
let inj = fun x -> x
let prj = fun x -> x
@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);
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'):