Skip to content

Instantly share code, notes, and snippets.

Avatar

James M. Greene JamesMGreene

View GitHub Profile
@pengwynn
pengwynn / random_voice_abc.rb
Created Aug 25, 2011
First grade fun learning Ruby
View random_voice_abc.rb
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 Apr 6, 2012
JavaScript: PhantomJS Mocha Scrapper
View run-mocha.js
/*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 Apr 24, 2012
phantomjs onDOMContentLoaded
View onDOMContentLoaded.js
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 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.
@paulirish
paulirish / gist:3098860
Created Jul 12, 2012
Open Conference Expectations
View gist:3098860

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 Jul 30, 2012
underscore.js mixin for plucking nested properties
View _.deep.js
_.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 Aug 6, 2012
Grunt task to remove console logging
View remove-logging.js
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 Aug 10, 2012
phantomjs retrieving text files
View retrieve-text-files.js
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 Aug 28, 2012
node.js script to inline static includes
View example.html
<!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 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];
}