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];
@firedfox
firedfox / onDOMContentLoaded.js
Created April 24, 2012 02:12
phantomjs onDOMContentLoaded
const PHANTOM_FUNCTION_PREFIX = '/* PHANTOM_FUNCTION */';
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
if (msg.indexOf(PHANTOM_FUNCTION_PREFIX) === 0) {
eval('(' + msg + ')()');
} else {
console.log(msg);
}
@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.
@paulirish
paulirish / gist:3098860
Created July 12, 2012 15:26
Open Conference Expectations

Open Conference Expectations

This document lays out some baseline expectations between conference speakers and conference presenters. The general goal is to maximize the value the conference provides to its attendees and community and to let speakers know what they might reasonably expect from a conference.

We believe that all speakers should reasonably expect these things, not just speakers who are known to draw large crowds, because no one is a rockstar but more people should have the chance to be one. We believe that conferences are better -- and, dare we say, more diverse -- when the people speaking are not just the people who can afford to get themselves there, either because their company paid or they foot the bill themselves. Basically, this isn't a rock show rider, it's some ideas that should help get the voices of lesser known folks heard.

These expectations should serve as a starting point for discussion between speaker and organizer. They are not a list of demands; they are a list of rea

@furf
furf / _.deep.js
Created July 30, 2012 17:06
underscore.js mixin for plucking nested properties
_.mixin({
// Get/set the value of a nested property
deep: function (obj, key, value) {
var keys = key.replace(/\[(["']?)([^\1]+?)\1?\]/g, '.$2').replace(/^\./, '').split('.'),
root,
i = 0,
n = keys.length;
@ehynds
ehynds / remove-logging.js
Created August 6, 2012 15:16
Grunt task to remove console logging
grunt.registerMultiTask("removelogging", "Remove console logging", function() {
var done = this.async();
var exec = require("child_process").exec;
var options = this.data.options || {};
grunt.file.expandFiles(this.data.files).forEach(function(file) {
var cmd = "sed -E 's/console\.(log|warn|error|assert|count|clear|group|groupEnd|trace|debug|dir|dirxml|profile|profileEnd|time|timeEnd)\((.*)\);?//g' " + file;
exec(cmd, options, function(error, stdout) {
if(error !== null) {
@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, '');
};
@millermedeiros
millermedeiros / example.html
Created August 28, 2012 13:52
node.js script to inline static includes
<!DOCTYPE html>
<!-- #include "inc_header.html" title="Example" header="Sample Title" -->
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h1>Sample Title</h1>
@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];
}