Skip to content

Instantly share code, notes, and snippets.

View zmsmith's full-sized avatar

Zach Smith zmsmith

View GitHub Profile
@zmsmith
zmsmith / gist:9003152
Last active August 29, 2015 13:56 — forked from Bpless/gist:1771461
{
"_id" : ObjectId("4f15adc6e9f3d887f2ba7a31"),
"uid" : 274790,
"did" : 720717,
"city_id" : 4,
"score" : 10000,
"published" : ISODate("2012-01-17T17:20:54Z"),
"active" : true,
"recs" : [
{
@zmsmith
zmsmith / gist:9003143
Last active August 29, 2015 13:56 — forked from Bpless/gist:1771930
from mongoengine.base import TopLevelDocumentMetaclass
class CompressedKeyDocumentMetaclass(TopLevelDocumentMetaclass):
def __new__(cls, name, bases, attrs):
"""
MongoEngine Document Classes access the 'TopLevelDocumentMetaclass'
__metaclass__. We allow that metaclass to set attrs on the class
and then compress the fields in the event that the instantiated
Document Class contains the meta attr 'compress_keys'
@zmsmith
zmsmith / gist:9003138
Last active August 29, 2015 13:56 — forked from Bpless/gist:1772125
from test.app import DecisionDocument, TrialDocument
subdoc = DecisionDocument(guilt='definitely', details={'bad_person_score': 'Very Bad Man'})
doc = TrialDocument(decision=[subdoc], reporter='Tom', jury='peers')
doc.save()
# -----Object Created------
{
"_id" : ObjectId("4f32c2f4d0ba3a4b5e000000"),
@zmsmith
zmsmith / gist:9003137
Last active August 29, 2015 13:56 — forked from Bpless/gist:1772027
{
"_id" : {
"set" : ISODate("2012-02-08T18:37:52.191Z"),
"db_key" : "_id"
},
"decision" : {
"set" : ISODate("2012-02-08T18:37:52.191Z"),
"db_key" : "d",
"embedded_fields" : {
"guilt" : {
@zmsmith
zmsmith / gist:9003136
Last active August 29, 2015 13:56 — forked from Bpless/gist:1772013
{
"_id" : {
"set" : ISODate("2012-02-08T18:37:52.191Z"),
"db_key" : "_id"
},
"judge" : {
"set" : ISODate("2012-02-08T18:37:52.191Z"),
"db_key" : "j"
},
"decision" : {
from mongoengine.document import Document, EmbeddedDocument
class DecisionDocument(EmbeddedDocument):
guilt = fields.StringField(required=True)
details = fields.DictField()
meta = {'allow_inheritance': False}
@zmsmith
zmsmith / s3logs.py
Last active December 13, 2015 18:09
A inefficient but effective way to scan logs on s3
from __future__ import print_function
import StringIO
import gzip
from boto.s3.connection import S3Connection
conn = S3Connection("<key_id>", "<secret>")
bucket = conn.get_bucket('<bucket>')
@zmsmith
zmsmith / gist:4643655
Created January 26, 2013 18:25
Add spellchecking in Sublime Text 2 to Markdown files (assuming you don't already have Markdown specific settings).
echo '{
"spell_check": true,
"dictionary": "Packages/Language - English/en_US.dic"
}' > ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Markdown.sublime-settings
@zmsmith
zmsmith / thumb.py
Last active December 10, 2015 14:08
from django.conf import settings
from libthumbor import CryptoURL
def thumb(url, **kwargs):
'''
returns a thumbor url for 'url' with **kwargs as thumbor options.
Positional arguments:
url -- the location of the original image
@zmsmith
zmsmith / gist:3797402
Created September 28, 2012 01:06
Find URLs with underscores
import re
def find_underscores(patterns):
for pattern in patterns:
raw = pattern.regex.pattern
rr = re.sub('\(.*?\)', lambda x: '', raw)
if '_' in rr:
print pattern.regex.pattern
if hasattr(pattern, 'url_patterns'):
find_underscores(pattern.url_patterns)