Skip to content

Instantly share code, notes, and snippets.

View tzaffi's full-sized avatar
🐙
Octopii are cool

Zeph Grunschlag tzaffi

🐙
Octopii are cool
View GitHub Profile
@tzaffi
tzaffi / on_all_events.yml
Last active May 18, 2024 17:43
GIthub Actions Examples
name: Comprehensive Workflow Example
on:
# Push event - triggers on pushes to specified branches and paths
push:
branches:
- main
- zeph/testing
tags:
- v*
@tzaffi
tzaffi / immutable_consts.py
Last active April 29, 2024 02:27
How to create "immutable" constants in Python
class ContainerOfConstants(type):
def __new__(metacls, name, bases, namespace):
namespace["_const_values"] = frozenset(
value
for key, value in namespace.items()
if not key.startswith("_")
)
cls = super().__new__(metacls, name, bases, namespace)
cls._initializing = True
return cls
@tzaffi
tzaffi / indexer_txn.sql
Last active August 9, 2023 18:28
Performant stats for Indexer's `txn` table
-- 1. Approximate the indexer table row counts:
SELECT
psut.relname AS table_name,
pc.reltuples::BIGINT AS estimated_count,
pg_total_relation_size(psut.schemaname || '.' || psut.relname) AS estimated_size,
pg_size_pretty(pg_total_relation_size(psut.schemaname || '.' || psut.relname)) AS size_human
FROM
pg_stat_user_tables psut
INNER JOIN
pg_class pc
@tzaffi
tzaffi / .psqlrc
Created July 22, 2023 03:57
psql config
\set PROMPT1 '%M:%[%033[1;31m%]%>%[%033[0m%] %n@%/%R%#%x '
\pset null '[null]'
\set COMP_KEYWORD_CASE upper
\timing
\set HISTSIZE 2000
\x auto
@tzaffi
tzaffi / Makefile
Created May 25, 2023 19:00
Python Runner for `runner.go`
SCENARIO = test_config.yml
SKIP = --skip-runner
RESETDB = --reset-db
debug-blockgen:
python run_runner.py \
--conduit-binary ./conduit \
--scenario $(SCENARIO) \
--keep-alive $(SKIP) \
--test-duration 30s \
$(RESETDB)
# ... assume the various _VERSION_ vars are defined
export PATH=$(GOPATH)/bin:$(PATH)
go install golang.org/dl/go$(GOLANG_VERSION_BUILD)@latest
go$(GOLANG_VERSION_BUILD) download
go$(GOLANG_VERSION_BUILD) mod tidy -compat=$(GOLANG_VERSION_SUPPORT)
# So for example, the last three lines may be:
go install golang.org/dl/go1.17.13@latest
go1.17.13 download
@tzaffi
tzaffi / cross-repo-comparison.go
Last active April 13, 2023 21:02
Parse `go` AST and Compare Types without Reflection
package main
import (
"encoding/csv"
"fmt"
"go/ast"
"go/parser"
"go/token"
"log"
"os"
@tzaffi
tzaffi / Justfile
Last active August 2, 2023 19:23
Conduit Scripts
set export
set shell := ["zsh", "-cu"]
NETWORKS := `echo $HOME` + "/networks"
NAME := "conduitnetwork"
CURR_NETWORK := NETWORKS + "/" + NAME
GO_ALGORAND := "/Users/zeph/github/tzaffi/go-algorand"
NODE_TEMPLATE := GO_ALGORAND + "/test/testdata/nettemplates/TwoNodesFollower100Second.json"
PRIVATE_DATA_NODE := "Primary"
DATA_NODE := env_var_or_default("DATA_NODE", PRIVATE_DATA_NODE)
@tzaffi
tzaffi / Makefile
Created March 26, 2023 03:45
Static Call Graphs via `pycg`
# ❯ pip freeze | grep pycg
# pycg==0.0.6
clean:
rm reachable.json everything.json diff.json
reachable.json:
pycg --package algosdk tests/steps/account_v2_steps.py tests/steps/application_v2_steps.py tests/steps/other_v2_steps.py tests/steps/steps.py -o reachable.json
EVERYTHING := $(shell find algosdk -name "*.py")
@tzaffi
tzaffi / __init__.py
Last active January 21, 2023 11:09
python `setprofile(hook)` to count the number of times each function in the package was called
import atexit
from collections import Counter, defaultdict
import sys
CALLS = Counter() # defaultdict(int)
def hook(frame, event, arg):
if event != "call":