Skip to content

Instantly share code, notes, and snippets.

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.
@reverie
reverie / simplegeo_zips.js
Created November 19, 2011 03:26 — forked from joshsmith/simplegeo_zips.js
Finding zip codes within the radius of a given address using SimpleGeo (with 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) {

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 / short_naturaltime.py
Created August 26, 2016 15:16
Django naturaltime with only one time denomination, no comma
@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'
@reverie
reverie / read-screenshot.py
Last active January 27, 2019 22:52
OCR your latest screenshot on MacOS and copy its contents to the clipboard
#!/usr/bin/env python3
# Give this +x and put it on your $PATH
import subprocess
import os.path
import glob
from pathlib import Path
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 / Stack.tsx
Created April 28, 2020 19:04
typescript/tailwind Stack component
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 = {
@reverie
reverie / .bashrc
Created May 4, 2020 20:56
Git bash helpers
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"