A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
from __future__ import with_statement | |
from alembic import context | |
from sqlalchemy import engine_from_config, pool | |
from logging.config import fileConfig | |
from models import Base | |
config = context.config | |
fileConfig(config.config_file_name) |
import sys, marshal, functools, subprocess | |
child_script = """ | |
import marshal, sys, types; | |
fn, args, kwargs = marshal.load(sys.stdin) | |
marshal.dump( | |
types.FunctionType(fn, globals())(*args, **kwargs), | |
sys.stdout) | |
""" |
// a list of useful queries for profiler analysis. Starting with the most basic. | |
// 2.4 compatible | |
// | |
// output explained: | |
// | |
{ | |
"ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred | |
"op" : "query", // the operation type | |
"ns" : "game.players", // the db and collection |
function! PythonGetLabel() | |
if foldlevel('.') != 0 | |
norm! zo | |
endif | |
let originalline = getpos('.') | |
let lnlist = [] | |
let lastlineindent = indent(line('.')) | |
let objregexp = "^\\s*\\(class\\|def\\)\\s\\+[^:]\\+\\s*:" | |
if match(getline('.'),objregexp) != -1 | |
let lastlineindent = indent(line('.')) |
#define USE_ROBIN_HOOD_HASH 1 | |
#define USE_SEPARATE_HASH_ARRAY 1 | |
template<class Key, class Value> | |
class hash_table | |
{ | |
static const int INITIAL_SIZE = 256; | |
static const int LOAD_FACTOR_PERCENT = 90; | |
struct elem |
require 'benchmark' | |
require 'mysql2' | |
require 'yaml' | |
require 'json' | |
require 'msgpack' | |
client = Mysql2::Client.new(host: "localhost", username: "user", password: 'password', database: 'tests') | |
sql = 'SELECT * FROM table LIMIT 1000'; | |
results = client.query(sql, as: :array) |
"use strict"; | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
// ==== connect to database ==== | |
mongoose.connect('mongodb://localhost/temp'); | |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |