Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
/*
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) {
Author.objects.extra(select={
'book_count': """
SELECT COUNT(*)
FROM books_book
WHERE books_book.author_id = books_author.id
"""
})
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):
<h1>Authors</h1>
<ul>
{% for author in author_list %}
<li>{{ author }}: {{ author.book_set.count }} books</li>
{% endfor %}
</ul>
<ul>
{% for author in author_list %}
<li>{{ author }}: {{ author.book_count }} books</li>
{% endfor %}
</ul>
class Author(Model):
name = CharField(max_length=100)
class Book(Model):
title = CharField(max_length=100)
author = ForeignKey(Author)
/*
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')";
}
# 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
// 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) {
(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,