Skip to content

Instantly share code, notes, and snippets.

@Tantalus13A98B5F
Tantalus13A98B5F / stlc.dfy
Last active May 18, 2024 17:29
A taste of logical relations using Dafny
datatype ty =
| TBool
| TFun (t1: ty, t2: ty)
type id = nat
datatype tm =
| ttrue
| tfalse
| tvar (n: id)
@Tantalus13A98B5F
Tantalus13A98B5F / tagless-exp.scala
Last active March 11, 2024 21:37
tagless final solution to the expression problem?
trait Literal[T, R]:
def apply(v: T): R
trait Addition[R]:
def apply(a: R, b: R): R
def getAst[R](using lit: Literal[Int, R], add: Addition[R]) =
add(add(lit(1), lit(2)), add(lit(3), lit(4)))
//-------------------------------------------------------
@Tantalus13A98B5F
Tantalus13A98B5F / progfix.v
Last active February 15, 2024 18:13
Examples of general recursion in Coq
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Program.Tactics.
Require Import Coq.Program.Wf.
Require Import Lia.
Import PeanoNat.Nat.
Fixpoint lexical (a: nat) :=
fix lexical' (b: nat) :=
match b with
| 0 => match a with
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import requests
from bs4 import BeautifulSoup
import pandas as pd
from pathlib import Path
@Tantalus13A98B5F
Tantalus13A98B5F / withsave_magic.py
Created April 14, 2021 14:32
IPython magic for save & run a cell (optionally in a subprocess)
from IPython.core.magic import register_cell_magic
import subprocess
import argparse
import sys
import os
@register_cell_magic
def withsave(line, cell):
parser = argparse.ArgumentParser()
parser.add_argument('fname')
@Tantalus13A98B5F
Tantalus13A98B5F / logmata.py
Last active March 3, 2021 10:44
A utility for parsing structured logs (NDPDA)
#!/usr/bin/env python3
'''Parse logs in structures with the help of a pushdown automata.
Grammar for the sample log file:
>This line is used for exact match.
$This line is used for regexp match.
This line is ignored.
The following lines marked a repeated region.
!repeat
@Tantalus13A98B5F
Tantalus13A98B5F / fzf-pipe
Created April 15, 2020 16:19
fzf-pipe: `fzf` wrapper for Git Bash
#!/usr/bin/env bash
TEMPDIR=$(mktemp -d)
cat >$TEMPDIR/input.txt
FZFOPTS="$(echo "$FZF_DEFAULT_OPTS" | sed 's/--height\s*\S*\s*//')"
for arg; do
FZFARGS="$FZFARGS \"$arg\""
done
cat >$TEMPDIR/script.sh <<EOF
@Tantalus13A98B5F
Tantalus13A98B5F / get_folder_size.py
Last active August 14, 2020 06:14
A simple GUI tool to inspect disk usage.
from tkinter.filedialog import askdirectory
from tkinter import *
from tkinter.ttk import *
import subprocess
import weakref
import sys
import os
def human_size(cntbytes):
@Tantalus13A98B5F
Tantalus13A98B5F / memview.py
Created January 6, 2020 04:33
A simple script to visualize the memory usage on Windows by accumulation.
import subprocess as subp
import pandas as pd
from matplotlib import pyplot as plt
p = subp.Popen(['tasklist', '/fo', 'csv'], stdout=subp.PIPE)
df = pd.read_csv(p.stdout, encoding='gbk')
df['mem'] = df['内存使用 '].transform(lambda x: int(x[:-2].replace(',', '')))
df['proc'] = df['映像名称']
df = df.groupby('proc')['mem'] \
.agg(['sum', 'count']) \
@Tantalus13A98B5F
Tantalus13A98B5F / parsepdf.py
Last active January 13, 2020 10:08
Simple PDF parser
'''My Simple PDF Parser
Can inspect the size of a PDF file.
'''
from contextlib import suppress, redirect_stdout
from collections import deque, OrderedDict
from weakref import ref
import re
class PDFRef: