Skip to content

Instantly share code, notes, and snippets.

View jbn's full-sized avatar

John B Nelson jbn

View GitHub Profile
#!/bin/bash
# Fetch updates from remote
git fetch
# Loop over all branches except main
for branch in $(git branch | grep -v "main"); do
# Delete the branch
git branch -D $branch
done
@jbn
jbn / get_openi_billing_usage.py
Created March 11, 2023 21:03
A python module to get how much you owe Sam Altman
from typing import Any, Dict, Optional
import openai
import requests
from datetime import date, timedelta
API_BASE = "https://api.openai.com"
USAGE_ENDPOINT = f"{API_BASE}/dashboard/billing/usage"
from typing import NewType
import timeit
UserID = NewType('UserID', int)
def check_on(user_id: UserID) -> int:
return user_id * 2
@jbn
jbn / lolps5.py
Created September 15, 2021 21:14
import subprocess
import requests
from pyquery import PyQuery
import time
def send_to_pushover():
requests.post("https://api.pushover.net/1/messages.json", data={
"token": "XXX",
"user": "XXX",
@jbn
jbn / aiohttp_uptime_http_server.py
Created April 7, 2016 12:24
An example showing how to stream HTML in a aiohttp server.
import asyncio
from aiohttp import web
import subprocess
async def uptime_handler(request):
# http://HOST:PORT/?interval=90
interval = int(request.GET.get('interval', 1))
# Without the Content-Type, most (all?) browsers will not render
@jbn
jbn / avi_rotate.py
Created July 7, 2021 17:31
How I rotate my AVI
import tweepy
import json
import time
import datetime
from calendar import monthrange
from PIL import Image, ImageEnhance
import pathlib
import pylunar
TWEETS = [
"F3B383064F9A76AD777D08A4C3CBF4CD:DF4E827DCBA71AEA510F4B2BB5F62796:FDA3BA94D91870DA38783787178F6B565C391D441E82D1318571D0B1C17DC9B305C1B47EE8C69BF8F244027F53B1317DD53D8E27A923B3FE411411142754B846C53300483C5AA46A90D6F33F8F4BDF65F98D10C059A6A36D7F3C9A49472C768BAD275A094128D00860C5FD",
"6A9537BA898C70D3DB6BB5D984B6423104B5691111067413F6C3E9C6A3AB90678ADA2445592C41CA4802990621F47E21431125AE1E34B3A4C394CBD1AC4F1ACCC8FE04059C6586EF2425710619112CABF775C3C7CAE44DB8B6467228D845990295307A5539B3F8B50C735F4D4B2AEED59E73A5142F26578AA768FBBEF51B63BBF8AA824C2F87ED4C17E56C85",
"27F2322110C16594C3369792230F845F10E26231F76C201F164667C3CAD73FFA72AD710704BD3C3E65E91BDDF8888C8A7964F25510C29A598D21734BD1FD6FD5DB3D15F06E580A0C2839A81954BBDB3C690C9AB146792C02D3D976ECF57C1F37AB900A535F177E5A9CCAC190B2424BBF13B1F3D7F04C74DA593D43F058DF77DF4ACDC7F2A6FFC5847931AA74",
"FEA4845903FF9AFDF42A0C8CB25C0409A031EDC4BA3C05BC47298898CB5BECF2C02D0BAE7554",
"3CDB109B0AD9E30F845A0E07EE78FC83:ACC4B7820D28BF600134E74D00
@jbn
jbn / shifted_geom.py
Last active October 4, 2020 01:06
A shifted geometric distribution with p=0.75 via bit twiddling
# Came across the `randomLevel` function in
#
# https://github.com/automerge/automerge/blob/main/backend/skip_list.js
#
# which implements a geometric distribution with bit twiddling.
#
# Below is a pedagogical implementation.
import random
from collections import Counter
@jbn
jbn / Dockerfile
Created September 25, 2020 20:08
An attempt to build akash from scratch and set up a validator
FROM golang:1.14.9-stretch
# See: https://docs.akash.network/validator-guides/gentxo
RUN cd $GOPATH/src && mkdir -p github.com/ovrclk && \
cd github.com/ovrclk && \
git clone https://github.com/ovrclk/akash.git && \
cd akash && \
MAINNET=true git checkout v0.8.1 && \
make deps-install && \
make install
@jbn
jbn / python_help_evolution.txt
Created July 13, 2020 18:50
Diff of python --help over time
Python 2.7.10
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)