Skip to content

Instantly share code, notes, and snippets.

View pomack's full-sized avatar

Aalok Shah pomack

  • Raleigh, NC
  • 03:29 (UTC -05:00)
View GitHub Profile
@pomack
pomack / decorators.py
Created April 30, 2012 02:03
decorators example
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.4 fallback.
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.middleware import csrf
from django.utils.decorators import available_attrs
@pomack
pomack / decorators_usage.py
Created April 30, 2012 02:06
decorators usage example
from phoenix.views.api.communication.template.standard import standard_view
__all__ = ('list_view',)
@json_login_required(allowed_methods=('GET', 'HEAD'))
def list_view(request, section='id', id=None):
return standard_view(request, section=section, id=id)
@pomack
pomack / bson_to_python_file.py
Created June 13, 2013 23:57
Convert a MongoDB BSON file to a python file that can be imported.
#!/usr/bin/env python
import argparse
import bson
import datetime
import struct
import sys
INDENT_SPACES = ' '
def read_bson_file(file, as_class=dict, tz_aware=True, uuid_subtype=bson.OLD_UUID_SUBTYPE):
@pomack
pomack / http_echo_and_proxy_server.py
Created August 9, 2013 14:42
A simple python HTTP server that either serves as a proxy or as an echo server. If working as an echo server, it outputs the headers and body into log output and to the client, which is useful when debugging a reverse proxy or caching server to see what is being sent. If working as a proxy server, it outputs what the request headers will be to t…
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import StringIO
import argparse
import logging
import os
import random
import sys
import urllib2
var standardSettings = {
'imageGetJson': '/api/v1/json/upload/images/list/@@company_id@@/?t=redactor',
'imageUpload': '/api/v1/json/upload/images/company/@@company_id@@/',
'source': false,
'css': '/static/survey/take/css/survey.css',
'minHeight': 100,
'buttons': [
'html', '|', 'formatting', '|', 'bold', 'italic', 'underline', '|',
'unorderedlist', 'orderedlist', 'outdent', 'indent', '|',
'image', 'table', 'link', '|',
@pomack
pomack / bash-shell-prompt.sh
Created February 21, 2014 15:04
Displays current time, username, host, and path with a comment to start to allow copying/pasting multi-line bash scripts
PS1="\e[01;33m# \e[01;36m\D{%Y-%m-%d %R %Z} \e[00;31m\u\e[01;32m@\e[00;31m\H \e[01;33m\w :\e[00m\n"
export PS1
function ngBindOutToAttribute(element, attributes, attribName, scope, scopeSource, initialize) {
var elementScope = element.scope(),
attribField = attributes[attribName],
valGetter = $parse(attributes[attribName]),
valSetter = valGetter.assign,
scopeGetter = $parse(scopeSource),
scopeSetter = scopeGetter.assign;
if(angular.isUndefined(scopeGetter(scope) && (angular.isUndefined(initialize) || initialize === true))) {
scopeSetter(scope, valGetter(elementScope));
}