Skip to content

Instantly share code, notes, and snippets.

View JamesMGreene's full-sized avatar

James M. Greene JamesMGreene

View GitHub Profile
@pengwynn
pengwynn / random_voice_abc.rb
Created August 25, 2011 21:57
First grade fun learning Ruby
voices = %w(Agnes Kathy Princess Vicki Victoria)
("a".."z").each do |letter|
`say -v #{voices.shuffle.first} "#{letter}"`
end
@joeytrapp
joeytrapp / run-mocha.js
Created April 6, 2012 02:09
JavaScript: PhantomJS Mocha Scrapper
/*global phantom:true, console:true, WebPage:true, Date:true*/
(function () {
var url, timeout, page, defer;
if (phantom.args.length < 1) {
console.log("Usage: phantomjs run-mocha.coffee URL [timeout]");
phantom.exit();
}
url = phantom.args[0];
@JamesMGreene
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.
@firedfox
firedfox / retrieve-text-files.js
Created August 10, 2012 09:49
phantomjs retrieving text files
const TEXT_PREFIX = /<html><head><\/head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/;
const TEXT_SUFFIX = /<\/pre><\/body><\/html>/;
var page = require('webpage').create();
page.onLoadFinished = function() {
var content = page.content;
if (TEXT_PREFIX.test(content) && TEXT_SUFFIX.test(content)) {
content = content.replace(TEXT_PREFIX, '').replace(TEXT_SUFFIX, '');
};
@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];
}
@jlongster
jlongster / gist:3881008
Created October 12, 2012 19:28
js destructuring macro
// Note: there are bugs in hygienic renaming, so this doesn't work all the time yet.
macro varr {
case [$var (,) ...] = $expr => {
var i = 0;
var arr = $expr;
$(var $var = arr[i++];) ...
}
@dunkfordyce
dunkfordyce / gist:4065345
Created November 13, 2012 11:38
Convert single line comments in javascript to console.log statements with esprima/falafel/javascript
var falafel = require('falafel');
var src = require('fs').readFileSync(process.argv[2]).toString();
var output = falafel(src, {comment: true}, function (node) {
if (node.type === 'Line') {
node.update('console.log("COMMENT:' + node.value + '");');
}
});
console.log(output);
@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) {
@getify
getify / 1.md
Created November 30, 2012 12:04
rethink how javascript "inheritance" ACTUALLY works...

JavaScript does not have "inheritance" or "prototypal inheritance" or "classes" or any of that jazz... what you've been told, and how you've been taught about it, are a misunderstanding... all this nonsense about constructor functions and new and such... that's all hogwash... well, it's all unnecessary effort, at best.

"Instead... only try to realize the truth... there is no spoon."

What JavaScript does have is "behavior delegation"... and object linking through the "prototype chain"... you merely link two instances of objects together, say Foo and Baz, and say that Baz "delegates" to Foo for any behavior that Baz doesn't own itself but that Foo does own. And thus, any object b (aka, "b is an instance of Baz" in the more confusing terminology) which is linked to Baz, delegates first to Baz, and then to Foo, for behavior.

That's it. Seriously. And function constructors and new and all that stuff, everything you've read before about OO in JS, they're just distractions that lea

@vitallium
vitallium / fix_compile_vs2012
Created December 4, 2012 06:46
[PhantomJS] Patch for compiling using VS2012
diff --git a/src/qt/mkspecs/win32-msvc2010/qmake.conf b/src/qt/mkspecs/win32-msvc2010/qmake.conf
index 036c522..ea2ddb0 100644
--- a/src/qt/mkspecs/win32-msvc2010/qmake.conf
+++ b/src/qt/mkspecs/win32-msvc2010/qmake.conf
@@ -9,7 +9,7 @@ TEMPLATE = app
CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe
QT += core gui
DEFINES += UNICODE WIN32 QT_LARGEFILE_SUPPORT
-QMAKE_COMPILER_DEFINES += _MSC_VER=1600 WIN32
+QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32