Skip to content

Instantly share code, notes, and snippets.

View jpmckinney's full-sized avatar

James McKinney jpmckinney

View GitHub Profile
@jpmckinney
jpmckinney / CWIL 2010 Attendees by Province or City.rb
Created October 26, 2010 21:55
Transforms attendee data into a KML file that can be uploaded to, e.g., GeoCommons
# coding: utf-8
require 'rubygems'
require 'date'
require 'pdf/reader'
require 'graticule'
require 'builder'
class String
def is_numeric?
@jpmckinney
jpmckinney / memcache_model.rb
Created November 1, 2010 19:25
ActiveModel class with Memcache backend
# blog post: http://blog.slashpoundbang.com/post/1455548868/memcachemodel-make-any-ruby-object-that-persists-in
# 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
jpmckinney / keychain.rb
Created November 9, 2010 02:56
Access the OS X Keychain from Ruby
# blog post: http://blog.slashpoundbang.com/post/1521530410/accessing-the-os-x-keychain-from-ruby
class KeyChain
def self.method_missing(meth, *args)
run args.unshift(meth)
end
def self.find_internet_password(*args)
# -g: Display the password for the item found
output = quiet args.unshift('find-internet-password', '-g')
@jpmckinney
jpmckinney / cinema.montreal.bookmarklet.js
Created November 25, 2010 16:50
Cinema Montreal theatre map bookmarklet
// blog post: http://blog.slashpoundbang.com/post/1573439856/google-maps-bookmarklet-for-cinema-clock
/*!
* jQuery JavaScript Library v1.4.4
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
@jpmckinney
jpmckinney / whois.rb
Last active September 24, 2015 11:57
Checks if a domain exists in all top-level domains
# blog post: http://blog.slashpoundbang.com/post/2346603512/checking-if-a-domain-exists-in-all-top-level-domains
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
jpmckinney / rinks.php
Created December 17, 2010 19:44
PHP parser for Ville de Montréal rink conditions PDFs
<?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
jpmckinney / unpack.and.beautify.js
Created December 23, 2010 07:46
Unpack and beautify JavaScript
// blog post: http://blog.slashpoundbang.com/post/2428557007/unpack-and-beautify-javascript
// Assumes js_beautify is available: see https://github.com/einars/js-beautify/raw/master/beautify.js
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
jpmckinney / js2c.rb
Created December 27, 2010 18:22
Convert between plain text JavaScript and C char array
# coding: utf-8
# blog post: http://blog.slashpoundbang.com/post/2488598258/running-javascript-from-the-command-line-with-v8
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 #{File.read(ARGV[0]).unpack('U*').map{|i| i == 8212 ? [226, 128, 148] : i }.flatten.each_slice(16).map{ |a| a.map{ |i| "0x%02x" % i }.join(',') }.join(",\n ") },0x00\n};"
else
@jpmckinney
jpmckinney / unpack_and_beautify.cpp
Created December 27, 2010 18:32
Unpack and beautify JavaScript from command-line
// blog post: http://blog.slashpoundbang.com/post/2488598258/running-javascript-from-the-command-line-with-v8
#include <v8.h>
#include <string.h>
#include <stdlib.h>
#include "beautify.h"
#include "unpack_and_beautify.h"
#define BUF_SIZE 1024
@jpmckinney
jpmckinney / unpack_and_beautify.h
Created December 27, 2010 23:17
unpack_and_beautify.js as char array
// blog post: http://blog.slashpoundbang.com/post/2488598258/running-javascript-from-the-command-line-with-v8
const char unpack_code[] = {
0x2f,0x2f,0x20,0x62,0x6c,0x6f,0x67,0x20,0x70,0x6f,0x73,0x74,0x3a,0x20,0x68,0x74,
0x74,0x70,0x3a,0x2f,0x2f,0x62,0x6c,0x6f,0x67,0x2e,0x73,0x6c,0x61,0x73,0x68,0x70,
0x6f,0x75,0x6e,0x64,0x62,0x61,0x6e,0x67,0x2e,0x63,0x6f,0x6d,0x2f,0x70,0x6f,0x73,
0x74,0x2f,0x32,0x34,0x32,0x38,0x35,0x35,0x37,0x30,0x30,0x37,0x2f,0x75,0x6e,0x70,
0x61,0x63,0x6b,0x2d,0x61,0x6e,0x64,0x2d,0x62,0x65,0x61,0x75,0x74,0x69,0x66,0x79,
0x2d,0x6a,0x61,0x76,0x61,0x73,0x63,0x72,0x69,0x70,0x74,0x0a,0x0a,0x2f,0x2f,0x20,
0x41,0x73,0x73,0x75,0x6d,0x65,0x73,0x20,0x6a,0x73,0x5f,0x62,0x65,0x61,0x75,0x74,