Skip to content

Instantly share code, notes, and snippets.

View JamesMGreene's full-sized avatar

James M. Greene JamesMGreene

View GitHub Profile
// Typical AMD factory that returns a value, but uses an r-value (sync) require(),
// rather than a long, awkward dependency list.
// You cannot use module.exports or exports to declare the module:
(function (define){
define(function (require) {
"use strict";
var mod = require('pkb/modA');
return {
@JamesMGreene
JamesMGreene / qunit-composite.js
Last active December 11, 2015 03:48
Our old proprietary version of the QUnit subsuite (composite) addon.
(function( QUnit ) {
var subsuiteFrame;
QUnit.extend( QUnit, {
testSuites: function( suites ) {
QUnit.done(function(result) {
subsuiteFrame.style.display = "none";
});
@JamesMGreene
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!
};
@JamesMGreene
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
JamesMGreene / JSHintErrorsWithUnicode.js
Created November 25, 2012 00:03
JSHintErrorsWithUnicode.js
var toRawIssueContentReplacements = {
'"': '"',
'<': '\u003c', /* Gives error "Unnecessary escapement" on the 'u' */
'>': '\u003e' /* Gives error "Unnecessary escapement" on the 'u' */
};
(function() {
console.log(JSON.stringify(toRawIssueContentReplacements));
})();
@JamesMGreene
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
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
};
page.open(url, function (status) {
//Page is loaded!
var iz, i = 0, queue = {};
@JamesMGreene
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
JamesMGreene / 0 - README.md
Created September 13, 2012 18:48
PhantomJS: Conceptual implementation of a short-term shim to establish the window.postMessage API for IPC

Topic

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.)

Problems

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

// Response to question on PhantomJS forum: https://groups.google.com/forum/#!topic/phantomjs/DouaSrjwwCE
function doAlpha(url) {
var page = require('webpage').create();
page.open(url, function(status) {
if (status === 'success') {
elements = page.evaluate(function() {
// ...
return result;
});