Skip to content

Instantly share code, notes, and snippets.

View miohtama's full-sized avatar
🏠
https://tradingstrategy.ai

Mikko Ohtamaa miohtama

🏠
https://tradingstrategy.ai
View GitHub Profile
@miohtama
miohtama / gist:5216738
Created March 21, 2013 21:05
Enabling SSLCACertificateFile and SSLVerifyClient for one page only in Apache 2.2+
# Apache configuration for running local browser against a locally running xxxx for manual smartcard testing
# Listen 4433
<VirtualHost 127.0.0.1:4433>
# Real men use mod_proxy
DocumentRoot "/nowhere"
ServerName local-apache
ServerAdmin you@example.com
@miohtama
miohtama / webserver.py
Created September 17, 2015 01:54
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
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("https://devnet-gateway.elrond.com")
sender = Account(pem_file="test-wallet.pem")
sender.sync_nonce(proxy)
// 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
miohtama / write-parquet-larger-than-ram.py
Created July 14, 2021 10:03
Writing Parquet files incrementally from Python
with pq.ParquetWriter(
fname,
Candle.to_pyarrow_schema(small_candles),
compression='snappy',
allow_truncated_timestamps=True,
version='2.0', # Highest available schema
data_page_version='2.0', # Highest available schema
) as writer:
def reset_data():
@miohtama
miohtama / ethereum_address_type_for_sqlalchemy.py
Created June 27, 2021 11:15
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.
"""
@miohtama
miohtama / approximate_row_count_sqlalchemy.py
Created June 13, 2021 19:07
Fast approximate_row_count with TimescaleDB and SQLAlchemy
import logging
import time
import timeit
from typing import Type
from sqlalchemy.orm import Session
from sqlalchemy.sql import text
from dex_ohlcv.db import get_real_database
from dex_ohlcv.models.uniswap import Base, UniswapLikeCandle, Pair
@miohtama
miohtama / get_all_erc_20_approve_transactions_using_bigquery.sql
Created April 2, 2021 10:00
Get all ERC-20() transactions using BigQuery public dataset
-- Get all approve() transaction
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, tx.block_timestamp as block_timestamp, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT (SUM(cost) / POWER(10, 18)) as eth_cost from txdata;
@miohtama
miohtama / Generating Ethereum addresses from mnemonic seed words.js
Created April 14, 2021 08:45
Generating Ethereum addresses from mnemonic seed words
const HDWallet = require('ethereum-hdwallet')
const mnemonic = 'your seed prhase goes here'
const hdwallet = HDWallet.fromMnemonic(mnemonic)
for(let i=0; i<1000; i++) {
console.log(`0x${hdwallet.derive(`m/44'/60'/0'/0/${i}`).getAddress().toString('hex')}, 3.33`)
}
def _console(context: ProcessContext):
imported_objects = {}
import datetime
from IPython import embed
from dex_ohlcv.models.base import Base
imported_objects["db_session_scoper"] = context.create_db_session_scoper()
imported_objects["web3"] = context.create_web3()
imported_objects["datetime"] = datetime