Skip to content

Instantly share code, notes, and snippets.

View catacgc's full-sized avatar

Catalin Costache catacgc

View GitHub Profile
import mongoengine
class MongoModelSerializer(serializers.ModelSerializer):
def get_default_fields(self):
cls = self.opts.model
opts = get_concrete_model(cls)
#pk_field = opts.pk
fields = []
fields += [getattr(opts, field) for field in opts._fields]
#fields += [field for field in opts.many_to_many if field.serialize]
@catacgc
catacgc / gist:6791011
Created October 2, 2013 09:05
Python - parse a specific argument
import sys
import argparse
def get_env():
parser = argparse.ArgumentParser()
parser.add_argument('--env', default='active')
opts, remaining = parser.parse_known_args()
print opts.env
#!/usr/bin/env python
#install: pip install redis
import redis
r1 = redis.StrictRedis(host='localhost', port=6379, db=1)
r2 = redis.StrictRedis(host='localhost', port=6379, db=2)
hash_name = 'hash:setting:view'
@catacgc
catacgc / Serialization benchmarks
Created October 27, 2012 14:39
Simple benchmark testing the serialization alternatives of a large object
<?php
ini_set('memory_limit', '2G');
$data = new MyObject(3000000);
benchmark('msgpack', 'msgpack_pack', 'msgpack_unpack', $data);
benchmark('serialize', 'serialize', 'unserialize', $data);