Skip to content

Instantly share code, notes, and snippets.

View craigds's full-sized avatar
👾
mildly amused

Craig de Stigter craigds

👾
mildly amused
View GitHub Profile
import pytest
from _pytest.python_api import ApproxBase
from _pytest.assertion.util import _compare_eq_dict
# Subclassing ApproxBase means we can patch into the pytest machinery for
# custom assertion error messages, since that class provides a `_repr_compare` method
# that is not present on any other types.
# https://github.com/pytest-dev/pytest/blob/556e075d23a91eb42821129a5d874ec3174e17ad/src/_pytest/assertion/util.py#L219
def diff_iterators(iter1, iter2):
"""
Yields every value that differs between two iterators, assuming they're ordered the same.
ie, given
iter1 = iter([1, 2, 5, 7, 9, 10, 12])
iter2 = iter([1, 3, 4, 5, 6, 9, 11])
yields:
2, 3, 4, 6, 7, 10, 11, 12
@craigds
craigds / create_lds_export.py
Created November 15, 2017 23:58
Sample python code for creating a simple export on LDS
# coding: utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import time
import koordinates

Keybase proof

I hereby claim:

  • I am craigds on github.
  • I am craigds (https://keybase.io/craigds) on keybase.
  • I have a public key ASD9-xLoSxRjbgeH8F-DvkQdtdsBmK9_6E8uiVhvL1yY9wo

To claim this, I am signing this object:

#!/usr/bin/env python
"""
Converts Internet Explorer 'capture network traffic' XML to a HAR file.
Turns out that XML is just a HAR file anyways, but in XML form. So this
just converts it to JSON, and Bob's your uncle.
Requires Python 2.7+ and LXML.
"""
from __future__ import unicode_literals
@craigds
craigds / MuteRadioAds.bookmarklet.js
Last active November 9, 2015 02:53 — forked from ireeymonse/MuteRdioAds.js
Mute Rdio Ads (bookmarklet)
javascript:(function()%7Bvar%20r%20%3D%20R.player%2C%20oVol%20%3D%20r.volume()%2C%20tf%20%3D%20r._onTrackFinished%2C%20ar%20%3D%20r._onAudioReady%2C%20n%20%3D%20r._next%3Br._onTrackFinished%20%3D%20function()%20%7Bconsole.log(%22iree%3AtrackFinished%3A%22%2Barguments)%3Bif%20(.001%20!%3D%3D%20r.volume())%7BoVol%20%3D%20r.volume()%3Br.volume(.001)%3B%7Dreturn%20tf.apply(this%2C%20arguments)%3B%7D%3Br._onAudioReady%20%3D%20function()%20%7Bconsole.log(%22iree%3AaudioReady%3A%22%2Br.playingAd())%3Bif%20(!r.playingAd())%7Br.volume(oVol)%3B%7Dreturn%20ar.apply(this%2C%20arguments)%3B%7D%3Bdocument.getElementById('header').style.backgroundColor%20%3D%20'blue'%7D)()
#!/usr/bin/env python
import mapnik
import random
import time
w,h = 16,16
img = mapnik.Image(w,h)
img.background = mapnik.Color("white")
@craigds
craigds / models.py
Last active December 26, 2015 04:08
our mptt category model that stores materialized URL for lookups
from fieldsignals import post_save_changed
from mptt.models import MPTTModel
class Category(MPTTModel):
parent = models.ForeignKey('self', null=True, blank=True, db_index=True)
name = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, db_index=True)
url = models.CharField(max_length=256, unique=True, db_index=True)
@craigds
craigds / gist:2594926
Created May 4, 2012 13:53
Output from https://gist.github.com/2594905 on django 1.3.1 (geos 3.2.0)
GEOSGeometry.wkt 'POINT (1 2)'
FAIL - expected: 'POINT (1 2 3)'
GEOSGeometry.ewkt 'POINT (1 2)'
FAIL - expected: 'POINT (1 2 3)'
GEOSGeometry.hex 'POINT (1 2)'
FAIL - expected: 'POINT (1 2 3)'
GEOSGeometry.wkb 'POINT (1 2)'
FAIL - expected: 'POINT (1 2 3)'
GEOSGeometry.ewkb 'POINT (1 2 3)'
#!/usr/bin/env python
import binascii
import json
import re
from osgeo import ogr
from django.contrib.gis.geos import Point
p = Point(1, 2, 3)
wkt = "POINT (1 2 3)"