Skip to content

Instantly share code, notes, and snippets.

View highfestiva's full-sized avatar

highfestiva highfestiva

View GitHub Profile
@highfestiva
highfestiva / textsearch.v
Last active April 7, 2021 17:43
A fast grep-like cli tool, which skips the usual suspects. (My first vlang experiment.)
import os
import os.cmdline
const (
exclude_dirs = map{
'.git': 1
'.svn': 1
'__pycache__': 1
}
@highfestiva
highfestiva / clip-pydata.py
Last active October 28, 2020 14:00
Format and plot random clipboard data
#!/usr/bin/env python3
'''Take clipboard data and try to format numberic as dataframes, or allows you to plot them right off the bat. Say you copy something like this:
some 32 number with accuracy 71.6
then 1 more thing
some 33 with accuracy 69.2 or accuracy 68.8
and run this script (preferrably through AutoHotkey or something similar). That will show you a menu like so:
@highfestiva
highfestiva / binance-liquidation-calculator.py
Last active April 16, 2024 06:13
CLI Binance liquidation calculation formula
#!/usr/bin/env python3
'''2021-03-26: Reverse-engineer by searching for the following terms in features*.js:
- bracketMaintenanceMarginRate
- cumFastMaintenanceAmount
- bracketNotionalFloor
- bracketNotionalCap'''
# (max) position, maintenance margin, maintenance amount
maint_lookup_table = [
@highfestiva
highfestiva / calc_pi.py
Created December 15, 2019 01:31
Calculate PI with an incredibly low accuracy
#!/usr/bin/env python3
import sys
terms = (int(sys.argv[1]) + 1) // 2
pi = 4 + sum(4/-(v*4+3) + 4/(v*4+5) for v in range(terms))
print(pi)
@highfestiva
highfestiva / bitmex-cross-margin-liquidation-calc.py
Created November 15, 2019 19:02
Optimized and simplified BitMEX's cross-margin calculation
def long_liq_price(wallet_balance_btc, qty, price):
usd = qty * int(-100000000 / price - 0.5)
a = wallet_balance_btc * 99925056.20784412 + 0.011498875843117663 * usd
a *= a>0
x = usd*1.004831 - a
return -100000000 / int(x / qty)
def short_liq_price(wallet_balance_btc, qty, price):
usd = qty * int(-100000000 / price - 0.5)
@highfestiva
highfestiva / bitmex-liquidation-calculator.py
Created October 26, 2019 20:54
cli bitmex liquidation calculation formula, minimal implementation
#!/usr/bin/env python3
import argparse
from math import ceil, floor
sign = lambda amt: -1 if amt<0 else (1 if amt>0 else 0)
class dobj:
@highfestiva
highfestiva / minimal-web.py
Last active August 13, 2019 05:45
Minimal general-purpose test web server
#!/usr/bin/env python3
from flask import Flask, request, jsonify
app = Flask(__name__)
methods = 'GET POST PUT DELETE'.split()
@app.route('/', methods=methods)
@highfestiva
highfestiva / knasboll.py
Last active October 1, 2018 21:36
Autotask to Exact Online invoice-to-book-keeping converter
#!/usr/bin/env python3
import argparse
import csv
from datetime import datetime
import dateutil.parser
from glob import glob
import xml.etree.ElementTree as ET
@highfestiva
highfestiva / memoize.py
Created December 30, 2017 17:15
Minimal 19 LoC memoization with timeout
import time
class memoize(object):
def __init__(self, timeout=60):
self.cache = {}
self.timeout = timeout
def _flush(self):
now = time.time()
@highfestiva
highfestiva / coinplot.py
Created December 8, 2017 14:32
Plot some candlesticks based on crypto currency data. Prepped for use in real webserver.
#!/usr/bin/env python3
from bokeh.embed import components as plot_html
from bokeh.plotting import figure, show, output_file
import pandas as pd
import requests
import webbrowser
url = 'https://www.binance.com/api/v1/klines?interval=15m&symbol=ARNBTC&limit=100'