Skip to content

Instantly share code, notes, and snippets.

View d6veteran's full-sized avatar

Will Curran d6veteran

  • Google, D20Mob, SuperKablamo
  • Seattle, WA
View GitHub Profile
import itertools
def findPhoneNumbers(phone_name):
PHONE_LENGTH = 10
allowed_numbers = ["1","2","3","4","5","6","7","8","9","0"]
# Get all permutations for positions not taken by phone name
match_length = PHONE_LENGTH - len(phone_name)
matches = itertools.permutations(allowed_numbers ,match_length)
@d6veteran
d6veteran / gist:984122
Created May 21, 2011 01:22
Multiple Custom Markers for Google Maps
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(36.14, -115.14);
var myLatlng = new google.maps.LatLng(36.14,-115.14);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
@d6veteran
d6veteran / gist:916056
Created April 12, 2011 18:12
Score Lists
<!-- HIGH SCORES -->
<div class="block">
<div class="score-block">
<div class="block-header">
<h2>High Scores</h2>
</div>
{% if high_scores %}
{% for s in high_scores %}
<div class="tiny-score">
<div class="player">
@d6veteran
d6veteran / gist:801431
Created January 29, 2011 02:18
Freebase Query for BGG IDs using cursor
[{
"cursor": true,
"id": null,
"type": "/games/game",
"mid": null,
"key": {
"namespace": "/user/pak21/boardgamegeek/boardgame",
"value": null,
"optional": false
}
@d6veteran
d6veteran / gist:797387
Created January 26, 2011 20:30
Dereference Reference Properties in Batch Get()
def prefetch_refprops(entities, *props):
fields = [(entity, prop) for entity in entities for prop in props]
ref_keys = [prop.get_value_for_datastore(x) for x, prop in fields]
ref_entities = dict((x.key(), x) for x in db.get(set(ref_keys)))
for (entity, prop), ref_key in zip(fields, ref_keys):
prop.__set__(entity, ref_entities[ref_key])
return entities
@d6veteran
d6veteran / gist:774644
Created January 11, 2011 16:17
Custom filter for Webapp templates: match item to items in List
from google.appengine.ext.webapp import template
from django import template as django_template
def in_list(value, arg):
"""
Given an item and a list, check if the item is in the list.
Usage:
{% if item|in_list:list %}
in list
{% else %}
@d6veteran
d6veteran / gist:760090
Created December 30, 2010 18:24
Using urllib2 for POSTing
#!/usr/bin/python
####
# 02/2006 Will Holcomb <wholcomb@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
@d6veteran
d6veteran / gist:749192
Created December 20, 2010 23:09
Getting Spiel Des Jahres Winners
query = [{
"type": "/games/game",
"id": None,
"name": None,
"!/award/award_honor/honored_for": {
"award": {
"id": "/en/spiel_des_jahres"
},
"year": {
"value": None,
@d6veteran
d6veteran / gist:746044
Created December 18, 2010 02:05
Using mql extended to call out to extended data - in this case a weblink.
[{
"id": "/en/settlers_of_catan",
"/common/topic/weblink": [{
"description": "BoardGameGeek",
"url": null
}]
}]
@d6veteran
d6veteran / gist:745671
Created December 17, 2010 20:42
Freebase schema for Type /games/game
{
"code": "/api/status/ok",
"result": [{
"attribution": [
"/user/metaweb"
],
"creator": [
"/user/metaweb"
],
"derivative_games": [