Skip to content

Instantly share code, notes, and snippets.

@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:
"""
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 / 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
@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 / 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 / soccer.json
Created November 10, 2012 17:57
soccer scores
This file has been truncated, but you can view the full file.
{
"sports": [{
"name": "soccer",
"id": 600,
"leagues": [{
"name": "Primera Divisi\u00F3n de Argentina",
"abbreviation": "arg.1",
"id": 745,
"groupId": 1,
"shortName": "Primera A",
import socket
if socket.gethostname() == 'productionserver.com':
DEBUG = False
else:
DEBUG = True
urlpatterns = patterns('django.views.generic.simple',
(r'^foo/$', 'direct_to_template', {'template': 'foo_index.html'}),
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}),
)
@dannyroa
dannyroa / settings.py
Created October 22, 2012 23:05
project directory
import os
PROJECT_DIR = os.path.dirname(__file__)
...
STATIC_DOC_ROOT = os.path.join(PROJECT_DIR, "static")
...
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, "templates"),
)
@dannyroa
dannyroa / scrolling tricks.java
Created October 13, 2012 19:05
scrolling trick
/*
* Copyright 2012 Roman Nurik + Nick Butcher
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software