Skip to content

Instantly share code, notes, and snippets.

View thautwarm's full-sized avatar
🧐

Taine Zhao thautwarm

🧐
View GitHub Profile
@thautwarm
thautwarm / cpointers.jl
Last active March 7, 2021 09:03
[julia] convenient interface for c-interops(zero-cost get element pointer/type-checked ccall, etc)
"""
modules that provides convenient pointer operations.
```julia
struct C
a :: Cint
end
struct A
a :: Cint
b :: Cdouble
@thautwarm
thautwarm / .bashrc.sh
Created February 13, 2021 07:04
bashrc
export PYTHONIOENCODING=utf8
PROMPT_COMMAND="prompt-command"
# cache init
source activate base
if [[ -z "$my_pragma_once" ]]; then
export PATH="$HOME/.local/bin:$PATH"
source ~/.bashfiles/color.sh
source "$(scoop prefix git)\etc\profile.d\git-prompt.sh"
source /usr/share/bash-completion/bash_completion
Weekly development breakdown
@thautwarm
thautwarm / dataframe-column-trans.ml
Created September 16, 2020 21:07
a use case of higher rank types. not about monad
type _ df =
| EmptyDF : unit df
| JoinDF : 'a array * 'b df -> ('a * 'b) df
type (_, _) index =
| TOS : ('e * 'o, 'e) index
| NEXT : ('o, 'e) index -> ('tos * 'o, 'e) index
let rec get : type a e. (a, e) index -> a df -> e array =
fun ind df ->
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
using MLStyle
import Base
@data Nat begin
Z()
S{N <: Nat} :: () => Nat
end
StoInt(s::Type{Z}) = 0
StoInt(s::Type{S{N}}) where N = StoInt(N) + 1
using MLStyle
using Libdl
struct DLL
path :: String
handle::Ptr{Nothing}
end
function DLL(path::String)
handle = dlopen_e(path)
@thautwarm
thautwarm / a.py
Created June 24, 2020 18:46
codegen-moshmosh
_isinstance = isinstance
def test_mm(data):
isinstance = _isinstance
# +pattern-matching
for d in data:
with match(d):
if [a, isinstance(str) and b, c]:
"%s(%s)%s" % (a, b, c)
if (isinstance(str) and s, isinstance(int) and i):
s * i
@thautwarm
thautwarm / string_process.jl
Created May 10, 2020 15:34
time efficient julia string
struct AString
buf::Vector{Char}
end
function convert(::Type{AString}, str::String)
n = ncodeunits(str)
buf = Char[]
i = 1
while i <= n
chr = str[i]::Char
@thautwarm
thautwarm / type_sort1.jl
Created April 1, 2020 10:33
use for static julia type utils
function sort_type(ts :: Vector{Type})
n = length(ts)
if n == 1
ts
elseif n == 2
a, b = ts[1], ts[2]
if a <: b
[a, b]
elseif b <: a
[b, a]