Skip to content

Instantly share code, notes, and snippets.

View amjith's full-sized avatar
🐐

Amjith Ramanujam amjith

🐐
View GitHub Profile
@amjith
amjith / PrintParser.py
Created November 12, 2010 07:06
Python script to parse user input to a list of numbers
#!/usr/bin/env python
def convert(inp):
"""
* Get the input from user.
* Parse the input to extract numbers
** Split by comma
*** Each item in the list will then be split by '-'
**** Populate the number between a-b using range(a,b)
>>> convert("")
[]
@amjith
amjith / profile_func.py
Created October 13, 2011 04:22
Profiling decorator
def profile_func(filename=None):
def proffunc(f):
def profiled_func(*args, **kwargs):
import cProfile
import logging
logging.info('Profiling function %s' % (f.__name__))
try:
profiler = cProfile.Profile()
retval = profiler.runcall(f, *args, **kwargs)
profiler.dump_stats(filename or '%s_func.profile' % (f.__name__))
@amjith
amjith / hello.py
Created July 5, 2012 20:16
Simple WSGI App
from time import sleep
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
@newrelic.agent.wsgi_application()
def hello_world(environ, start_response):
path = environ.get('PATH_INFO')
if path.startswith('/slow'):
for _ in range(9):
@amjith
amjith / framework_web.py
Created August 14, 2012 00:16
instrument_webpy
import sys
import newrelic.api.transaction
import newrelic.api.function_trace
import newrelic.api.in_function
import newrelic.api.out_function
import newrelic.api.pre_function
import newrelic.api.name_transaction
from newrelic.api.object_wrapper import callable_name
from newrelic.api.web_transaction import WSGIApplicationWrapper
import sys
import newrelic.api.transaction
import newrelic.api.function_trace
import newrelic.api.in_function
import newrelic.api.out_function
import newrelic.api.pre_function
import newrelic.api.name_transaction
from newrelic.api.object_wrapper import callable_name
from newrelic.api.web_transaction import WSGIApplicationWrapper
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:
@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')
@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 / 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