Skip to content

Instantly share code, notes, and snippets.

@amcclosky
amcclosky / command-bar.js
Last active Nov 4, 2021
useCommandBar - React Hook for next.js
View command-bar.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 Jan 15, 2021
A sqlalchemy column type that wraps a Pendulum datetime
View pendulum_type.py
# 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 Aug 10, 2020
Recover commits
View README.md

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 Jul 24, 2020
A global roughly time-ordered identifier mixin for sqlalchemy.
View README.md

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 Jul 24, 2020 — forked from kohenkatz/generate_ulid_text.sql
UILD Utilities in PL/pgSQL
View README.md

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 Jul 17, 2020
Python + Node Web Dev Container
View Dockerfile
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"
View csv.py
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]
View keybase.md

Keybase proof

I hereby claim:

  • I am amcclosky on github.
  • I am amcclosky (https://keybase.io/amcclosky) on keybase.
  • I have a public key ASAN0P7ksrN5EzohNFt_mu2gbJI9o1thM23aFAgmy6Ko-Qo

To claim this, I am signing this object:

View .bash_profile
source ~/bin/fancy_prompt.sh
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
alias show-hidden='defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder'
alias hide-hidden='defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder'
alias flushdns='sudo discoveryutil udnsflushcaches'
View fancy_prompt.sh
# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
# A big thanks to \amethyst on Freenode
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
tput sgr0