Skip to content

Instantly share code, notes, and snippets.

@karlb
karlb / send_fee_currency_tx.mjs
Last active January 9, 2024 12:39
Celo notes
import { createPublicClient, createWalletClient, http, defineChain } from 'viem'
import { celoAlfajores } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
const devChain = defineChain({
...celoAlfajores,
id: 1337,
name: 'local dev chain',
network: 'dev',
rpcUrls: {
@karlb
karlb / query_plan.py
Last active December 17, 2022 18:25
SQLite memo
import sqlite3
conn = sqlite3.connect(":memory:")
conn.row_factory = sqlite3.Row
def print_query_plan(query, bindings={}):
depth_of = {0: -1}
result = conn.execute("EXPLAIN QUERY PLAN " + query, bindings).fetchall()
for r in result:
depth = depth_of[r['parent']] + 1
@karlb
karlb / company_logo.sparql
Last active September 25, 2023 17:25
Wikidata queries
#defaultView:ImageGrid
SELECT DISTINCT *
WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:api "EntitySearch" .
bd:serviceParam wikibase:endpoint "www.wikidata.org" .
bd:serviceParam mwapi:search ?company_name .
bd:serviceParam mwapi:language "en" .
?comp wikibase:apiOutputItem mwapi:item .
?num wikibase:apiOrdinal true .
@karlb
karlb / cancel_pending.py
Created December 2, 2021 13:17
Cancel pending ethereum transactions
import eth_keyfile
from web3 import Account, Web3
from web3.middleware import geth_poa_middleware
w3 = Web3(Web3.HTTPProvider("http://geth.goerli.ethnodes.brainbot.com:8545"))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
addr = "8f5ea3bb3e99c317b8745918f6973f7afbf659c3"
first_stuck = 226164
stuck_nonces = range(first_stuck, first_stuck + 20)
gas_price = w3.toWei(10, "gwei")
@karlb
karlb / tei2html.py
Last active June 15, 2020 07:06
tei2html for pyglossary
#!/usr/bin/env python3
from typing import List, Union, Callable
from lxml import etree as ET
from io import BytesIO
tei = '{http://www.tei-c.org/ns/1.0}'
ns = {
None: 'http://www.tei-c.org/ns/1.0',
}
@karlb
karlb / Find table size.sql
Last active December 17, 2022 18:23
PostgreSQL memo
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size,
round(total_size / sum(total_size) OVER () * 100, 2) AS percent
FROM (
SELECT
table_name,
pg_table_size(table_name) AS table_size,