Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Barratt sbarratt

View GitHub Profile
@sbarratt
sbarratt / torch_jacobian.py
Created May 9, 2019
Get the jacobian of a vector-valued function that takes batch inputs, in pytorch.
View torch_jacobian.py
def get_jacobian(net, x, noutputs):
x = x.squeeze()
n = x.size()[0]
x = x.repeat(noutputs, 1)
x.requires_grad_(True)
y = net(x)
y.backward(torch.eye(noutputs))
return x.grad.data
@sbarratt
sbarratt / scrape_ftx.py
Last active Nov 14, 2022
A script to export all FTX history
View scrape_ftx.py
import pandas as pd
import time
import requests
import time
import hmac
from requests import Request
import sys
import json
import os
@sbarratt
sbarratt / erc20.py
Created Sep 26, 2022
ERC-20 Transfers as a Sparse Matrix
View erc20.py
from ctc import evm
from scipy import sparse
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
transfers = await evm.async_get_erc20_transfers(
token='0x956f47f50a910163d8bf957cf5846d573e7f87ca',
event_name='Transfer',
)
@sbarratt
sbarratt / keyboardhook.cpp
Created May 31, 2016
Create a keyboard hook using Win32 System API and log what the user types into a console.
View keyboardhook.cpp
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <iostream>
HHOOK hHook{ NULL };
enum Keys
{
ShiftKey = 16,
@sbarratt
sbarratt / geo.py
Last active Jun 30, 2022
This script provides coordinate transformations between geodetic, ecef and enu in python. Based on https://gist.github.com/govert/1b373696c9a27ff4c72a.
View geo.py
"""
This script provides coordinate transformations from Geodetic -> ECEF, ECEF -> ENU
and Geodetic -> ENU (the composition of the two previous functions). Running the script
by itself runs tests.
based on https://gist.github.com/govert/1b373696c9a27ff4c72a.
"""
import math
a = 6378137
b = 6356752.3142
@sbarratt
sbarratt / flash.go
Created Apr 11, 2021
flashbots http attempt
View flash.go
package main
import (
"fmt"
"log"
"bytes"
"math/big"
"encoding/json"
"io/ioutil"
"net/http"
@sbarratt
sbarratt / kmeans_missing.py
Created Nov 3, 2017
K-means script that works with NaN entries.
View kmeans_missing.py
"""
Author: Shane Barratt
Email: sbarratt@stanford.edu
K-means script that works with NaN entries.
"""
import numpy as np
import IPython as ipy
import matplotlib.pyplot as plt
View Presentation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sbarratt
sbarratt / 3per.py
Last active Aug 15, 2016
Implementation of the 3-Base Periodicity Property: https://en.wikipedia.org/wiki/3-Base_Periodicity_Property
View 3per.py
import matplotlib.pyplot as plt
from numpy.fft import fft
from numpy.fft import fftshift
import numpy as np
import random
dictionary = ['A','C','G','T']
def generate_random_sequence(N):
return [dictionary[random.randint(0,len(dictionary)-1)] for _ in range(N)]
View cnn.py
"""CNN from https://www.microsoft.com/en-us/research/wp-content/uploads/2003/08/icdar03.pdf"""
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
import tensorflow as tf
def weight_variable(shape):
initial = tf.random_normal(shape, stddev=0.05)
return tf.Variable(initial)