Skip to content

Instantly share code, notes, and snippets.

@sbarratt
sbarratt / utoh.py
Last active June 2, 2016 18:09
Takes a list of urls from stdin and writes formatted hyperlinks to stdout.
#!/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.
"""
@sbarratt
sbarratt / windows_multi.cpp
Last active July 15, 2016 11:01
Windows multithreading in c++
//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 / scrolltest.html
Created July 25, 2016 06:07
Scroll through a list of items nicely.
<html>
<head>
<style>
#content {
font-size: 18;
text-align: center;
padding-top: 150px;
}
.blurry-text {
color: transparent;
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
"""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)
@sbarratt
sbarratt / 3per.py
Last active August 15, 2016 17:17
Implementation of the 3-Base Periodicity Property: https://en.wikipedia.org/wiki/3-Base_Periodicity_Property
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)]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sbarratt
sbarratt / kmeans_missing.py
Created November 3, 2017 00:21
K-means script that works with NaN entries.
"""
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 / flash.go
Created April 11, 2021 23:58
flashbots http attempt
package main
import (
"fmt"
"log"
"bytes"
"math/big"
"encoding/json"
"io/ioutil"
"net/http"
@sbarratt
sbarratt / erc20.py
Created September 26, 2022 17:47
ERC-20 Transfers as a Sparse Matrix
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',
)