Skip to content

Instantly share code, notes, and snippets.

@dannyroa
dannyroa / ncaaf.json
Created November 10, 2012 17:59
NCAA Football Scores
{"sports" :[{"name" :"football","id" :20,"leagues" :[{"name" :"NCAA Football","abbreviation" :"college-football","id" :23,"groupId" :99,"shortName" :"NCAA Football","events" :[{"id" :323150130,"date" :"2012-11-10T17:00:00Z","season" :{"year" :2012,"type" :2,"description" :"regular","startDate" :"2012-08-28T07:00:00Z","endDate" :"2012-12-18T07:59:59Z"},"timeValid" :true,"competitions" :[{"id" :323150130,"date" :"2012-11-10T17:00:00Z","stats" :{"attendance" :0},"competitors" :[{"type" :"team","score" :28,"homeAway" :"home","team" :{"id" :130,"homeAway" :"home","location" :"Michigan","name" :"Wolverines","nickname" :"Michigan","abbreviation" :"MICH","color" :"001531","links" :{"api" :{"teams" :{"href" :"http://api.espn.com/v1/sports/football/college-football/teams/130"}}},"record" :{"summary" :"6-3","wins" :6,"losses" :3,"overtimeLosses" :0,"ties" :0}}},{"type" :"team","score" :31,"homeAway" :"away","team" :{"id" :77,"homeAway" :"away","location" :"Northwestern","name" :"Wildcats","nickname" :"N'western","abbre
@dannyroa
dannyroa / nba.json
Created November 10, 2012 21:36
NBA Scores
{"sports" :[{"name" :"basketball","id" :40,"leagues" :[{"name" :"National Basketball Assoc.","abbreviation" :"nba","id" :46,"groupId" :7,"shortName" :"NBA","events" :[{"id" :400277801,"date" :"2012-11-11T00:00:00Z","season" :{"year" :2013,"type" :2,"description" :"regular","startDate" :"2012-10-30T07:00:00Z","endDate" :"2013-04-18T06:59:59Z"},"timeValid" :true,"competitions" :[{"id" :400277801,"date" :"2012-11-11T00:00:00Z","stats" :{"attendance" :0},"competitors" :[{"type" :"team","score" :0,"homeAway" :"home","team" :{"id" :28,"homeAway" :"home","location" :"Toronto","name" :"Raptors","abbreviation" :"TOR","color" :"CE0F41","links" :{"api" :{"teams" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/28"}}},"record" :{"summary" :"1-4","wins" :1,"losses" :4,"overtimeLosses" :0,"ties" :0}}},{"type" :"team","score" :0,"homeAway" :"away","team" :{"id" :20,"homeAway" :"away","location" :"Philadelphia","name" :"76ers","abbreviation" :"PHI","color" :"000000","links" :{"api" :{"teams" :{"href" :"http://a
@dannyroa
dannyroa / normalize_file_path.py
Last active December 11, 2015 10:49
• all single dot components of the path must be removed. For example, "foo/./bar" should be normalized to "foo/bar". • all double dots components of the path must be removed, along with their parent directory. For example, "foo/bar/../baz" should be normalized to "foo/baz".
def normalize_file_path(path):
#assumptions: valid path does not start with '../' or '/..'
if path.startswith('../') or path.startswith('/..'):
return None
#normalize all the double dots first
def normalize_file_path(path):
#assumptions: valid path does not start with '../' or '/..'
if path.startswith('../') or path.startswith('/..'):
return None #alternatively, raise an exception
#normalize all the double dots first
@dannyroa
dannyroa / backends.py
Last active December 11, 2015 11:58
'code' should only be used once. Once the 'code' is used to obtain the 'access_token', store the 'access_token' to the session. Use 'access_token' if available in the session.
from django.contrib.auth.models import User
from facebookconnect.models import FacebookProfile
from django.conf import settings
from django.core.urlresolvers import reverse
import facebook
from facebookconnect.utils import facebook_login_check, get_access_token
class FacebookConnectBackend:
"""
class FacebookBackend:
"""
Authenticates against django.contrib.auth.models.User.
"""
@ staticmethod
def authenticate(request):
if 'access_token' in request.session:
# Sorting a List using Mergesort in Python
# 2011-05-16
def mergeSort(toSort):
if len(toSort) <= 1:
return toSort
mIndex = len(toSort) / 2
left = mergeSort(toSort[:mIndex])
right = mergeSort(toSort[mIndex:])
def get_val():
words = { 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven'
, 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen'
, 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen'
, 19 : 'nineteen', 20 : 'twenty', 30 : 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty'
, 70 : 'seventy', 80 : 'eighty', 90 : 'ninety', 100 : 'hundred', 1000 : 'thousand' }
@dannyroa
dannyroa / gist:5528998
Created May 6, 2013 23:08
fake camera & gallery for android
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
@dannyroa
dannyroa / access_token.py
Last active December 18, 2015 01:28
google oauth2 login
def get_access_token(request):
token = request.GET.get('token', None)
if not token:
return HttpResponse('error')
users = GlassUser.Query.all().eq(token=token)