Skip to content

Instantly share code, notes, and snippets.

Scott Adams 7wonders

  • Stockholm
Block or report user

Report or block 7wonders

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@7wonders
7wonders / guardian_authorization.py
Last active Aug 3, 2016
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.
View guardian_authorization.py
import logging
from tastypie.authorization import DjangoAuthorization
from tastypie.exceptions import Unauthorized
from guardian.core import ObjectPermissionChecker
logger = logging.getLogger(__name__)
@7wonders
7wonders / gist:6254309
Created Aug 16, 2013
Creating a simple bluetooth serial port on pretty much any flavour of linux
View gist:6254309
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
@7wonders
7wonders / NSObject+IsEmpty.m
Last active Dec 21, 2015
NSObject category based on wil shipleys classic isEmpty code. very handy.
View NSObject+IsEmpty.m
#import "NSObject+IsEmpty.h"
@implementation NSObject (IsEmpty)
- (BOOL)isEmpty
{
return self == nil
|| (self == [NSNull null])
|| ([self respondsToSelector:@selector(length)]
&& [(NSData *) self length] == 0)
@7wonders
7wonders / authentication.py
Last active Dec 20, 2015
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.
View authentication.py
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):
You can’t perform that action at this time.