Skip to content

Instantly share code, notes, and snippets.

@benfoxall
benfoxall / gist:1326272
Created October 30, 2011 18:54
Sparql postcode lookup
PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?lat ?long
WHERE {
<http://data.ordnancesurvey.co.uk/id/postcodeunit/OX30NG>
geo:long ?long;
geo:lat ?lat
}
// This fires an animation, but returns a
// deferred object rather than the jQuery object
$.fn.deferredAnimate = function( prop, speed, easing, callback ){
var dfr = $.Deferred();
// update the appropriate arguments
if(typeof speed === "object"){
speed.complete = withResolve(speed.complete);
} else {
@benfoxall
benfoxall / gist:1753574
Created February 6, 2012 17:40
A function for converting .NET dates in json responses
/*!
* $.convertJSONDates
*
* $.getJSON(…).pipe($.convertJSONDates).done(function(data){…})
*
* Based on …
*
* jQuery.parseJSON()
* http://erraticdev.blogspot.com/2010/12/converting-dates-in-json-strings-using.html
*
// There are some webkit issues:
// - chrome 18 - won't display svg paths with linecap="round" + dash-array="0,2"
// (http://code.google.com/p/chromium/issues/detail?id=21057)
//
// - safari (iOS5 only) - will badly mistranslate linecap=(not round) + dash-array=(anything)
//
// This 'fix' means that the dash array will not have any zero-width dashes so will work
// across those two webkit browsers.
if(paper.raphael.svg){
// also - applying this straight off doesn't seem to work with raphael so it needs
@benfoxall
benfoxall / tit-trip.js
Created April 16, 2012 21:18
Don't freak out Chris
// a placeholder for us to gather the steps with when
// we know what we want to do with them
var stepHandler;
// the actual function that will be called by the data section
function step(name, fn){
// if our handler has been assigned
if(stepHandler){
@benfoxall
benfoxall / gist:2421650
Created April 19, 2012 15:22
buttons jasmine
var Button = function(){
this.presses = 0;
}
Button.prototype.press = function(){
this.presses++;
}
describe('button', function(){
// this is out of 'beforeEach', becuase we want to
method create(colour){
class customClass{}
customClass.colour = colour;
return customClass;
}
RedClass = create('red');
GreenClass = create('red');
redInstance = new RedClass();
@benfoxall
benfoxall / gist:2498761
Created April 26, 2012 10:55
weird js includer
// include social media scripts
window.___gcfg = {lang: 'en-GB'};
(function include(id, src){
var s = 'script',js, fjs = document.getElementsByTagName(s)[0];
if (!document.getElementById(id)){
js = document.createElement(s); js.id = id;
js.src = src;
(function($){
$(function(){
var rnd = function(n){
return Math.floor((Math.random()*n*n)) % n
}
var elements_at = function(at){
return $('li:visible').filter(function(){
return $(this).css('left') == (at*350) + 'px';
(function(){
var props = {
js:true,
touch : 'ontouchstart' in window,
overflowScroll: document.documentElement && ('webkitOverflowScrolling' in document.documentElement.style),
iframe: window!=window.top
};
var cns = [];
for(var p in props){
if(props.hasOwnProperty(p)){