Skip to content

Instantly share code, notes, and snippets.

@amcclosky
amcclosky / README.md
Last active September 13, 2024 18:13
Script to find the current Magic Number of an MLB Team

Magic Number Script

$ uv run magic.py "Houston Astros"
Reading inline script metadata from: magic.py
The magic number for the Houston Astros is 12.
@amcclosky
amcclosky / deeplinks.md
Last active March 1, 2024 21:58
Backflip Deeplink Tests
@amcclosky
amcclosky / r2.py
Created January 21, 2024 02:15
R2 Compatible boto3 s3 client
import boto3
from botocore.config import Config
from . import config
r2 = boto3.client(
service_name="s3",
endpoint_url=config.R2_S3_ENDPOINT,
aws_access_key_id=config.R2_ACCESS_KEY_ID,
@amcclosky
amcclosky / command-bar.js
Last active November 4, 2021 16:21
useCommandBar - React Hook for next.js
// yarn add commandbar or npm install commandbar --save
import { useEffect } from 'react'
import { init as initCommandBar } from 'commandbar'
const COMMANDBAR_ORG =
process.env.COMMANDBAR_ORG || process.env.NEXT_PUBLIC_COMMANDBAR_ORG
function useCommandBar({ org = COMMANDBAR_ORG, userId, userMeta = {} }) {
@amcclosky
amcclosky / pendulum_type.py
Created January 15, 2021 23:54
A sqlalchemy column type that wraps a Pendulum datetime
# custom sqlalchemy column type for a pendulum datetime - https://pendulum.eustace.io/
from datetime import datetime
import pendulum
import sqlalchemy as sa
from sqlalchemy.types import TypeDecorator as _TypeDecorator
from sqlalchemy_utils.types.scalar_coercible import ScalarCoercible as _ScalarCoercible
@amcclosky
amcclosky / README.md
Created August 10, 2020 16:49
Recover commits

Recover Commits via GitHub API

#til #git #github

curl -u amcclosky:<personal access token> https://api.github.com/repos/amcclosky/baseball/events

curl -u amcclosky:<personal access token> -X POST -d '{"ref":"refs/heads/recover-office-hours", "sha":"d460395af3337bc6b71fd19b154f831ecc6cfa01"}' https://api.github.com/repos/amcclosky/baseball/git/refs

github - How to recover from a git push -force? - Stack Overflow

@amcclosky
amcclosky / README.md
Last active July 24, 2020 17:25
A global roughly time-ordered identifier mixin for sqlalchemy.

A sqlalchemy model mixn, GlobalIdMixin which provides a global roughly time-ordered identifier and an obfuscated version of the global id for public consumption.

Makes use of python-ulid, PL/sql ULID and hashids-python.

@amcclosky
amcclosky / README.md
Last active July 24, 2020 17:30 — forked from kohenkatz/generate_ulid_text.sql
UILD Utilities in PL/pgSQL

UILD for PL/pgSQL

ULID is a format for k-ordered distributed id generation. i.e. you can generate a random unique id with no central coordination and later be able to mostly sort the ids by the time they were generated.

When won't ids be sorted?

If ids are generated within the same second on different instances they could be out of order within that second.

Source of this code:

@amcclosky
amcclosky / Dockerfile
Created July 17, 2020 06:01
Python + Node Web Dev Container
FROM mcr.microsoft.com/vscode/devcontainers/python:3.7
# Docker script args, location, and expected SHA - SHA generated on release
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG DOCKER_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/master/script-library/docker-debian.sh"
ARG DOCKER_SCRIPT_SHA="dev-mode"
ARG ENABLE_NONROOT_DOCKER="true"
class CSVImportMixin:
"""Adds from_csv to a SQLAlchemy model class."""
__tablename__ = None
__upsert_keys__ = ("id",)
@classmethod
def _columns(cls):
_columns = get_columns(cls)
return [c for c in _columns]