Skip to content

Instantly share code, notes, and snippets.

View ianawilson's full-sized avatar

Ian A Wilson ianawilson

View GitHub Profile
@ianawilson
ianawilson / temporary_setting.py
Last active December 23, 2015 00:29
temporary setting decorator for testing
from functools import wraps
def temporary_setting(setting_name, value):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
from django.conf import settings
# save and disable the setting
old_value = getattr(settings, setting_name)
@ianawilson
ianawilson / test.py
Last active December 21, 2015 02:09
Demonstrating a problem with patching and the Tastypie api client.
from django.contrib.auth.models import User
from tastypie.test import ResourceTestCase
class Test(ResourceTestCase):
def test_patch(self):
user = User(username='username', email='test@test.com')
user.set_password('password')
user.save()
@ianawilson
ianawilson / gist:4708931
Last active December 12, 2015 03:39
Plugging functions in python
class Klass:
def foo(self):
print 'foo'
a = Klass()
a.foo()
_old_foo = Klass.foo
@ianawilson
ianawilson / Bootstrap.php
Created October 11, 2012 16:30
Cache initialization
protected function _initCache()
{
$frontend = array(
'lifetime' => null,
'automatic_serialization' => true
);
$backend = array(
'host' => 'localhost',
'port' => 11211,
@ianawilson
ianawilson / gist:3297517
Created August 8, 2012 18:52
rails / redmine debug logs
Processing IssuesController#create to json (for 10.4.5.251 at 2012-08-08 14:42:17) [POST]
Parameters: {"_json"=>"issue%5Bproject_id%5D=lasso&issue%5Bsubject%5D=api+test+issue&issue%5Bdescription%5D=testing+from+localhost%3A8000", "format"=>"json", "controller"=>"issues", "action"=>"create"}
Setting Columns (1.3ms) SHOW FIELDS FROM `settings`
SQL (0.5ms) SELECT max(`settings`.updated_on) AS max_updated_on FROM `settings`
Setting Load (0.4ms) SELECT * FROM `settings` WHERE (`settings`.`name` = 'rest_api_enabled') LIMIT 1
AnonymousUser Columns (1.3ms) SHOW FIELDS FROM `users`
AnonymousUser Load (0.3ms) SELECT * FROM `users` WHERE ( (`users`.`type` = 'AnonymousUser' ) ) LIMIT 1
Setting Load (0.3ms) SELECT * FROM `settings` WHERE (`settings`.`name` = 'login_required') LIMIT 1
Filter chain halted as [:find_project] rendered_or_redirected.
Completed in 30ms (View: 0, DB: 4) | 404 Not Found [http://dev.lasso.rochester.edu/issues.json]
@ianawilson
ianawilson / gist:3172462
Created July 24, 2012 20:33
lasso db error
[Tue Jul 24 16:00:01 2012] [error] Traceback (most recent call last):
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 117, in get_response
[Tue Jul 24 16:00:01 2012] [error] response = middleware_method(request, e)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response
[Tue Jul 24 16:00:01 2012] [error] response = callback(request, *callback_args, **callback_kwargs)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py", line 366, in wrapper
[Tue Jul 24 16:00:01 2012] [error] return self.admin_site.admin_view(view)(*args, **kwargs)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
[Tue Jul 24 16:00:01 2012] [error] response = view_func(request, *args, **kwargs)
[Tue Jul 24 16:00:01 2012] [error]
@ianawilson
ianawilson / gist:3172430
Created July 24, 2012 20:28
raven json problem with proxy objects
[Tue Jul 24 16:00:01 2012] [error] Traceback (most recent call last):
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/models.py", line 172, in actually_do_stuff
[Tue Jul 24 16:00:01 2012] [error] get_client().capture('Exception', exc_info=exc_info, request=request)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/client.py", line 94, in capture
[Tue Jul 24 16:00:01 2012] [error] result = super(DjangoClient, self).capture(event_type, **kwargs)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/raven/base.py", line 378, in capture
[Tue Jul 24 16:00:01 2012] [error] self.send(**data)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/client.py", line 114, in send
[Tue Jul 24 16:00:01 2012] [error] return super(DjangoClient, self).send(**kwargs)
[Tue Jul 24 16:00:01 2012] [error] File "/usr/local/lib/python
@ianawilson
ianawilson / sentry.conf
Created July 24, 2012 13:24
sentry upstart conf
expect fork
start on startup
exec sudo -u itslocal /srv/sentry/bin/sentry --config=/srv/sentry/sentry.conf.py start
# if we get both or neither, no good
if not (bool(timeAssignment) ^ bool(dropTake)):
raise DropError('drop() takes either a ' + self.family.RecurringTimeAssignment.__name__ + ' or ' + self.family.DropTake.__name__ + ' as an argument but not both nor neither')
if timeAssignment and not type(timeAssignment) == self.family.RecurringTimeAssignment:
raise TypeError('timeAssignment must be a ' + self.family.RecurringTimeAssignment.__name__)
if dropTake and not type(dropTake) == self.family.DropTake:
raise TypeError('dropTake must be a '+ self.family.DropTake.__name__)