Skip to content

Instantly share code, notes, and snippets.

View techiev2's full-sized avatar
🥷

Sriram Velamur techiev2

🥷
View GitHub Profile
function lookup(obj /*Object */, props/* String */){
if ( ! (obj && props)) { return undefined; }
var ps = props.split('.');
var pointer = obj;
var val = undefined;
var i = 0, len = ps.length;
for(;i<len;i++) {
@techiev2
techiev2 / object.py
Last active December 22, 2015 23:49
Mongoengine Query/Object creation wrapper
#!/usr/bin/env python
"""Object utils"""
# coding=utf-8
__author__ = 'Sriram Velamur'
import sys
sys.dont_write_bytecode = True
from mongoengine import (ValidationError, NotUniqueError,
@techiev2
techiev2 / mongo.py
Last active December 23, 2015 06:29
BaseDocument definition for Mongoengine documents
class BaseDocument(me.Document):
"""
Base document definition.
Defines the following attributes common to all derived models.
:attr created_at datetime: Creation time defaulting to UTC
:attr updated_at datetime: Updation time defaulting to UTC
Defines the following metadata for the derived models' support.
:attr allow_inheritance True: Required by Mongoengine.
@techiev2
techiev2 / view.py
Created September 17, 2013 13:37
BaseView
VIEW_ERRORS = {
'405': {
'status': 405,
'message': 'End point does not accept the method'
},
'404': {
'status': 404,
'message': '{0} not found'
},
@techiev2
techiev2 / controller.py
Last active December 23, 2015 06:29
Model Controller
class Handler(RequestHandler, object):
"""
Base request handler overridden with required decorators and data
members.
"""
def set_default_headers(self, *args, **kwargs):
"""Set API handler default headers"""
super(Handler, self).set_default_headers(*args, **kwargs)
self.set_header("Access-Control-Allow-Origin", "*")
@techiev2
techiev2 / bootstrap.py
Last active December 23, 2015 08:29
Bootstrapper for Tornadoweb with Object wrapper support
"""
Tornadoweb bootstrapper.
"""
import sys
sys.dont_write_bytecode = True
import os
from datetime import datetime
import re
# -*- coding: utf-8 -*-
"""
sphinx.application
~~~~~~~~~~~~~~~~~~
Sphinx application object.
Gracefully adapted from the TextPress system by Armin.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
@techiev2
techiev2 / gist:7351846
Last active December 27, 2015 15:59
MongoDB / PythonODM / Migrations
People who've been working with MongoDB, any suggestions on a migration tool for working with schema changes?
Something like South that is kind of the de facto standard with Django/migrations with Rails?
I saw a Node based gist earlier today but haven't checked it out though.
And for the context, this 3 year old ticket on Mongoengine's repository, the ODM we are currently working with.
A -1 and the repo maintainer's remarks on the request.
Migrations seem to be happening a lot and is usually a pain going through it with a solution that is otherwise seamless.
We would like to see if we can implement a parallel if any other developer has looked at it, irrespective of technology and port it
https://github.com/hmarr/mongoengine/issues/105
@techiev2
techiev2 / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@techiev2
techiev2 / mergelatestremote.sh
Last active April 30, 2017 21:07
Helper script to fetch the latest changed remote and merge to master.
#!/bin/bash
function getRemotes {
remotes=`git branch -r | grep -v HEAD`
local branches=""
for branch in $remotes; do
echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch;
done | sort -r | head -n 1 | awk '{print $7}'
echo $branches
}