Skip to content

Instantly share code, notes, and snippets.

View yifeihuang's full-sized avatar

Yifei Huang yifeihuang

  • Sequoia Capital
View GitHub Profile
@yifeihuang
yifeihuang / decode_log.py
Last active June 13, 2022 02:50
Example code to decode an Ethereum event log
from web3._utils.events import get_event_data
@lru_cache(maxsize=None)
def _get_topic2abi(abi):
if isinstance(abi, (str)):
abi = json.loads(abi)
event_abi = [a for a in abi if a['type'] == 'event']
topic2abi = {event_abi_to_log_topic(_): _ for _ in event_abi}
return topic2abi
@yifeihuang
yifeihuang / decode_transaction.py
Created October 20, 2021 17:33
Decoding an Ethereum smart contract transaction
import traceback
import sys
from functools import lru_cache
from web3 import Web3
from web3.auto import w3
from web3.contract import Contract
from web3._utils.events import get_event_data
from web3._utils.abi import exclude_indexed_event_inputs, get_abi_input_names, get_indexed_event_inputs, normalize_event_input_types
from web3.exceptions import MismatchedABI, LogTopicError
from web3.types import ABIEvent
@yifeihuang
yifeihuang / example_abi.json
Created October 20, 2021 16:23
Uniswap v2 Router Application Binary Interface
[
{
"inputs": [
{
"internalType": "address",
"name": "_factory",
"type": "address"
},
{
"internalType": "address",
@yifeihuang
yifeihuang / timeseries_interpolation.py
Last active September 29, 2021 21:45
Interpolate time series data with pyspark
from pyspark.sql import functions as f
from pyspark.sql import types as t
from pyspark.sql import Window as w
from pyspark.sql.functions import pandas_udf, PandasUDFType
import numpy as np
import datetime
sequence = [1, 2, 4, 7, 11, 16, 22]
sequence2 = [3, 5, 6, 8, 10, 18, 20]
@yifeihuang
yifeihuang / churn_shap.ipynb
Created December 28, 2020 22:25
Explain GBT churn model with SHAP
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yifeihuang
yifeihuang / parallel_apply.ipynb
Last active December 28, 2020 10:31
Parallelized apply for Pandas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yifeihuang
yifeihuang / serp_template.ipynb
Last active December 8, 2020 19:31
Example code for calling SERP API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yifeihuang
yifeihuang / peeking simulation.ipynb
Last active December 6, 2022 12:40
Empirical simulation to show how peeking inflates false discovery rate
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yifeihuang
yifeihuang / example multivariate analysis.ipynb
Last active December 4, 2020 03:45
Multivariate experiment analysis procedure
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yifeihuang
yifeihuang / AB test formulas.ipynb
Last active July 10, 2023 02:55
AB test sample size calculation and analysis procedures
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.