Skip to content

Instantly share code, notes, and snippets.

View gorakhargosh's full-sized avatar

Yesudeep Mangalapilly gorakhargosh

View GitHub Profile
from tipfy import RequestHandler
from tipfyext.jinja2 import Jinja2Mixin
from tipfy.sessions import SessionMiddleware
class ChromeFrameMiddleware(object):
"""
Middleware that enables the Google Chrome frame plugin or IE edge
rendering engine.
"""
def after_dispatch(self, handler, response):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Facebook
# Copyright (C) 2010, 2011 Tipfy.org
# Copyright (C) 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@gorakhargosh
gorakhargosh / urlparse.py
Created June 28, 2011 23:29
This is the state of urlparse in Python code.
try:
# Python 3.
from urllib.parse import urlparse, urlunparse, parse_qs, quote, unquote_plus
except ImportError:
# Python 2.5+
from urlparse import urlparse, urlunparse
from urllib import quote, unquote_plus
try:
# Python 2.6+
from urlparse import parse_qs
@gorakhargosh
gorakhargosh / oauth
Created June 29, 2011 22:49
OAuth 1.0 Client in simple words
Authorization in simple words:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Construct a client with its client credentials.
2. Send an HTTP request for temporary credentials with a callback URL
which the server will call with an OAuth verification code.
3. Parse out temporary credentials from a successful server response.
4. Using the temporary credentials build an authorization URL and
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Facebook
# Copyright (C) 2010, 2011 Tipfy.org
# Copyright (C) 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Facebook
# Copyright (C) 2010, 2011 Tipfy.org
# Copyright (C) 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
def generate_random_string(bit_strength=64, decimal=False):
"""
Generates a random ASCII-encoded unsigned integral random number in decimal
or hexadecimal representation.
:param bit_strength:
Bit strength.
:returns:
A string representation of a randomly-generated ASCII-encoded
hexadecimal/decimal-representation unsigned integral number
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Facebook
# Copyright (C) 2010, 2011 Tipfy.org
# Copyright (C) 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
from pyoauth.oauth1 import Credentials
from pyoauth.oauth1.client import Client
client_credentials = Credentials(
identifier="CONSUMER KEY",
shared_secret="CONSUMER SECRET"
)
@gorakhargosh
gorakhargosh / python-pylint.el
Created July 13, 2011 01:16 — forked from ieure/python-pylint.el
Run pylint on Python source in Emacs.
;;; python-pylint.el --- minor mode for running `pylint'
;; Copyright (c) 2009, 2010 Ian Eure <ian.eure@gmail.com>
;; Author: Ian Eure <ian.eure@gmail.com>
;; Keywords: languages python
;; Last edit: 2010-02-12
;; Version: 1.01