Skip to content

Instantly share code, notes, and snippets.

View spjwebster's full-sized avatar

Steve Webster spjwebster

View GitHub Profile
@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 / 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 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 / 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 / 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 / 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

-- 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 / 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>
@spjwebster
spjwebster / __init__.py
Created May 8, 2014 08:13
Redis-based session handler for Flask
# Set session handler
app.session_interface = RedisSessionInterface()
function augment(parent, properties) {
var child = properties.constructor || function() {
return parent.apply(this, arguments);
};
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
for (var key in properties) {