Skip to content

Instantly share code, notes, and snippets.

View ianstormtaylor's full-sized avatar
🖖

Ian Storm Taylor ianstormtaylor

🖖
View GitHub Profile
@ianstormtaylor
ianstormtaylor / Makefile
Last active August 29, 2015 14:02
This is the normal way that Duo tests would be created for modules. It's testing the logic inside the module itself, but it's not testing the actual "built" file.
build-test.js: index.js test.js
duo test.js > build-test.js
test: build-test.js
mocha build-test.js
@ianstormtaylor
ianstormtaylor / Makefile
Last active August 29, 2015 14:02
This is what we would do with Analytics.js tests, since we actually want to be testing the physical built file itself, we're actually a layer above Duo because we're trying to test the Duo build process, which normal module testing shouldn't concern itself with. Use `-` in filenames instead of `/` since Gist has limitations.
build: index.js
duo index.js --global analytics > analytics.js
test: index.js test-index.js
duo test-index.js > test-build.js
open test-index.html # which adds both builds via <script> tags
@ianstormtaylor
ianstormtaylor / gist:2519665
Created April 28, 2012 14:57
Enhanced Backbone.Router route function to handle trailing slashes and query strings.
// Enhanced route function that automatically binds variant routes.
route : function (route, name, callback) {
var variants = [
route,
route + '/',
route + '?:querystring',
route + '/?:querystring'
];
@ianstormtaylor
ianstormtaylor / backbone_extensions.js
Created April 30, 2012 13:51 — forked from szimek/backbone_extensions.js
Mongo-style reduce for Backbone collections.
// Reduce collection using provided conditions
// e.g. FriendList.where({age: 30, gender: 'male'})
// Returns object of the same "class", so it's possible to chain methods
Backbone.Collection.prototype.where = function(conditions) {
return new this.constructor(_(conditions).reduce(function(memo, value, key) {
memo = _(memo).filter(function(model) {
return model.get(key) === value;
});
return memo;
}, this.models));
// javascripts/libs/underscore/underscore.min.js
// The actual underscore library.
...
// javascripts/libs/underscore.js
// A "module" that we require elsewhere.
@ianstormtaylor
ianstormtaylor / base.router.js
Created September 19, 2012 04:16
Enhanced Backbone Router to make a lot of things easier.
define([
'underscore',
'backbone'
],
function (_, Backbone) {
return Backbone.Router.extend({
// Variants of the routes to be automatically bound to. This way you
@ianstormtaylor
ianstormtaylor / kissmetrics.js
Last active December 14, 2015 06:49
Here's how to easily convert your KISSmetrics calls to Segment.io calls.
/**
* Identify
*
* KISSmetrics' identify and set calls turn into an analytics.identify call.
*/
_kmq.push(['identify', 'USER_ID_HERE']);
_kmq.push(['set', {
name : 'Achilles',
email : 'user@example.com'
@ianstormtaylor
ianstormtaylor / trackLink.js
Last active December 15, 2015 00:18
How to track multiple links and add link-specific properties for the event by using a callback method.
@ianstormtaylor
ianstormtaylor / wordpress-tracking.php
Created March 17, 2013 23:00
Tracking additional events from the Segment.io WordPress library, directly in PHP.
$event = 'Event Name';
$properties = array(
'title' => single_post_title('', false)
);
Analytics::track($event, $properties);