Skip to content

Instantly share code, notes, and snippets.

View bryanhelmig's full-sized avatar
Zapier is hiring!

Bryan Helmig bryanhelmig

Zapier is hiring!
View GitHub Profile
@bryanhelmig
bryanhelmig / fix_openai_bytes.py
Last active November 4, 2022 16:48
handle openapi bytes (davinci, babbage, curie, ada, etc.)
def try_strip_bytes_prefix(token: str) -> str:
if token.startswith("bytes:") and "\\" in token:
return token[6:]
return token
def try_bytes_fix(tokens: list[str]) -> str:
# this encode/decode dance fixes places where openai provides
# "bytes: \\xf0\\x9f\\x98" + "bytes:\\x83" for tokens and replaces
# with the appropriate emoji (e.g. "😃")
@bryanhelmig
bryanhelmig / asgi.py
Last active April 13, 2023 12:40
A Django + Starlette or FastAPI connection handling example (ASGI, with WSGIMiddleware).
# Looking for a good remote Python job? Check out Zapier at https://zapier.com/jobs/.
import functools
import importlib
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") # noqa
import anyio
from asgiref.sync import sync_to_async
from django.conf import settings
var immer = require("immer");
var produce = immer.produce;
var patches = [];
var state0 = { a: 1 };
var state1 = produce(
state0,
function (draft) {
draft.b = 9;
},
@bryanhelmig
bryanhelmig / compare-pips.py
Created December 26, 2017 20:55
Compare pip freeze to requirements.txt for use in a bash script where pip may not be installed.
#!/usr/bin/env python
import argparse
import subprocess
import sys
from packaging.version import parse as parse_version
def parse_dependencies(text):
@bryanhelmig
bryanhelmig / linty.sh
Created September 11, 2017 21:55
a zapier python lint command, put it on path!
#!/usr/bin/env bash
CHANGED_PYTHON_FILES=`git diff-tree --diff-filter=ACMRT --no-commit-id --name-only -r origin/develop.. -- "*.py" | tr "\n" " "`
flake8 --exit-zero --format=pylint ${CHANGED_PYTHON_FILES}
pylint --py3k --disable=no-absolute-import --disable=round-builtin -sn --msg-template="{path}:{line}: [{msg_id}] {msg}" ${CHANGED_PYTHON_FILES}
@bryanhelmig
bryanhelmig / nintendo-switch-getter.py
Created March 23, 2017 01:24
A script that watches prime now for stock, sending a webhook to Zapier which you can configure to send you an SMS, Slack, whatever...
import time
import bs4
import requests
import logging
import sys
logger = logging.getLogger('switchlogger')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)

Keybase proof

I hereby claim:

  • I am bryanhelmig on github.
  • I am bryanhelmig (https://keybase.io/bryanhelmig) on keybase.
  • I have a public key whose fingerprint is BC07 78B9 D1A4 3DBA DF36 F565 4429 102A 84CB 847F

To claim this, I am signing this object:

package main
import (
"fmt"
)
func decorator(f func(s string)) func(s string) {
return func(s string) {
fmt.Println("Started")
@bryanhelmig
bryanhelmig / active_user_analysis.py
Last active February 8, 2017 23:47
Counts of users' events by day
"""
users if active or not on a given day plus counts of events
"""
import os
import csv
from collections import defaultdict
from collections import Counter
UFILE = 'data/users.csv'
@bryanhelmig
bryanhelmig / detect_mashing.py
Last active January 12, 2024 03:19
A short snippet of Python that detects keyboard mashing like dsuyafgsgafiuyas.
import itertools
import math
def tokenize_keyboard(board):
return [list(row.strip()) for row in board]
def invert_grid(grid):
out = {}
for row_i, row in enumerate(grid):
for col_i, cell in enumerate(row):