Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am timblair on github.
  • I am timblair (https://keybase.io/timblair) on keybase.
  • I have a public key whose fingerprint is 00B7 B4C9 C77C 3E30 F381 0B80 45B2 84B3 AC7A 6D2F

To claim this, I am signing this object:

@timblair
timblair / youre.js
Created January 26, 2015 10:35
youre.js
module.exports = function (robot) {
robot.hear(/ (?:is )(\w+ ?){1,6}/i, function (msg) {
if (Math.random() < 0.001) {
var match = msg.match[0].trim().replace(/^is /,"");
msg.send("You're " + match);
}
});
};
@timblair
timblair / decoder.rb
Last active August 29, 2015 14:16
RFC 5322-compliant Message ID generator
require "date"
class MessageID
module Decode
STAMP_FIELD_FORMAT = "%Y%m%d%H%M%S%N"
def self.decode(id)
user, host = id.split("@")
parts = user.split(".").map { |part| part.to_i(36) }
stamp, ident = parts.shift, []
@timblair
timblair / event-listener
Last active August 29, 2015 14:16
Simple RabbitMQ message listener
#!/usr/bin/env ruby
require "bunny"
abort "Usage: #{$0} BINDING_KEY [BINDING_KEY, ...]" if ARGV.empty?
conn = Bunny.new("amqp://development.vm:5672")
conn.start
channel = conn.create_channel
exchange = channel.exchange("event", no_declare: true)
@timblair
timblair / rbenv-update-bundler.sh
Last active August 29, 2015 14:23
Use rbenv? Need to update All The Rubies™ because of Bundler's BUNDLED_WITH change? Then use this script.
#!/bin/bash
eval "$(rbenv init -)"
CURRENT_RUBY=$(rbenv version-name)
LATEST_BUNDLER=$(curl -s https://rubygems.org/api/v1/versions/bundler/latest.json | cut -d'"' -f 4)
echo "Latest Bundler version: $LATEST_BUNDLER"
for RUBY_VERSION in $(rbenv versions --bare); do
rbenv shell "$RUBY_VERSION"
if $(gem list -i bundler); then
@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)>