This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.authentication import Authentication | |
class DjangoAuthentication(Authentication): | |
"""Authenticate based upon Django session""" | |
def is_authenticated(self, request, **kwargs): | |
return request.user.is_authenticated() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v1_api = Api(api_name='v1') | |
v1_api.register(BookResource()) | |
# Intentionally left out PageResource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
OlderNewer