Skip to content

Instantly share code, notes, and snippets.

View koirikivi's full-sized avatar

Rainer Koirikivi koirikivi

View GitHub Profile
@koirikivi
koirikivi / closest_block.py
Created March 1, 2022 15:35
Get block that's closest to timestamp with web3.py (Ethereum)
from datetime import datetime
from web3 import Web3
from web3.types import BlockData
import logging
logger = logging.getLogger(__name__)
@koirikivi
koirikivi / check_log_inconsistencies.py
Last active August 18, 2021 09:47
Check inconsistencies between eth_getLogs and eth_getTransactionReceipt
#!/usr/bin/env python3
"""
Check for inconsistencies in logs returned by eth_getLogs and eth_getTransactionReceipt
- Check that the `data` field is the same for logs with same transactionHash and logIndex,
between JSONRPC responses from eth_getLogs and eth_getTransactionReceipt
- Check that the logs from eth_getLogs are also found from eth_getTransactionReceipt
- Check that the logs from eth_getTransactionReceipt are also found from eth_getLogs
- Check that logs from eth_getLogs are not from failed transactions
@koirikivi
koirikivi / bench_cached_property_decorator.py
Last active September 20, 2023 15:51 — forked from smithdc1/bench_cached_property_decorator.py
Benchmark of Django and Python's cached_property decorators (with IO and multithreading)
import pyperf
import time
from concurrent.futures import ThreadPoolExecutor
from django.utils.functional import cached_property as dj_cached_property
from functools import cached_property as py_cached_property
# Most web requests have some IO, like database access. Simulate with sleeping
SLEEP_TIME = 0.01
@koirikivi
koirikivi / replace_closure_variables.py
Created April 15, 2020 10:59
Replace closure variables in Python (stupid)
def foo():
x = 42
def f():
return x
return f
f = foo()
f() # 42
def replace_closure_variables(func, **kwargs):
@koirikivi
koirikivi / codify.py
Last active February 24, 2020 12:10
Copy selection as un-indented code block (for Slack, Telegram, etc)
#!/usr/bin/env python3
"""
Turn input into something that's easy to paste to telegram/slack/other channels
as a code block
Usage:
$ cat foo | codify.py | xclip -selection clipboard
Vim shortcut to copy visual selection on <leader>c (add to .vimrc):
vmap <leader>c :w !cat \| codify.py \| xclip -selection clipboard<cr>
@koirikivi
koirikivi / find-elements-causing-horizontal-scrolling.js
Last active January 18, 2020 09:49
Find elements that cause horizontal scrolling
/*
Paste this in JS console or create a bookmarklet to find which elements cause a horizontal scroll on the page.
Correctly detects even elements that are hidden by css tricks (e.g. clip property).
Requires jQuery but could probably be optimized to work without it with modest effort.
*/
(function() {
var mainSelector = prompt(
'Selector under which to search',
'body'
);
@koirikivi
koirikivi / getNextAvailableTabIndex.js
Created December 21, 2018 14:43
Getting next available tabindex with jQuery
function getNextAvailableTabIndex() {
var tabIndexes = $('[tabIndex]').map(function() {
return parseInt($(this).attr('tabindex'), 10);
}).toArray();
tabIndexes.push(0); // account for [] and [-1]
return Math.max.apply(null, tabIndexes) + 1;
}
x = 2;
if(x % 2 == 0): {
print("x is even")
}
else: {
print("x is odd")
}
### Keybase proof
I hereby claim:
* I am koirikivi on github.
* I am koirikivi (https://keybase.io/koirikivi) on keybase.
* I have a public key ASCccGJ9jSXEti0O44INgzyD4PfHpPEOBkvJOXRIc5hmuwo
To claim this, I am signing this object:
#include <stdio.h>
int main() {
int test = 1;
if (test == 1)
{
printf("Test passed!\n");
}
else;