This file contains 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
/* | |
Geolocation with HTML5, falling back to Google Ajax APIs. | |
http://marcgrabanski.com/article/html5-geolocation-fallback-google-ajax-api | |
*/ | |
<script src="http://www.google.com/jsapi?key=YOUR_API_KEY"></script> | |
<script> | |
var myLocation; // global variable to store lat/lng | |
if (navigator && navigator.geolocation) { | |
// HTML5 GeoLocation | |
function getLocation(position) { |
This file contains 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
Author.objects.extra(select={ | |
'book_count': """ | |
SELECT COUNT(*) | |
FROM books_book | |
WHERE books_book.author_id = books_author.id | |
""" | |
}) |
This file contains 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
class AuthorManager(Manager): | |
def get_query_set(self): | |
return super(AuthorManager, self).get_query_set().extra(select={ | |
'book_count': """ | |
SELECT COUNT(*) | |
FROM books_book WHERE | |
books_book.author_id = books_author.id""" | |
}) | |
class Author(Model): |
This file contains 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
class Author(Model): | |
name = CharField(max_length=100) | |
class Book(Model): | |
title = CharField(max_length=100) | |
author = ForeignKey(Author) |
This file contains 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
/* | |
Cross-browser CSS Gradients. Works in IE6+ | |
*/ | |
#nav a { | |
background: -moz-linear-gradient(top, #c8106e, #87114f); | |
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #87114f),color-stop(1, #c8106e)); | |
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#c8106e', endColorstr='#87114f'); | |
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#c8106e', endColorstr='#87114f')"; | |
} |
This file contains 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
# Lower bound of Wilson score confidence interval | |
def ci_lower_bound(pos, n, power=0.10) | |
return 0 if n == 0 | |
z = Statistics2.pnormaldist(1-power/2) | |
phat = 1.0*pos/n | |
(phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) | |
end |
This file contains 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
// You can access a function from within itself using `arguments.callee` | |
function same() { | |
console.log(same == arguments.callee); | |
} | |
same(); // => true | |
// Functions have name and length attributes. | |
// `func.length` returns the number of formal arguments the function accepts. | |
function awesome(a, b, c) { |
This file contains 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
(function($) { | |
$.fn.thePlugin = function(options) { | |
// build main options before element iteration: | |
var opts = $.extend({}, $.fn.thePlugin.defaults, options); | |
var $this = $(this); | |
var thePlugin = { | |
index: 0, |