Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import itertools
import re
import sys
from base64 import b64encode
from hashlib import sha256
import phonenumbers
import pytz
from csvkit import DictReader, DictWriter
@allancaffee
allancaffee / tld-grouping.py
Last active June 28, 2018 16:17
TLD grouping
domains = """
am.example.com
ap.example.com
eu.example.com
itd.sel.example.com
jp.example.com
ncope.account.example.com
bizbat.example.com
scesh.example.com
smss.example.com
@allancaffee
allancaffee / gist:1510658
Created December 22, 2011 15:18
Strange date histogram facet behavior with ElasticSearch version 0.18.5
curl -X PUT 'http://localhost:9200/articles/article/1?pretty=true' -d '{
"title": "One",
"some_date": "2000-01-01T00:00:00"
}'
# {
# "ok" : true,
# "_index" : "articles",
# "_type" : "article",
# "_id" : "1",
@allancaffee
allancaffee / gist:1508383
Created December 22, 2011 00:38
ElasticSearch (version 0.18.5) term query for literal url match
curl -XPUT localhost:9200/test_a/type1/1 -d '{
"url" : "http://example.com/blog"
}'
# {"ok":true,"_index":"test_a","_type":"type1","_id":"1","_version":1}
curl localhost:9200/test_a/type1/_search?pretty=true -d '{
"query": {
"term": {
"url": "http://example.com/blog"
}
@allancaffee
allancaffee / version.py
Created July 30, 2011 13:34
python git versioning tool
# -*- coding: utf-8 -*-
# Author: Douglas Creager <dcreager@dcreager.net>, Allan Caffee <allan.caffee@gmail.com>
# This file is placed into the public domain.
# Calculates the current version number. If possible, this is the
# output of “git describe”, modified to conform to the versioning
# scheme that setuptools uses. If “git describe” returns an error
# (most likely because we're in an unpacked copy of a release tarball,
# rather than in a git working copy), then we fall back on reading the
# contents of the RELEASE-VERSION file.
@allancaffee
allancaffee / deterministic_dingus.py
Created May 4, 2011 12:09
A potential deterministic dingus implementation (and test)
from dingus import Dingus
class DeterministicDingus(Dingus):
"""This dingus returns a different Dingus depending on the arguments it's called with.
It has the property of being purely deterministic (i.e. the same
arguments always return the same object). Unfortunately this
means that the behaviour of returning an identical `Dingus` when
called without arguments is lost.
@allancaffee
allancaffee / testcase.py
Created January 25, 2011 22:50
Demonstration of bug in mongokit custom type handling
import datetime
from mongokit import CustomType, Document, Connection
class CustomDate(CustomType):
mongo_type = unicode
python_type = datetime.datetime # optional, just for more validation
init_type = None # optional, fill the first empty value
def to_bson(self, value):
"""convert type to a mongodb type"""