Skip to content

Instantly share code, notes, and snippets.

View cppio's full-sized avatar

Parth Shastri cppio

View GitHub Profile
@cppio
cppio / CubicalPrim.agda
Created June 10, 2026 02:41
Expressing the side conditions for the cubical primitives using cubical subtypes.
{-# OPTIONS --safe --cubical #-}
module _ where
open import Agda.Primitive.Cubical renaming ( primIMin to _∧_
; primIMax to _∨_
; primINeg to ~_
)
open import Agda.Builtin.Cubical.Sub renaming (primSubOut to outS)
{-# OPTIONS --safe --cubical #-}
open import Agda.Builtin.Cubical.Path
module Homotopy {ℓ} {A : Set ℓ} {x y : A} (p q : x ≡ y) where
open import Agda.Primitive.Cubical renaming ( primIMin to _∧_
; primIMax to _∨_
; primINeg to ~_
; primHComp to hcomp
@cppio
cppio / Trans.agda
Created May 28, 2026 02:59
Transitity of identity (aka path composition)
{-# OPTIONS --safe --cubical #-}
open import Agda.Builtin.Cubical.Path
module Trans {ℓ} {A : Set ℓ} {x y z : A} (x≡y : x ≡ y) (y≡z : y ≡ z) where
open import Agda.Primitive.Cubical renaming ( primIMin to _∧_
; primIMax to _∨_
; primINeg to ~_
; primHComp to hcomp
import plistlib, pprint, sys, uuid
with open(sys.argv[1], "rb") as plist:
plist = plistlib.load(plist)
assert plist["$archiver"] == "NSKeyedArchiver"
objs = plist["$objects"]
def decode(val):
if isinstance(val, dict):
from PIL import Image
def trim(im):
data = list(im.getdata())
cs = set()
w, h = im.size
for x in range(w):
cs.add(data[x])
cs.add(data[(h - 1) * w + x])
for y in range(h):
import hashlib, sys, zipfile
with zipfile.ZipFile(sys.argv[1]) as zip:
for filename in sorted(zip.namelist()):
if filename.endswith("/"):
continue
with zip.open(filename) as file:
print(hashlib.file_digest(file, sys.argv[2]).hexdigest(), filename)
import struct, sys, zlib
PNG_HEADER = b"\x89PNG\r\n\x1a\n"
for path in sys.argv[1:]:
with open(path, "rb") as png:
png = png.read()
print(path + ":")
if not png.startswith(PNG_HEADER):
print("not a png")
@cppio
cppio / varnames.py
Last active October 15, 2025 05:20
import dis, sys
def varnames():
frame = sys._getframe(1)
instrs = dis.get_instructions(frame.f_code)
instr = next(instr for instr in instrs if instr.offset > frame.f_lasti)
match instr.opname:
case "STORE_FAST" | "STORE_GLOBAL" | "STORE_NAME":
return instr.argval
case "STORE_FAST_LOAD_FAST":
def sig(fn):
code = fn.__code__
defaults = fn.__defaults__
kwdefaults = fn.__kwdefaults__
if defaults is None:
defaults = ()
if kwdefaults is None:
kwdefaults = {}
pos, varnames = code.co_varnames[:code.co_argcount], code.co_varnames[code.co_argcount:]
@cppio
cppio / descr.py
Last active October 18, 2025 13:14
Python descriptors
import types
class StaticMethod:
def __init__(self, f):
self.f = f
def __get__(self, instance, owner):
return self.f
class ClassMethod: