Skip to content

Instantly share code, notes, and snippets.

View amjith's full-sized avatar
🐐

Amjith Ramanujam amjith

🐐
View GitHub Profile
@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 / 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
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
# 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
from contextlib import contextmanager
import sys
@contextmanager
def export():
print "Enter:"
yield
print sys._getframe(2).f_locals
print "Exit"
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
@amjith
amjith / file_list.py
Last active August 29, 2015 14:23
List of files.
>>> collection = ['django_migrations.py',
'django_admin_log.py',
'main_generator.py',
'migrations.py',
'api_user.doc',
'user_group.doc',
'accounts.txt',
]
>>> import re # regex module from standard library.
>>> def fuzzyfinder(user_input, collection):
suggestions = []
pattern = '.*'.join(user_input) # Converts 'djm' to 'd.*j.*m'
regex = re.compile(pattern) # Compiles a regex.
for item in collection:
match = regex.search(item) # Checks if the current item matches the regex.
if match:
suggestions.append(item)
return suggestions
'main_generator.py' - 0
'migrations.py' - 0
'django_migrations.py' - 7
'django_admin_log.py' - 9
>>> import re # regex module from standard library.
>>> def fuzzyfinder(user_input, collection):
suggestions = []
pattern = '.*'.join(user_input) # Converts 'djm' to 'd.*j.*m'
regex = re.compile(pattern) # Compiles a regex.
for item in collection:
match = regex.search(item) # Checks if the current item matches the regex.
if match:
suggestions.append((match.start(), item))
return [x for _, x in sorted(suggestions)]