Skip to content

Instantly share code, notes, and snippets.

David King davbo

  • London, UK.
Block or report user

Report or block davbo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
davbo /
Created May 8, 2012
Mocking django managers
from import IndexView, Feed
from unittest import TestCase
class TestMocking(TestCase):
def test_mock_count(self):
Feed.objects = Mock()
feeds = [Feed(url=''), Feed(url='http://bar.baz')]
mock_queryset = Mock(return_value=feeds)
mock_queryset.count.return_value = 42
Feed.objects.all = mock_queryset
View gist:2907505
>>> class IdentifierList(list):
... def by_namespace(self):
... return None
>>> class Locality():
... @property
... def identifiers(self):
... return IdentifierList(self._identifiers)
... @identifiers.setter
... def identifiers(self, value):
View gist:2907608
>>> class Old():
... pass
>>> class New(object):
... pass
>>> type(Old())
<type 'instance'>
>>> type(New())
<class '__main__.New'>
davbo /
Created Jun 26, 2012
Install ElasticSearch on Ubuntu 12.04
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
davbo /
Created Aug 15, 2012
Content negotiation
from flask import Blueprint
from .helpers import template_or_json
from .views import ServiceView, register_mimetype
places = Blueprint('places', __name__, template_folder='templates')
davbo /
Created Oct 3, 2012
Stop watching WebLearn repos
import requests
auth = (USER, PASS)
for repo in requests.get('', params={'per_page': 100}, auth=auth).json:
if repo['name'].startswith('wl-'):
requests.delete('' % (repo['owner']['login'], repo['name']), auth=auth)
davbo / gist:5670378
Created May 29, 2013
Museums app JSON snippet
View gist:5670378
"opening_hours":"Tuesday to Friday: 12-5pm; Saturday: 10am-5pm; Sunday: 2-5pm; Monday: Closed",
davbo /
Created May 29, 2013
Preloads JSON & images for our University Museums offline JavaScript applicaiton
import json
import urllib2
import os
import codecs
from urlparse import urlparse
from string import Template
build_dir = os.environ['TARGET_FOLDER']
davbo / preloaded.js
Created May 29, 2013
Replaces any preloaded images with locally cached version
View preloaded.js
define(['underscore'], function(_) {
return {
replace: function (images) {
// Look for the image in our preloaded images and replace
// the path if we find it.
var preload = window.preload || {};
_.each(images, function (val, key) {
if (_.has(preload, val)) {
images[key] = preload[val];
davbo / blogs.opml.xml
Last active Apr 25, 2016
Programming blogs
View blogs.opml.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<title>Programming blogs</title>
<outline text="Developer blogs" title="Developer blogs">
<outline type="rss" text="flak rss" title="flak rss" xmlUrl="" htmlUrl=""/>
<outline type="rss" text="Kamal Marhubi" title="Kamal Marhubi" xmlUrl="" htmlUrl=""/>
You can’t perform that action at this time.