Skip to content

Instantly share code, notes, and snippets.

@uberscientist
uberscientist / pill_timer.ino
Created January 3, 2019 03:14
Arduino alarm clock
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#include <SPI.h>
#include <ezTime.h>
#include <SPIFFS.h>
#include <ESPAsyncWebServer.h>
#include <WiFi.h>
AsyncWebServer server(80);
SSD1306 display(0x3c, 4, 15);
@uberscientist
uberscientist / simulation.py
Last active December 19, 2018 06:34
Monte Carlo on Maplestory2 Casino Game
import random
import math
import matplotlib.pyplot as plt
def getResults(num_groups=4, num_players=9):
players = ['Player {i}'.format(i=i) for i in range(1, num_players)]
players += ['You', 'Casino']
random.shuffle(players)
group_size = math.ceil(len(players) / num_groups)
{'type': 'trade', 'symbol': 'SPY180606P00235000', 'exch': 'I', 'price': '0.08', 'size': '2', 'cvol': '0', 'date': '1527611813000', 'last': '0.08'}
{'type': 'trade', 'symbol': 'SPY180606C00261000', 'exch': 'C', 'price': '14.29', 'size': '30', 'cvol': '50', 'date': '1528209279000', 'last': '14.29'}
{'type': 'trade', 'symbol': 'SPY180606C00235000', 'exch': '', 'price': '', 'size': '0', 'cvol': '0', 'date': '0', 'last': ''}
{'type': 'trade', 'symbol': 'SPY180606P00256000', 'exch': 'Q', 'price': '0.01', 'size': '3', 'cvol': '0', 'date': '1528119065000', 'last': '0.01'}
{'type': 'quote', 'symbol': 'SPY', 'bid': 275.34, 'bidsz': 1, 'bidexch': 'P', 'biddate': '1528238802000', 'ask': 275.37, 'asksz': 22, 'askexch': 'P', 'askdate': '1528238662000'}
{'type': 'trade', 'symbol': 'SPY', 'exch': 'P', 'price': '275.1', 'size': '0', 'cvol': '51115122', 'date': '1528237800000', 'last': '275.1'}
{'type': 'quote', 'symbol': 'SPY', 'bid': 275.34, 'bidsz': 1, 'bidexch': 'P', 'biddate': '1528238802000', 'ask': 275.37, 'asksz': 22,
@uberscientist
uberscientist / error.py
Created May 11, 2018 00:07
Error sporadically occurs during stream
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/nak/.virtualenvs/tradier-bot/lib/python3.6/site-packages/urllib3/response.py", line 543, in _update_chunk_length
self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/nak/.virtualenvs/tradier-bot/lib/python3.6/site-packages/urllib3/response.py", line 302, in _error_catcher
def encode_pair(f):
# Decorator function to encode "pair" to bytes object
def new_f(*args, **kwargs):
args = list(args)
pair = args[1]
if type(pair) == str:
args[1] = pair.encode()
assert type(args[1]) == bytes
args = tuple(args)
return f(*args, **kwargs)
@uberscientist
uberscientist / xpubsub_proxy.py
Created February 19, 2018 04:32
Example code for figure 13 "Pub-Sub Network with a Proxy" http://zguide.zeromq.org/page:all#The-Dynamic-Discovery-Problem
import zmq
from threading import Thread
from time import sleep
from random import randint
# Setup sockets for the proxy XSUB/XPUB and bind them to separate ports
ctx = zmq.Context()
xsub_sock = ctx.socket(zmq.XSUB)
xpub_sock = ctx.socket(zmq.XPUB)
xsub_sock.bind('tcp://127.0.0.1:1234')
@uberscientist
uberscientist / pubsub.py
Created February 15, 2018 14:47
pyzmq PUB/SUB example
import zmq
from multiprocessing import Process
from time import sleep
"""
Simple multiprocess pub/sub ZeroMQ example python3
2/15/2018
"""
tcp_interface = 'tcp://127.0.0.1:5600'
@uberscientist
uberscientist / main.js
Created July 18, 2017 23:36
Attempt to calculate black-scholes on GPU
var gpu = new GPU();
gpu.addFunction(function CND(x) {
var k = 1 / (1 + .2316419 * x);
if(x < 0) {
x = x * -1
return 1 - ( 1 - Math.exp(-x * x / 2)/ Math.sqrt(2*Math.PI) * k * (.31938153 + k * (-.356563782 + k * (1.781477937 + k * (-1.821255978 + k * 1.330274429)))) );
} else {
return ( 1 - Math.exp(-x * x / 2)/ Math.sqrt(2*Math.PI) * k * (.31938153 + k * (-.356563782 + k * (1.781477937 + k * (-1.821255978 + k * 1.330274429)))) );
}
Verifying that "mindsforge.id" is my Blockstack ID. https://onename.com/mindsforge
@uberscientist
uberscientist / histograms.py
Last active May 6, 2017 20:02
display half-hourly returns of the SPX index
import pandas as pd
from collections import defaultdict
from redis import StrictRedis
from activetick_http import ActiveTick
from datetime import datetime, timedelta
from bokeh.charts import Histogram, show
from bokeh.layouts import column, row
from bokeh.models import Range1d
from bokeh.models.widgets import Div