Skip to content

Instantly share code, notes, and snippets.

View spjwebster's full-sized avatar

Steve Webster spjwebster

View GitHub Profile
@spjwebster
spjwebster / SelectionListViewController.h
Created February 22, 2009 19:20
A generic selection list UITableViewController subclass, revised from Jeff LaMarche's original.
//
// SelectionListViewController.h
//
// Created by Jeff LaMarche on 2/18/09.
// Revised by Steve Webster on 2/22/09.
//
#import <UIKit/UIKit.h>
@protocol SelectionListViewControllerDelegate <NSObject>
-- activate screensaver
tell application "ScreenSaverEngine" to activate
set screensaver_running to true
set away_message to "Gone fishing"
-- pause itunes if running
tell application "System Events" to set iTunesRunning to (number of items in (processes whose name is "iTunes") is greater than 0)
if iTunesRunning then
tell application "iTunes" to pause
end if
@spjwebster
spjwebster / gist:1074866
Created July 10, 2011 19:19
Firefox (SpiderMonkey) doesn’t hoist function declarations in blocks

Firefox (SpiderMonkey) doesn’t hoist function declarations in blocks

We include a third-party JavaScript library on our pages so we can run A/B and multivariate testing, and this code requires at least jQuery 1.4.0. Unfortunately we have more than a few dark corners of our site that are still dependent on an old (1.2.x) version of jQuery, so I had to find a way to detect the version of jQuery and not invoke the A/B testing code if we didn’t have the appropriate version.

Since we’re dealing with third party library, I didn’t really want to customise the code to add jQuery version detection as I’d have to do it all over again whenever the library is updated. Also, the library consists of global function declarations interspersed with fragments of immediately executed code that calls those functions, and I didn’t fancy refactoring the fragments just to add version detection.

Never mind, I thought. We include this library, along with the test data relevant to the current page, in a JavaScript bundle file ge

@spjwebster
spjwebster / Solarized Dark.taskpapertheme
Created October 11, 2011 20:53
Custom Solarized TaskPaper theme
<theme>
<!-- Solarized color definitions -->
<color id="base03" red="0" green="0.168627" blue="0.211765" alpha="1.0" />
<color id="base02" red="0.027451" green="0.211765" blue="0.258824" alpha="1.0" />
<color id="base01" red="0.345098" green="0.431373" blue="0.458824" alpha="1.0" />
<color id="base00" red="0.396078" green="0.482353" blue="0.513725" alpha="1.0" />
<color id="base0" red="0.513725" green="0.580392" blue="0.588235" alpha="1.0" />
<color id="base1" red="0.576471" green="0.631373" blue="0.631373" alpha="1.0" />
<color id="base2" red="0.933333" green="0.909804" blue="0.835294" alpha="1.0" />
<color id="base3" red="0.992157" green="0.964706" blue="0.890196" alpha="1.0" />
@spjwebster
spjwebster / scale.js
Created October 13, 2011 21:59
Linear scaling via function currying, from domain to arbitrary range. Inspired by protovis.
function scale( domainMin, domainMax ) {
var rangeMin = 0;
var rangeMax = 100;
var f = function( value ) {
var r = (value - domainMin) / (domainMax - domainMin);
return rangeMin + (r * (rangeMax - rangeMin));
}
f.domain = function( newDomainMin, newDomainMax ) {
@spjwebster
spjwebster / 001_query.sql
Created November 20, 2011 22:02
Analysis of jQuery googleapis.com usage based on HTTP Archive stats
SELECT COUNT(DISTINCT pageid), URL
FROM requests
WHERE url LIKE 'https://ajax.googleapis.com/ajax/libs/jquery/%'
OR url LIKE 'http://ajax.googleapis.com/ajax/libs/jquery/%'
GROUP BY url
ORDER BY count DESC;
@spjwebster
spjwebster / 001_query.sql
Created November 22, 2011 21:46
Analysis of jQuery aspnetcdn.com usage based on HTTP Archive stats
SELECT url, COUNT(DISTINCT pageid) AS count
FROM requests
WHERE url LIKE 'https://ajax.aspnetcdn.com/ajax/jQuery/%'
OR url LIKE 'http://ajax.aspnetcdn.com/ajax/jQuery/%'
GROUP BY url
ORDER BY count DESC;
@spjwebster
spjwebster / 001_query.sql
Created November 22, 2011 21:48
Analysis of jQuery code.jquery.com usage based on HTTP Archive stats
SELECT url, COUNT(DISTINCT pageid) AS count
FROM requests
WHERE url LIKE 'https://code.jquery.com/jquery-%'
OR url LIKE 'http://code.jquery.com/jquery-%'
GROUP BY url
ORDER BY count DESC;
@spjwebster
spjwebster / gist:4354116
Created December 21, 2012 17:06
Dynamic font loading for iOS
// From http://www.marco.org/2012/12/21/ios-dynamic-font-loading
NSData *inData = /* your decrypted font-file data */;
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error)
NSLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
@spjwebster
spjwebster / gist:5432925
Created April 22, 2013 06:59
wildshroom player locations
Manix84: 232, 54, 194
samriley: 274, 64, 276
MatthewvanBuuren: -81, 70, 72
nefarioustim: -28, 97, 886
spjwebster: 480, 64, 858