Skip to content

Instantly share code, notes, and snippets.

View amjith's full-sized avatar
🐐

Amjith Ramanujam amjith

🐐
View GitHub Profile
import wrapt
class NotFlask():
def __init__(self):
self.routes = {}
#def route(self, route_str):
#@wrapt.decorator
#def decorator(f, instance, args, kwargs):
#self.routes[route_str] = f
from contextlib import contextmanager
import sys
@contextmanager
def export():
print "Enter:"
yield
print sys._getframe(2).f_locals
print "Exit"
# Part of a package named foo.
__all__ = []
def export(defn):
"""Decorator to explicitly mark functions that are exposed in a lib."""
globals()[defn.__name__] = defn
__all__.append(defn.__name__)
return defn
set -g -x PATH $HOME/bin /usr/local/bin $PATH /usr/X11/bin
set -g -x TERM xterm-256color
# Rbenv settings
set -gx RBENV_ROOT /usr/local/var/rbenv
. (rbenv init -|psub)
# Docker boot2docker
set -g -x DOCKER_CERT_PATH /Users/amjith/.boot2docker/certs/boot2docker-vm
set -g -x DOCKER_TLS_VERIFY 1
@amjith
amjith / gist:746c9dc52a1c54021736
Created January 5, 2015 01:19
pip fails to launch
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2912, in <module>
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 550, in _build_master
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 563, in _build_from_requirements
keys2.append(dist.key)
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 742, in resolve
@amjith
amjith / bg_task.py
Created November 23, 2013 00:14
Example newrelic background job context manager.
import newrelic.agent
newrelic.agent.initialize('staging.ini')
newrelic.agent.register_application(timeout=10.0)
def add(a, b):
return a + b
def sub(a, b):
return a - b
@amjith
amjith / obfuscate_deobfuscate.py
Created July 24, 2013 05:22
Obfuscate/Deobfuscate
from __future__ import print_function
import base64
import six
#def _encode(name, key):
#s = []
#for i in range(len(name)):
#s.append(chr(ord(name[i]) ^ ord(key[i % len(key)])))
#return s
@amjith
amjith / wsgi_app.py
Created June 4, 2013 00:09
WSGI app to test the NR disable/enable.
from time import sleep
from webtest import TestApp
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
def hello_world(environ, start_response):
path = environ.get('PATH_INFO')
if path.startswith('/slow'):
@amjith
amjith / gist:5499230
Created May 1, 2013 23:40
Example Tornado
import tornado.ioloop
import tornado.web
import os
HERE = os.path.dirname(__file__)
class MainHandler(tornado.web.RequestHandler):
def get(self):
#self.render(HERE+'fileuploadform.html')
self.render('/Users/amjith/playground/python/tornado/async_api/fileuploadform.html')
import sys
from newrelic.api.function_trace import FunctionTrace
from newrelic.api.object_wrapper import ObjectWrapper
from newrelic.api.transaction import current_transaction
from newrelic.api.pre_function import wrap_pre_function
def wrap_handle_exception(*args):
transaction = current_transaction()
if transaction: