Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Barratt sbarratt

View GitHub Profile
@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 / 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 / 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
@sbarratt
sbarratt / geo.py
Last active Mar 22, 2021
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
View Presentation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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)
View mlp.py
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
import matplotlib.pyplot as plt
# Load data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
# Neural Network Initialization
@sbarratt
sbarratt / scrolltest.html
Created Jul 25, 2016
Scroll through a list of items nicely.
View scrolltest.html
<html>
<head>
<style>
#content {
font-size: 18;
text-align: center;
padding-top: 150px;
}
.blurry-text {
color: transparent;
@sbarratt
sbarratt / windows_multi.cpp
Last active Jul 15, 2016
Windows multithreading in c++
View windows_multi.cpp
//more details: http://www.bogotobogo.com/cplusplus/multithreaded2A.php
#include <Windows.h>
#include <process.h>
#include <stdio.h>
unsigned int __stdcall test_thread(void *data) {
printf("Thread Started");
return 0;
}
@sbarratt
sbarratt / utoh.py
Last active Jun 2, 2016
Takes a list of urls from stdin and writes formatted hyperlinks to stdout.
View utoh.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Urls to Hyperlinks.
This script takes line-separated urls from stdin and writes formatted hyperlinks to stdout.
Usage:
# cat urls.txt | python ltoh.py > hyperlinks.
"""