Skip to content

Instantly share code, notes, and snippets.


Mikko Ohtamaa miohtama

View GitHub Profile
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=* \
miohtama / gist:34a83d870a14aa7e580d
Last active Oct 31, 2021
Safe evaluation of math expressions in Python, using byte code verifier and eval()
View gist:34a83d870a14aa7e580d
The orignal author: Alexer /
import opcode
import dis
import sys
import multiprocessing
miohtama / gist:5216738
Created Mar 21, 2013
Enabling SSLCACertificateFile and SSLVerifyClient for one page only in Apache 2.2+
View gist:5216738
# Apache configuration for running local browser against a locally running xxxx for manual smartcard testing
# Listen 4433
# Real men use mod_proxy
DocumentRoot "/nowhere"
ServerName local-apache
miohtama /
Last active Oct 22, 2021
Transaction-aware Celery tasks for Pyramid - only run the task after the transaction has committed
"""Transaction-aware Celery task handling.
Core originally written for Warehouse project
from celery import Task
from pyramid import scripting
from pyramid.interfaces import IRequest
from pyramid.request import Request
miohtama /
Created Sep 17, 2015
Using Waitress web server to run functional py.test test suite for a WSGI app in Python
"""py.test fixtures for spinning up a WSGI server for functional test run."""
import threading
import time
from pyramid.router import Router
from waitress import serve
from urllib.parse import urlparse
import pytest
"""A stateful event scanner for Ethereum-based blockchains using
With the stateful mechanism, you can do one batch scan or incremental scans,
where events are added where the scanner left last time.
Copyright 2021 Mikko Ohtamaa,, licensed under MIT
import datetime
import time
miohtama / gist:5389146
Created Apr 15, 2013
Decoding emails in Python e.g. for GMail and imapclient lib
View gist:5389146
import email
def get_decoded_email_body(message_body):
""" Decode email body.
Detect character set if the header is not set.
We try to get text/plain, but if there is not one then fallback to text/html.
:param message_body: Raw 7-bit message body input e.g. from imaplib. Double encoded in quoted-printable and latin-1
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")
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(