Skip to content

Instantly share code, notes, and snippets.

View jzempel's full-sized avatar

Jonathan Zempel jzempel

  • Zendesk
  • California
View GitHub Profile
@jzempel
jzempel / org.mongo.mongod.plist
Created July 5, 2011 16:38
Mongo Launch Daemon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongo.mongod</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
@jzempel
jzempel / test.html
Created June 22, 2012 19:56
Flask Hard Crash
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
{% for category, message in get_flashed_messages(with_categories=true) %}
<div>{{ message }}</div>
{% endfor %}
<form action="{{ url_for("post") }}" method="post">
@jzempel
jzempel / test.py
Created June 22, 2012 20:23
Flask and Flask-Babel Exception
from flask import session
from flask.ext.babel import lazy_gettext
from traceback import format_exc
import os
import pickle
text = lazy_gettext('foo')
repr(text) # "lu'foo'"
text.value # u'foo'
text.__getattribute__('value') # u'foo'
@jzempel
jzempel / test.py
Created June 22, 2012 20:45
Flask and Flask-Babel Exception (simplified)
from flask.ext.babel import lazy_gettext
import os
import pickle
text = lazy_gettext('foo')
pickle.dump(text, open('lazy.string', 'wb'))
broken = pickle.load(open('lazy.string', 'rb'))
os.remove('lazy.string')
broken._kwargs # Traceback ... RuntimeError: maximum recursion depth exceeded while calling a Python object
@jzempel
jzempel / lru_cache.py
Created July 21, 2012 19:05
LRU Cache
# -*- coding: utf-8 -*-
"""
LRU Cache.
:author: Jonathan Zempel
"""
from threading import Lock
from unittest import main, TestCase
@jzempel
jzempel / survivor.py
Created July 22, 2012 19:40
Duck, Duck, Survivor
def survivor(count):
if count >= 2:
survivors = range(1, count + 1)
start = 1
last = survivors[-1]
while len(survivors) > 1:
survivors = survivors[start::2]
start = 1 if last == survivors[-1] else 0
last = survivors[-1]
@jzempel
jzempel / application:__init__.py
Created July 29, 2012 20:37
Flask with Celery 3.0
from blueprint import example
from extensions import mail
from flask import Flask
import settings
def create_app(settings=settings):
ret_val = Flask(__name__)
ret_val.config.from_object(settings)
# initialize extensions...
@jzempel
jzempel / application:__init__.py
Created July 29, 2012 21:19
Flask with Celery (wish list)
from blueprint import example
from extensions import celery, mail
from flask import Flask
import settings
def create_app(settings=settings):
ret_val = Flask(__name__)
ret_val.config.from_object(settings)
# initialize extensions...
@jzempel
jzempel / utils.py
Created September 8, 2012 22:02
Constant Diff
def diff(module1, module2):
"""Determine the difference in constant definitions between two modules.
:param module1: First module with constants.
:param module2: Second module with constants.
"""
_and = {}
_or = {}
_xor = {module1: {}, module2: {}}
@jzempel
jzempel / utils.py
Created September 8, 2012 22:06
Constant Duplicates
import re
def duplicates(module):
"""Determine if the given module contains multiple definitions for the
same constant.
:param module: The module to check.
"""
ret_val = set()