Skip to content

Instantly share code, notes, and snippets.

@timblair
timblair / counter.js
Created December 28, 2008 00:47
Simple JavaScript in-page counter
var Counter = {
_c: {},
get: function(c) { return Counter._c[c] || 0; },
set: function(c, v) { Counter._c[c] = v; return v; },
inc: function(c, v) { return Counter.set(c, Counter.get(c) + (v || 1)); },
dec: function(c, v) { return Counter.inc(c, (v ? -v : -1)); }
};
/**
* Usage:
@timblair
timblair / pinger.js
Created January 9, 2009 16:18
Simple JS which polls a given script eveny X seconds, using an image rather than Ajax-style request.
Pinger = function(opts) { for (var o in opts) { this.config[o] = opts[o]; } }
Pinger.prototype = {
running: false,
config: {
host : document.location.host,
secure : (document.location.protocol == "https:"),
script : '',
interval : 300 // interval time in seconds
},
start: function() { this.running = true; this.schedule(); },
@timblair
timblair / Safe cfinclude from within cached component functions
Created April 15, 2009 10:30
A hack-tastic way of safely including arbitrary templates in a function contained within a cached ColdFusion component
<cffunction name="myFunc">
<!--
What's going on here? Basically, any <cfinclude>d view files run within the scope
of this function, which means any variables used are effectively unscoped in terms
of the component. Because we're caching the view component it means we could end up
with nasty race conditions. By var-ing a new 'variables' scope it effectively
localises any variable usage (scoped or unscoped) within both the function call and
any included files. We also make a reference to the original (component) 'variables'
scope in to a new named 'scope' called 'global', so any calls to functions within
@timblair
timblair / osx_global_zoom_keyboard_shortcut.sh
Created June 3, 2009 12:56
Set a global keyboard shortcut (CMD-CTRL-Z) for apps which have a 'zoom' or 'zoom window' menu option.
#!/bin/bash
defaults write NSGlobalDomain NSUserKeyEquivalents '{"Zoom" = "@^Z"; "Zoom Window" = "@^Z"; }'
@timblair
timblair / mxunit-assert-equals-case-sensitivity.diff
Created June 22, 2009 08:54
Patch to allow case-sensitive text matching as part of assertEquals() in mxunit.
Index: framework/Assert.cfc
===================================================================
--- framework/Assert.cfc (revision 1148)
+++ framework/Assert.cfc (working copy)
@@ -128,21 +128,23 @@
<cfargument name="expected" type="any" required="yes" hint="The expected string value" />
<cfargument name="actual" type="any" required="yes" hint="The actual string value" />
<cfargument name="message" required="false" default="This test failed" hint="Custom message to print in the failure." />
+ <cfargument name="caseSensitive" type="boolean" required="false" default="false" hint="If set to TRUE checks the original string unaltered. Default is to check the string in lowercase" />
<cfset arguments = normalizeArguments("equals",arguments)>
@timblair
timblair / caveatPatchor.js
Created February 15, 2011 10:27 — forked from protocool/caveatPatchor.js
Sample caveatPatchor.js file for use in Propane 1.1.2 and above: pulls avatars from Gravatar
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
LoadModule passenger_module /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/passenger-3.0.6/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/passenger-3.0.6
PassengerRuby /opt/ruby-enterprise-1.8.7-2011.03/bin/ruby
@timblair
timblair / gist:942151
Created April 26, 2011 12:09
National Rail really is run by a bunch of monkeys...
$ curl --silent -i http://ojp.nationalrail.co.uk/ | grep 'Powered-By'
X-Powered-By: An infinite number of monkeys
@timblair
timblair / proxy.rb
Created June 29, 2011 10:09
Simple HTTP proxy for strangely formatted localhost requests, as used by certain native mobile apps.
# Incredibly simple HTTP proxy that takes `GET` requests of the form
#
# http://127.0.0.1:12345/www.domain.com/path/to/resource
#
# and proxies to
#
# http://www.domain.com/path/to/resource
#
# All body content and headers are passed through untouched.
#
@timblair
timblair / markit
Created June 29, 2011 16:04
Uses the `markdown` command-line tool to build an HTML doc.
#!/usr/bin/env ruby
# A simple wrapper to the command-line `markdown` tool which wraps
# HTML header and footer, including any style references you choose.
require 'open3'
require 'erb'
# Define the ERB template to wrap the HTML content in.
template = ERB.new <<-EOS