Skip to content

Instantly share code, notes, and snippets.


Mikko Ohtamaa miohtama

View GitHub Profile
miohtama /
Created Jan 11, 2022
Bing IndexNow URL submitter for Python
"""Use IndexNow API to send the latest updates to Bing.
Ensures Bing picks up the pages that should be fresh and interesting.
Do not wait them picked up by the natural crawler process.
To submit the pages you need to have a Bing known file at the root of your website.
IndexNow will also submit the Yandex.
miohtama / find-long-queries.sql
Created Dec 2, 2021
PostgreSQL find long queries
View find-long-queries.sql
now() - pg_stat_activity.query_start AS duration,
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
miohtama /
Created Dec 2, 2021
Bash script for pgmetrics + pgdash reporting loop
# Monitor loop for TimescaleDB using pgdash
# - TimescaleDB runs in a Docker, exposed over TCP/IP socket
# - pgdash SaaS offering used
# - run the sample collection loop every 30 seconds
set -e
set -x
miohtama /
Last active Nov 6, 2021
Throttling background task queue using Dramatiq - wait until more workers are freed
import time
from typing import Dict, Optional
from dramatiq import Message, Broker
from dramatiq.results import ResultMissing
class TaskQueue:
"""A task queue using Dramatiq background task framework.
miohtama / bsh-notes.bash
Created Nov 4, 2021
Binance Smart Chain notes
View bsh-notes.bash
./geth_linux \
--config ./config.toml \
--datadir ./data/bsc \
--cache 8000 \
--rpc.allow-unprotected-txs \
--txlookuplimit 0 \
--http.port 9545 \
--http.addr \
--http.vhosts=* \
from erdpy.accounts import Account, Address
from erdpy.proxy import ElrondProxy
from erdpy.transactions import BunchOfTransactions
from erdpy.transactions import Transaction
from erdpy.wallet import signing
proxy = ElrondProxy("")
sender = Account(pem_file="test-wallet.pem")
View colormapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
pragma abicoder v2;
contract ArrayTest {
function colourToString(uint r, uint g, uint b) private pure returns(string memory) {
bytes memory alphabet = "0123456789abcdef";
miohtama /
Created Aug 19, 2021
Fast event fetcher and decoder for
"""Below is an example for faster JSON-RPC event fetcher.
It skips a lot of steps, like converting raw binary values to corresponding numbers (float, ints),
looking up ABI labels and building `AttributedDict` object.
The resulting Event dictitionary is generated faster, but harder to use and you need to know what you are doing.
def _fetch_events_for_all_contracts(
miohtama /
Created Jul 14, 2021
Writing Parquet files incrementally from Python
with pq.ParquetWriter(
version='2.0', # Highest available schema
data_page_version='2.0', # Highest available schema
) as writer:
def reset_data():
miohtama /
Created Jun 27, 2021
Ethereum address to for SQLAlchemy
class EthereumAddress(types.TypeDecorator):
"""SQLAlchemy class to store Ethereum addresses as binary in SQL database.
Ethereum address is 160 bits, the last bytes of 256 bit public key of the address's signer.
Ethereum address checksum is encoded in the case of hex letters.
We skip any Ethereum address checksum checks, as they slow down large data processing too much.
Any returned address data will be in lowercase.