- L1 cache reference
0.5 ns
- Branch mispredict
5 ns
(on a bad CPU architecture you're pretty much screwed) - L2 cache reference
7 ns
- Mutex lock/unlock
25 ns
- Main memory reference
100 ns
- Compress 1K bytes with Zippy
3,000 ns
- Send 2K bytes over 1 Gbps network
20,000 ns
- Read 1 MB sequentially from memory
250,000 ns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from datetime import datetime | |
from mongoengine import * | |
from mongoengine.queryset import QuerySet | |
class BugFixTest(unittest.TestCase): | |
def setUp(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "edit", | |
"children": | |
[ | |
{ | |
"id": "sublime_highlight", | |
"caption": "Highlight", | |
"children": | |
[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.ext.mongoengine import MongoEngine | |
app = Flask(__name__) | |
app.config.from_pyfile('the-config.cfg') | |
db = MongoEngine(app) # Pass the app | |
db.init_app(app) # Initiate the app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fabric | |
from fabric.api import env | |
from functools import wraps | |
############################################################################### | |
# Decorators | |
############################################################################### | |
def limit_roles(*role_list): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import simplejson | |
from pymongo.dbref import DBRef | |
from pymongo.objectid import ObjectId | |
class MongoEngineEncoder(simplejson.JSONEncoder): | |
"""Handles Encoding of ObjectId's""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExtendedEmbeddedDocumentField(BaseField): | |
"""An embedded document field attaches the owner_document to field, | |
when pulled from the database. | |
""" | |
def to_python(self, value): | |
if not isinstance(value, self.document_type): | |
embedded = self.document_type._from_son(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.conf import settings | |
import unittest | |
from mongoengine import * | |
from django.template.defaultfilters import length | |
from django.template import Context, Template | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import session, g | |
current_user = LocalProxy(get_user) # Global access to the current user | |
def get_user(): | |
""" | |
A proxy for the User model | |
Is used as a `LocalProxy` so is context local. | |
Uses the `g` object to cache the `User` instance which prevents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A decorator for management commands (or any class method) to ensure that there is | |
only ever one process running the method at any one time. | |
Requires lockfile - (pip install lockfile) | |
Author: Ross Lawley | |
""" | |
import time |