Skip to content

Instantly share code, notes, and snippets.


James M. Greene JamesMGreene

View GitHub Profile
JamesMGreene / jetty-macros-for-ant-using-ant-contrib.xml
Created May 15, 2012
How to start and stop Jetty from Ant. Two versions: one using Ant Contrib, one without.
View jetty-macros-for-ant-using-ant-contrib.xml
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 Jul 8, 2012
Shortcut functions to easily create deep namespaces in JavaScript
View NoRootNamespaceEnforcement.js
(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.
View PixelClicker.js
// 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 Sep 13, 2012
PhantomJS: Conceptual implementation of a short-term shim to establish the window.postMessage API for IPC
View 0 -


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 Sep 18, 2012
Break a URL down by utilizing an HTML anchor ("a") element to turn it into a Location object
View getUrlAsLocation.js
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 Oct 21, 2012 — forked from ahomu/shot.js
Create slides(Reveal.js) PNG images using phantomjs
View shot.js
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 Nov 24, 2012
Using Q, is this the best way to pass the results of two sequenced promises to the subsequent `then`/`spread` clause?
View CombiningSequencedPromiseResultsWithQ.js
'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) {
View JSHintErrorsWithUnicode.js
var toRawIssueContentReplacements = {
'"': '&quot;',
'<': '\u003c', /* Gives error "Unnecessary escapement" on the 'u' */
'>': '\u003e' /* Gives error "Unnecessary escapement" on the 'u' */
(function() {
JamesMGreene / globalErrorHandlerHookup.js
Created Nov 29, 2012
jQuery event handlers to prevent logging after the window goes crazy! =)
View globalErrorHandlerHookup.js
(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 Dec 10, 2015
Our old proprietary version of the QUnit JUnitLogger addon... compare to master branch version
View junitlogger.js
(function() {
'use strict';
var currentRun, currentModule, currentTest, assertCount;
// Gets called when a report is generated.
QUnit.jUnitReport = function(/* data */) {
// Override me!