Skip to content

Instantly share code, notes, and snippets.


James McKinney jpmckinney

View GitHub Profile
jpmckinney / CWIL 2010 Attendees by Province or City.rb
Created Oct 26, 2010
Transforms attendee data into a KML file that can be uploaded to, e.g., GeoCommons
View CWIL 2010 Attendees by Province or City.rb
# coding: utf-8
require 'rubygems'
require 'date'
require 'pdf/reader'
require 'graticule'
require 'builder'
class String
def is_numeric?
jpmckinney / memcache_model.rb
Created Nov 1, 2010
ActiveModel class with Memcache backend
View memcache_model.rb
# blog post:
# No transactions or exceptions (yet).
module MemcacheModel
def self.included(base)
base.class_eval do
extend ActiveModel::Naming
extend ActiveModel::Translation
extend ActiveModel::Callbacks
extend MemcacheModel::ClassMethods
jpmckinney / keychain.rb
Created Nov 9, 2010
Access the OS X Keychain from Ruby
View keychain.rb
# blog post:
class KeyChain
def self.method_missing(meth, *args)
run args.unshift(meth)
def self.find_internet_password(*args)
# -g: Display the password for the item found
output = quiet args.unshift('find-internet-password', '-g')
jpmckinney / cinema.montreal.bookmarklet.js
Created Nov 25, 2010
Cinema Montreal theatre map bookmarklet
View cinema.montreal.bookmarklet.js
// blog post:
* jQuery JavaScript Library v1.4.4
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
jpmckinney / whois.rb
Last active Sep 24, 2015
Checks if a domain exists in all top-level domains
View whois.rb
# blog post:
name = "domain" # CHANGE THIS
require 'whois'
# deleted, unimplemented, or not in use: bv cs dd eh er gb sj ss yu
tlds = %w(aero asia biz cat com coop info int jobs mobi museum name net org post pro tel travel xxx) + # generic
%w(edu gov mil) + # USA
%w(arpa) + # infrastructure
jpmckinney / rinks.php
Created Dec 17, 2010
PHP parser for Ville de Montréal rink conditions PDFs
View rinks.php
// Original by: Philippe Dagenais-Pérusse
// Get the files to parse
if ($argc) { // Command-line interface
$files = array_slice($argv, 1);
else {
$files = array();
if ($handle = opendir($path)) {
jpmckinney / unpack.and.beautify.js
Created Dec 23, 2010
Unpack and beautify JavaScript
View unpack.and.beautify.js
// blog post:
// Assumes js_beautify is available: see
function unpack_and_beautify(value) {
var position = 0,
open_string = "eval(function(",
open_index = -1,
close_string = "'.split('|'),0,{}))",
close_index = -1,
close_length = close_string.length,
jpmckinney / js2c.rb
Created Dec 27, 2010
Convert between plain text JavaScript and C char array
View js2c.rb
# coding: utf-8
# blog post:
abort "usage: #{$0} filename.h\n #{$0} filename.js prefix" unless ARGV[0]
abort "ERROR: Couldn't open '#{ARGV[0]}' for reading" unless File.exist?(ARGV[0])
abort "ERROR: Prefix is required if input is JavaScript" if ARGV[0][/js$/] && !ARGV[1]
if ARGV[0][/js$/]
puts "const char #{ARGV[1]}_code[] = {\n #{[0]).unpack('U*').map{|i| i == 8212 ? [226, 128, 148] : i }.flatten.each_slice(16).map{ |a|{ |i| "0x%02x" % i }.join(',') }.join(",\n ") },0x00\n};"
jpmckinney / unpack_and_beautify.cpp
Created Dec 27, 2010
Unpack and beautify JavaScript from command-line
View unpack_and_beautify.cpp
// blog post:
#include <v8.h>
#include <string.h>
#include <stdlib.h>
#include "beautify.h"
#include "unpack_and_beautify.h"
#define BUF_SIZE 1024
jpmckinney / unpack_and_beautify.h
Created Dec 27, 2010
unpack_and_beautify.js as char array
View unpack_and_beautify.h
// blog post:
const char unpack_code[] = {