Skip to content

Instantly share code, notes, and snippets.

@reverie
reverie / .bashrc
Created May 4, 2020
Git bash helpers
View .bashrc
function c { git checkout $@; }
function b { git branch $@; }
alias s="git status"
alias d="git diff"
alias dc="git diff --cached"
alias dv="git diff | vim -"
alias l="git log"
alias gp="git pull"
alias gpu="git push"
alias cam="git commit -am"
@reverie
reverie / Stack.tsx
Created Apr 28, 2020
typescript/tailwind Stack component
View Stack.tsx
import React from "react";
import classNames from "classnames";
// See https://tailwindcss.com/docs/margin/
type MarginSize = "2" | "4" | "8";
// See https://tailwindcss.com/docs/responsive-design/
type ScreenSize = "sm" | "md";
type Config = {
View lenient_email_extractor.py
def extract_first_email(s):
"""
Assumes `s` is a list of email addresses split by (mixed) spaces or commas.
Returns (first_email, rest) where first_email + rest == s,
or (None, None) if we don't think this is an email address.
"""
first_quote = s.find('"')
first_at = s.find('@')
if first_at == -1:
return (None, None)
@reverie
reverie / read-screenshot.py
Last active Jan 27, 2019
OCR your latest screenshot on MacOS and copy its contents to the clipboard
View read-screenshot.py
#!/usr/bin/env python3
# Give this +x and put it on your $PATH
import subprocess
import os.path
import glob
from pathlib import Path
@reverie
reverie / short_naturaltime.py
Created Aug 26, 2016
Django naturaltime with only one time denomination, no comma
View short_naturaltime.py
@register.filter
def short_naturaltime(value):
from django.contrib.humanize.templatetags.humanize import naturaltime
base = naturaltime(value)
if ',' not in base:
return base
return base.split(',', 1)[0] + ' ago'
View keybase.md

Keybase proof

I hereby claim:

  • I am reverie on github.
  • I am ab (https://keybase.io/ab) on keybase.
  • I have a public key whose fingerprint is 0CFF 98F7 8E4F D9EF 23FD 425F 3F7F 0E06 8CE1 9593

To claim this, I am signing this object:

@reverie
reverie / simplegeo_zips.js
Created Nov 19, 2011 — forked from joshsmith/simplegeo_zips.js
Finding zip codes within the radius of a given address using SimpleGeo (with JS!)
View simplegeo_zips.js
$(document).ready(function() {
simplegeo_key = 'TOKEN';
var places_client = new simplegeo.Places12Client(simplegeo_key);
var context_client = new simplegeo.ContextClient(simplegeo_key);
// Given an address and radius (and the SimpleGeo client), returns
// a comma-separated list of zip codes within that radius.
function get_nearby_zips(address, radius, places_client, callback) {
View Django 1.2 UUIDField with South support
from django.db import models
import uuid
class UUIDField(models.CharField):
"""
A field which stores a UUID value in hex format. This may also have
the Boolean attribute 'auto' which will set the value on initial save to a
new UUID value (calculated using the UUID1 method). Note that while all
UUIDs are expected to be unique we enforce this with a DB constraint.
You can’t perform that action at this time.