Skip to content

Instantly share code, notes, and snippets.

View JamesMGreene's full-sized avatar

James M. Greene JamesMGreene

View GitHub Profile
JamesMGreene / jetty-macros-for-ant-using-ant-contrib.xml
Created May 15, 2012 20:10
How to start and stop Jetty from Ant. Two versions: one using Ant Contrib, one without.
A more-correct version of the Ant script bits outlined on this blog post:
NOTE: This file's macrodefs use task definitions from the Ant Contrib library ("if", "then" and "else", in particular).
If you are not using the Ant Contrib library, you cannot use this version of the file.
JamesMGreene / NoRootNamespaceEnforcement.js
Created July 8, 2012 12:14
Shortcut functions to easily create deep namespaces in JavaScript
(function(exports) {
* @namespace My namespace!
exports.MyNS = {
* Returns the namespace object specified and creates it if it doesn't exist.
* Does NOT enforce that any requested namespace is attached to the MyNS root namespace.
* @param {String} nsString A string representation of the desired namespace.
// Response to question on PhantomJS forum:!topic/phantomjs/DouaSrjwwCE
function doAlpha(url) {
var page = require('webpage').create();, function(status) {
if (status === 'success') {
elements = page.evaluate(function() {
// ...
return result;
JamesMGreene / 0 -
Created September 13, 2012 18:48
PhantomJS: Conceptual implementation of a short-term shim to establish the window.postMessage API for IPC


Providing an inter-process communication (IPC) mechanism such that a WebPage can explicitly signal back to PhantomJS as a push, thus eliminating/minimizing the need for users to setup polling functions, etc.

In PhantomJS 1.6, @detro added a WebPage onCallback handler that could be triggered from a webpage client by invoking the specially attached window.callPhantom function. However, @ariya expressed some discontent with this approach and so the three of us began discussing utilizing an existing API for cross-domain messaging instead: window.postMessage. (See Discussion for more info.)


PhantomJS currently only allows for a single handler per signal (a separate problem I'm working on over here). As such, automatically attaching internal handler may prevent users from attaching their own handlers for onInitialized (tha

JamesMGreene / getUrlAsLocation.js
Created September 18, 2012 14:20
Break a URL down by utilizing an HTML anchor ("a") element to turn it into a Location object
var getUrlAsLocation = (function() {
var urlPartKeyNames = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash"];
return function(url) {
var link = document.createElement("a"),
urlAsLocation = {};
link.href = url;
for (var i = 0, len = urlPartKeyNames.length; i < len; i++) {
var urlPartKey = urlPartKeyNames[i];
urlAsLocation[urlPartKey] = link[urlPartKey];
JamesMGreene / shot.js
Created October 21, 2012 19:47 — forked from ahomu/shot.js
Create slides(Reveal.js) PNG images using phantomjs
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://localhost:1947/';
page.viewportSize = {
width: 1024,
height: 768
};, function (status) {
//Page is loaded!
var iz, i = 0, queue = {};
JamesMGreene / CombiningSequencedPromiseResultsWithQ.js
Created November 24, 2012 15:47
Using Q, is this the best way to pass the results of two sequenced promises to the subsequent `then`/`spread` clause?
'use strict';
var Q = require('q');
var cmd = new require('commander').Command();
var client = new require('myAwesomeApi').Client();
var getUsername = function(done) {
var username;
cmd.prompt('Username: ', function(name) {
if (!name) {
JamesMGreene / JSHintErrorsWithUnicode.js
Created November 25, 2012 00:03
var toRawIssueContentReplacements = {
'"': '&quot;',
'<': '\u003c', /* Gives error "Unnecessary escapement" on the 'u' */
'>': '\u003e' /* Gives error "Unnecessary escapement" on the 'u' */
(function() {
JamesMGreene / globalErrorHandlerHookup.js
Created November 29, 2012 21:52
jQuery event handlers to prevent logging after the window goes crazy! =)
(function($, window, undefined) {
// WARNING! Set this as you see fit
var suppressUnhandledErrors = true;
var okToLogErrors = true;
var isOnline = true;
var offlineErrorQueue = [];
var logError = function(err) {
JamesMGreene / junitlogger.js
Last active December 10, 2015 20:28
Our old proprietary version of the QUnit JUnitLogger addon... compare to master branch version
(function() {
'use strict';
var currentRun, currentModule, currentTest, assertCount;
// Gets called when a report is generated.
QUnit.jUnitReport = function(/* data */) {
// Override me!