Skip to content

Instantly share code, notes, and snippets.

View rene-armida's full-sized avatar

Michael Rene Armida rene-armida

View GitHub Profile
name 2014-05-01 00:00:00+00:00 2014-06-01 00:00:00+00:00 2014-07-01 00:00:00+00:00 2014-08-01 00:00:00+00:00 2014-09-01 00:00:00+00:00 2014-10-01 00:00:00+00:00 2014-11-01 00:00:00+00:00 2014-12-01 00:00:00+00:00 2015-01-01 00:00:00+00:00 2015-02-01 00:00:00+00:00 2015-03-01 00:00:00+00:00 2015-04-01 00:00:00+00:00 2015-04-23 00:00:00+00:00
@rene-armida
rene-armida / exception_attrs.py
Last active December 11, 2015 03:58
Example of asserting properties of an exception caught by assertRaises / assert_raises. Run with `python -m unittest2 -v exception_attrs` from the same dir as the file.
import unittest2
# some code under test
def raise_msg(x):
raise ValueError('hello: %s' % x)
class SomeError(ValueError):
def __init__(self, x):
self.x = x
@rene-armida
rene-armida / matchers.feature
Created November 2, 2012 15:01
Behave pretty formatter raises AssertionError when handling nested regex groups
Feature: matchers
# passes fine
Scenario: regex, no nested groups, matching
Given that I am testing behave
When I try to use a regex matcher for unnested groups
Then I should have to call step_matcher
# both of the following trigger AssertionError
@rene-armida
rene-armida / paste_wsgi_example.py
Created September 26, 2012 07:16
Example Paste/WebOb/Routes WSGI app
'''
A minimal example of how to use Paste and WebOb to build a custom
WSGI app and serve it.
Depends on:
* paste - http://pypi.python.org/pypi/Paste
* webob - http://pypi.python.org/pypi/WebOb/1.1.1
* routes - http://pypi.python.org/pypi/Routes/1.12.3
I (marmida) still think this is less appropriate than using CouchDB; you'll need
@rene-armida
rene-armida / assert_raises_cm.py
Created August 9, 2012 00:31
Monkey patch: backport context manager support into nose.tools.assert_raises in python2.6
# code for monkey-patching
import nose.tools
# let's fix nose.tools.assert_raises (which is really unittest.assertRaises)
# so that it always supports context management
# in order for these changes to be available to other modules, you'll need
# to guarantee this module is imported by your fixture before either nose or
# unittest are imported
@rene-armida
rene-armida / solution_eval.py
Created April 27, 2012 20:37
A solution to Jon Erickson's math puzzle
# http://books.google.com/books?id=0FW3DMNhl1EC&lpg=PA1&ots=tt-xF-JWXq&dq=jon%20erickson%20art%20of%20exploitation%20math%20problem&pg=PA1#v=onepage&q=math%20problem&f=false
#
# Use each of the numbers 1, 3, 4, and 6 exactly once with any of the four basic math operations
# (addition, subtraction, multiplication, and division) to total 24. Each number must be used
# once and only once, and you may define the order of operations; for example, 3 * (4 + 6) + 1 = 31
# is valid, however incorrect, since it doesn't total 24.
from fractions import Fraction
import itertools
@rene-armida
rene-armida / patch_django_social_auth_oauth2_redirect_uri.py
Created March 6, 2012 03:22
Monkey patch: force django-social-auth's OAuth2 redirect_uris to start with 'https://'
from django.core.signals import request_started
from django.dispatch import receiver
# signals
@receiver(request_started)
def monkey_patch_redirect_uri(sender, **kwargs):
'''
Apply a cheesy hack to fix a glitch in social_auth:
* social_auth.backends.BaseOAuth2.__init__ calculates self.redirect_uri using request.build_absolute_uri
* django.http.request.build_absolute_uri uses the scheme of the current request