Skip to content

Instantly share code, notes, and snippets.

👘
もんだいない

Taine Zhao thautwarm

👘
もんだいない
View GitHub Profile
@thautwarm
thautwarm / a.py
Created Jun 24, 2020
codegen-moshmosh
View a.py
_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
time efficient julia string
View string_process.jl
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 Apr 1, 2020
use for static julia type utils
View type_sort1.jl
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]
View alloc.asm
.word 0x10000002 ; MERL cookie
.word 0x00000760 ; File Length (in bytes) is 1888
.word 0x00000640 ; Code Length (in bytes) is 1600
init:
sw $1, -4($30)
sw $2, -8($30)
sw $3, -12($30)
sw $4, -16($30)
sw $5, -20($30)
sw $6, -24($30)
View print.asm
.word 0x10000002 ; MERL cookie
.word 0x0000010c ; File Length (in bytes) is 268
.word 0x000000ec ; Code Length (in bytes) is 236
print:
sw $1, -4($30)
sw $2, -8($30)
sw $3, -12($30)
sw $4, -16($30)
sw $5, -20($30)
sw $6, -24($30)
View moshmosh-for-ipython.sh
ipython profile create && \
pip install -U moshmosh-base -i https://pypi.org/simple --no-compile &&\
wget https://raw.githubusercontent.com/thautwarm/moshmosh/master/moshmosh_ipy.py &&\
mv moshmosh_ipy.py /home/$USER/.ipython/profile_default/startup/moshmosh_ipy.py
@thautwarm
thautwarm / HKT.hs
Created Jul 24, 2019
HKTs via type classes
View HKT.hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
import Unsafe.Coerce
import Prelude hiding ((>>=))
data App a b
class TypeApp cons k0 k1 | k1 -> cons k0, cons k0 -> k1 where
inj :: k1 -> App cons k0
@thautwarm
thautwarm / hkt.ts
Created Dec 12, 2018
higher kinded types implementation
View hkt.ts
interface HKT<K, T>{
}
interface Monad<M> {
bind: <A, B>(m: HKT<M, A>, k: (a: A) => HKT<M, B>) => HKT<M, B>
return: <A>(a: A) => HKT<M, A>
// ret$: <A>(m: (a: A) => HKT<M, A>) => HKT<M, A>
}
class Maybe implements Monad<Maybe> {
@thautwarm
thautwarm / test.fs
Last active Nov 17, 2018
compelling variable sized struct in LLVM IR
View test.fs
[<Fact>]
let ``nested push32`` () =
let var = ref None
let var2 = ref None
let var3 = ref None
let arg1 = ref <| Some "arg1"
let arg2 = ref <| Some "arg2"
let type_here = Push32 <| I 32
View macro_esc_failed.md

no macro leads to success:

struct A end
struct B end
function f()
enum1 = A()
enum2 = B()
begin
    let enum_test = enum1
        begin
You can’t perform that action at this time.