Skip to content

Instantly share code, notes, and snippets.

View alastaircoote's full-sized avatar

Alastair Coote alastaircoote

View GitHub Profile
@alastaircoote
alastaircoote / gist:84c25191b18b3ec330a7
Last active August 29, 2015 14:15
User agent/referrer check
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'XX-XXXXXXX-XX', 'auto');
if (/\/FBIOS;/.test(navigator.userAgent) === true) {
ga('set', 'referrer', 'http://www.facebook.com/__ios_webview__');
@alastaircoote
alastaircoote / offlinetracker.js
Last active July 16, 2022 17:19
OfflineTracker as JS
var OfflineTrack,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
OfflineTrack = (function() {
function OfflineTrack(dataSendFunc) {
var e;
this.dataSendFunc = dataSendFunc;
this.pageVisibilityChanged = __bind(this.pageVisibilityChanged, this);
this.doOnlineOfflineCheck = __bind(this.doOnlineOfflineCheck, this);
this.sendData = __bind(this.sendData, this);
@alastaircoote
alastaircoote / offlinetrack.coffee
Last active August 29, 2015 13:57
Example code for tracking offline usage
class OfflineTrack
constructor: (@dataSendFunc) ->
# dataSendFunc is a function passed in to OfflineTrack to actually store
# this offline tracking data remotely - basically, I wanted to abstract this
# out so that anyone can use whatever tracking system they wish.
try
@alastaircoote
alastaircoote / jstest.cs
Last active December 31, 2015 23:09
Using iOS's JavascriptCore as a Web Worker of sorts
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.JavaScriptCore;
namespace jscoretest
{
public partial class jscore_testViewController : UIViewController
{
@alastaircoote
alastaircoote / starts_and_ends.sql
Last active December 17, 2015 23:09
Messy SQL query to get start and end figures for turnstile data
SELECT d.unit, d.scp, d.dt,
(SELECT s.dt FROM stats s WHERE s."desc" = 'REGULAR' AND s.unit = d.unit AND date(s.dt) = d.dt AND s.scp = d.scp AND EXTRACT(hour from s.dt) >= 3 ORDER BY s.dt LIMIT 1) AS start_time,
(SELECT s.exits FROM stats s WHERE s."desc" = 'REGULAR' AND s.unit = d.unit AND date(s.dt) = d.dt AND s.scp = d.scp AND EXTRACT(hour from s.dt) >= 3 ORDER BY s.dt LIMIT 1) AS start_exits,
(SELECT s.dt FROM stats s WHERE s."desc" = 'REGULAR' AND s.unit = d.unit AND date(s.dt) = d.dt AND s.scp = d.scp AND EXTRACT(hour from s.dt) >= 11 ORDER BY s.dt LIMIT 1) AS midday_time,
(SELECT s.exits FROM stats s WHERE s."desc" = 'REGULAR' AND s.unit = d.unit AND date(s.dt) = d.dt AND s.scp = d.scp AND EXTRACT(hour from s.dt) >= 11 ORDER BY s.dt LIMIT 1) AS midday_exits
FROM
(SELECT DISTINCT stats.unit, stats.scp, date(stats.dt) AS dt FROM stats)
as d
@alastaircoote
alastaircoote / processsubway.coffee
Last active December 17, 2015 23:08
Quick script to parse NYC subway turnstile data
# As the following indicates, this script replies on the csv and async npm modules.
# It reads all the files placed inside a "csvs" directory, in the same directory as this file.
csv = require "csv"
fs = require "fs"
async = require "async"
columns = ["C/A","UNIT","SCP","DATE1","TIME1","DESC1","ENTRIES1","EXITS1","DATE2","TIME2","DESC2","ENTRIES2","EXITS2","DATE3","TIME3","DESC3","ENTRIES3","EXITS3","DATE4","TIME4","DESC4","ENTRIES4","EXITS4","DATE5","TIME5","DESC5","ENTRIES5","EXITS5","DATE6","TIME6","DESC6","ENTRIES6","EXITS6","DATE7","TIME7","DESC7","ENTRIES7","EXITS7","DATE8","TIME8","DESC8","ENTRIES8","EXITS8"]
outputArray = ['"ca","unit","scp","dt","desc","entries", "exits"']
@alastaircoote
alastaircoote / gist:5384053
Created April 14, 2013 20:19
Hashchange event hook
var hashChange = function() {
var el = document.getElementById(window.location.hash.substr(1));
$(".activeTr").removeClass("activeTr").find("td").css({
"background":"",
"color":""
});
$(el).parent().addClass("activeTr").find("td").css({
"background":"#08c",
"color":"#fff"
@alastaircoote
alastaircoote / gist:1781404
Created February 9, 2012 17:27
Making the webview wrapper
var baseWindow = Titanium.UI.createWindow({
title: "",
barColor: "#232323",
title: "Front Page",
backgroundImage: "images/bgpattern_dark.png"
});
var mainWebView = Ti.UI.createWebView({
url:"html/index.html",
backgroundColor: "transparent",