Skip to content

Instantly share code, notes, and snippets.

class AppendOnlyModelMeta(DeclarativeMeta):
@staticmethod
def _get_append_only_attributes(cls):
'''A helper method to get a list of append-only attributes
declared on the class.'''
[...]
def __init__(cls, classname, bases, dict_):
if hasattr(cls, '__history_class__'):
cls._history_fields = cls._get_append_only_attributes(cls)
verisign,PayPal Payflow Pro,Lucre
paypaldirect,PayPal direct,lucre
paypalexpress,PayPal Express,offsite
paypaladaptive,PayPal,asynchronous
paypaladaptiveb2b,PayPal,asynchronous
from pretenders.server.server import run
import multiprocessing
ml = multiprocessing.Process(name='ml', target=run)
ml.start()
def _init():
from pretenders.client.http import HTTPMock

MySQL demystified

How does MySQL execute queries?

  • SQL => Parse Tree => Execution plan
  • The execution plan is a data structure, not byte-code
  • The executor makes storage engine calls

Execution plan

"Deep left tree" -- always

Explain output columns

Request handling models

Abstraction layer

  • What is wsgi

PEP3333, a web server gateway interface, specifies how web server should communicate with web applications and how web applications can be chained together to process one request

  • Benefit?
** Reason for termination ==
** {{badmatch,
{{msg_status,13,
<<247,153,167,208,33,41,98,109,106,45,132,14,79,220,50,7>>,
{basic_message,
{resource,<<"/.../trunk">>,exchange,<<"...">>},
[<<"cardapp.txnfailed">>],
{content,60,none,
<<248,0,16,97,112,112,108,105,99,97,116,105,111,110,47,106,115,111,
110,5,117,116,102,45,56,0,0,0,0,2,0>>,
@kevinjqiu
kevinjqiu / hexspeak.py
Created April 22, 2011 03:04
hexspeak.py
def words():
with open('/usr/share/dict/words', 'r') as f:
return (x.strip().upper() for x in f.readlines())
MAPPING = {'A':'A', 'B':'B', 'C':'C', 'D':'D',
'E':'E', 'F':'F', 'O':'0', 'S':'5', 'I':'1'}
def main():
is_hexword = lambda word: all(ch in MAPPING for ch in word)
for word in filter(is_hexword, words()):
@kevinjqiu
kevinjqiu / wibblefish.clj
Created September 15, 2011 04:20
wibblefish in Clojure
(defn fizzbuzz []
(map #(cond (= 0 (mod % 15)) "wibblefish" (= 0 (mod % 3)) "wibble" (= 0 (mod % 5)) "fish" :else %) (range 1 101)))
@kevinjqiu
kevinjqiu / monty_hall.py
Created October 4, 2011 18:00
empirically prove monty hall
import random
import sys
def pick(switch):
doors = ['car', 'goat', 'goat']
random.shuffle(doors)
choices = zip(range(len(doors)), doors)
my_choice = random.choice(choices)
rest_choices = filter(lambda x: x!=my_choice, choices)
@kevinjqiu
kevinjqiu / jsontidy.py
Created March 27, 2012 21:19
jsontidy
#! /usr/bin/env python
import sys
import json
print json.dumps(json.loads(sys.stdin.read()), sort_keys=True, indent=4)