Skip to content

Instantly share code, notes, and snippets.

@klipstein
klipstein / b64field.py
Created November 22, 2010 12:25
Base64 file handling for django-tastypie
import base64
import os
from tastypie.fields import FileField
from django.core.files.uploadedfile import SimpleUploadedFile
class Base64FileField(FileField):
"""
A django-tastypie field for handling file-uploads through raw post data.
It uses base64 for en-/decoding the contents of the file.
Usage:
@bohde
bohde / authentication.py
Created December 24, 2010 15:17
Django based auth for Tastypie
from tastypie.authentication import Authentication
class DjangoAuthentication(Authentication):
"""Authenticate based upon Django session"""
def is_authenticated(self, request, **kwargs):
return request.user.is_authenticated()
@zyegfryed
zyegfryed / gist:814432
Created February 7, 2011 14:25
Tastypie OAuth
from oauth2 import Error
from django.utils.translation import ugettext as _
from tastypie.authentication import Authentication
from oauth_provider.utils import initialize_server_request, send_oauth_error, get_oauth_request
from oauth_provider.consts import OAUTH_PARAMETERS_NAMES
from oauth_provider.store import store, InvalidTokenError
@colinsullivan
colinsullivan / django-tastypie_user-profile-field.py
Created April 12, 2011 17:13
This is a django-tastypie resource field that incorporates the Django user profile into a model resource for a `User` transparently.
###
# This field is used on the user model to transparently add stuff from the
# user profile object into the user resource.
#
# Copyright (c) 2012 Colin Sullivan <colinsul [at] gmail.com>
# Licensed under the MIT License.
###
class UserProfileManyToManyField(fields.ManyToManyField):
###
# We will override the dehydrate method so when we're trying to dehydrate
@tschellenbach
tschellenbach / Django Mock Request Object.py
Created April 18, 2011 12:54
Fake django requests for testing purposes
from django.core.handlers.base import BaseHandler
from django.test.client import RequestFactory
class RequestMock(RequestFactory):
def request(self, **request):
"Construct a generic request object."
request = RequestFactory.request(self, **request)
handler = BaseHandler()
handler.load_middleware()
for middleware_method in handler._request_middleware:
@bohde
bohde / api.py
Created May 18, 2011 14:19
Example of ToMany resources in Django Tastypie
v1_api = Api(api_name='v1')
v1_api.register(BookResource())
# Intentionally left out PageResource
@miratcan
miratcan / cups.py
Created June 8, 2011 21:53 — forked from huseyinyilmaz/cups.py
my solution for 40 cups and 9 oranges problem.
#!/usr/bin/python3.2
from itertools import combinations
"""
You have 40 bowls, all placed in a line at exact intervals of 1 meter. You also have 9 oranges. You wish to place all the oranges in the bowls, no more than one orange in each bowl, so that there are no three oranges A, B, and C such that the distance between A and B is equal to the distance between B and C. How many ways can you arrange the oranges in the bowls?.
(http://www.bittorrent.com/company/about/developer_challenge)
"""
def find_count(orange_count=9,cup_count=40,start_point=0,l=[]):
"""
orange_count: how many oranges should be placed in cups. for our question it is 9.
cup_count: how many cups should be used
@miratcan
miratcan / pivotal2github.py
Created June 29, 2011 16:47
Simple script for migrating from pivotaltracker to github
from github2.client import Github
from csv import reader as CsvReader
# FILL INFORMATION BELOW
# your username at github
GITHUB_USERNAME = ""
# your api token, you can find it at https://github.com/account/admin
GITHUB_API_TOKEN = ""
@miratcan
miratcan / komikaze.py
Created June 30, 2011 18:34
a Crawler for komikaze.net
"""
Mirat Can Bayrak / 2009
"""
from urllib import urlopen, urlretrieve
from datetime import date as Date
from datetime import timedelta
from xml.dom import minidom
from os.path import basename
import re
@melissaboiko
melissaboiko / nostalgic.py
Created July 13, 2011 13:45
simple matrix-style demo. done out of nostalgia for what it was like to study linux in the 90s.
#!/usr/bin/env python
import locale
import curses as c
from curses.wrapper import wrapper
import random
locale.setlocale(locale.LC_ALL,'')
coding = locale.getpreferredencoding()
random.seed()
# more = use digits more often