Skip to content

Instantly share code, notes, and snippets.

@neelriyer
neelriyer / btcpy.ipynb
Last active August 11, 2021 01:24
btcpy.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@neelriyer
neelriyer / hedgefundie_value_at_risk.ipynb
Created July 30, 2021 01:12
Hedgefundie_Value_at_risk.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@neelriyer
neelriyer / pancake_bunny_hacker_decompiled.sol
Last active August 2, 2021 18:25
Smart Contract behind the Pancake Bunny hack
# https://www.cointribune.com/en/columns/the-defi-column/has-pancake-bunny-fallen-victim-to-a-1-billion-hack/
#
# Panoramix 17 Feb 2020
#
#
# I failed with these:
# - unknownee872558(?)
# All the rest is below.
#
@neelriyer
neelriyer / cyclegan_training.py
Created September 1, 2020 22:41
Cyclegan Training Script (with copy to google drive functionality)
# adapted from: https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/test.py
for epoch in range(opt.epoch_count, opt.n_epochs + opt.n_epochs_decay + 1): # outer loop for different epochs; we save the model by <epoch_count>, <epoch_count>+<save_latest_freq>
epoch_start_time = time.time() # timer for entire epoch
iter_data_time = time.time() # timer for data loading per iteration
epoch_iter = 0 # the number of training iterations in current epoch, reset to 0 every epoch
visualizer.reset() # reset the visualizer: make sure it saves the results to HTML at least once every epoch
model.update_learning_rate() # update learning rates in the beginning of every epoch.
for i, data in enumerate(dataset): # inner loop within one epoch
@neelriyer
neelriyer / compare_models.py
Created August 10, 2020 08:23
Quickly compare neural network against xgb, lgb and random forest
from sklearn.ensemble import RandomForestRegressor
import xgboost as xgb
import lightgbm as lgb
def rmspe_calc(y_true, y_pred):
# Compute Root Mean Square Percentage Error between two arrays.
return np.sqrt(np.mean(np.square(((y_true - y_pred) / y_true)), axis=0))
models = [
from itertools import product
from tqdm.notebook import tqdm
def get_learner(emb_szs=emb_szs, layers=[1000,500], ps=[0.02,0.04], emb_drop=0.08):
return (tabular_learner(data,
layers=layers,
ps=ps,
emb_drop=emb_drop,
y_range=y_range,
@neelriyer
neelriyer / mealkit_preprocessing.py
Created August 10, 2020 08:02
Pre-processing data for mealkit neural network article
# Fill Missing values
# Encode categorical variables
# Normalize continous variables
procs=[FillMissing, Categorify, Normalize]
cont_vars = [i for i in [‘checkout_price’,
‘base_price’,
‘Elapsed’,
‘week_sin’,
‘week_cos’,
@neelriyer
neelriyer / reconstruct_audio.py
Created August 10, 2020 00:26
reconstruct the audio from a waveform
# taken from: https://github.com/alishdipani/Neural-Style-Transfer-Audio/blob/master/NeuralStyleTransfer.py
if torch.cuda.is_available():
output = output.cpu()
output = output.squeeze(0)
output = output.numpy()
N_FFT=2048
a = np.zeros_like(output)
@neelriyer
neelriyer / run_neural_style_transfer_audio.py
Created August 10, 2020 00:26
Run neural style transfer for audio
import torch
import torch.nn as nn
from torch.nn import Conv2d, ReLU, AvgPool1d, MaxPool2d, Linear, Conv1d
from torch.autograd import Variable
import torch.optim as optim
import numpy as np
import os
import torchvision.transforms as transforms
import gc; gc.collect()
@neelriyer
neelriyer / create_cnn.py
Created August 10, 2020 00:25
create cnn for neural style transfer
import torch
import torch.nn as nn
from torch.nn import ReLU, Conv1d
import torch.optim as optim
import numpy as np
import copy
class CNNModel(nn.Module):
def __init__(self):
super(CNNModel, self).__init__()