Skip to content

Instantly share code, notes, and snippets.

View ScottEAdams's full-sized avatar

Scott Adams ScottEAdams

View GitHub Profile
@ScottEAdams
ScottEAdams / guardian_authorization.py
Last active August 3, 2016 22:01
A django-tastypie Authorization Class that uses django-guardian for row level permission checking. This is a version of https://gist.github.com/airtonix/5476453 that adds an extra "generic_post_check" as the item check was failing when trying to post a new object and makes filters work with lists.
import logging
from tastypie.authorization import DjangoAuthorization
from tastypie.exceptions import Unauthorized
from guardian.core import ObjectPermissionChecker
logger = logging.getLogger(__name__)
@ScottEAdams
ScottEAdams / gist:6254309
Created August 16, 2013 23:10
Creating a simple bluetooth serial port on pretty much any flavour of linux
scott@scott:~$ sudo hcitool scan
Scanning ...
00:81:22:78:00:67 MY780067
scott@scott:~$ sudo rfcomm bind /dev/rfcomm1 00:81:22:78:00:67 1
scott@scott:~$ ls -l /dev/rfcomm1
crw-rw---- 1 root dialout 216, 1 Aug 17 01:00 /dev/rfcomm1
@ScottEAdams
ScottEAdams / NSObject+IsEmpty.m
Last active December 21, 2015 04:19
NSObject category based on wil shipleys classic isEmpty code. very handy.
#import "NSObject+IsEmpty.h"
@implementation NSObject (IsEmpty)
- (BOOL)isEmpty
{
return self == nil
|| (self == [NSNull null])
|| ([self respondsToSelector:@selector(length)]
&& [(NSData *) self length] == 0)
@ScottEAdams
ScottEAdams / authentication.py
Last active December 20, 2015 22:59
Two similar ways for doing email based authentication for tastypie. Based on a mixture of BasicAuthentication and userena email login. Good for when using USERENA_WITHOUT_USERNAMES = True.
import base64
from django.contrib.auth import get_user_model, authenticate
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from tastypie.authentication import Authentication
from tastypie.http import HttpUnauthorized
class TastyEmailAuthentication(Authentication):
def __init__(self, realm='django-tastypie', **kwargs):