Skip to content

Instantly share code, notes, and snippets.

View Fordi's full-sized avatar

Bryan Elliott Fordi

View GitHub Profile
@Fordi
Fordi / jquery.ajaxcancel.js
Created June 30, 2011 16:03
Function for killing all running ajax requests in jQuery
(function ($) {
var _ajax = $.ajax,
xhrQueue = [];
$.ajax = function () {
var ret;
xhrQueue.push(ret=_ajax.apply(this, arguments));
return ret;
};
$.ajaxCancel = function () {
while (xhrQueue.length>0) xhrQueue.pop().abort();
@Fordi
Fordi / PHP's str_split for Javascript
Created July 1, 2011 23:55
Crock32: The Base32 implementation outlined by Douglas Crockford
Javascript str_split:
String.prototype.strSplit = function (n) {
return this.match(new RegExp('.{1,'+(n||1)+'}', 'g'));
}
@Fordi
Fordi / ShortcutIcon.js
Created July 19, 2011 19:29
Shortcut icon manager
jQuery.icon = (function ($) {
var types = {
ico: 'image/x-icon',
gif: 'image/gif',
png: 'image/png',
jpg: 'image/jpeg',
jpeg: 'image/jpeg'
},
_icon,
_stack=[],
@Fordi
Fordi / text-clock.html
Created August 11, 2011 12:06
Text-based clock
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.clock {
font: 48pt Consolas;
margin: 0 auto;
width: 556pt;
@Fordi
Fordi / module-template.js
Created August 12, 2011 21:28
Module template
/**
* This code block is designed to enable the consumer of a script to name your library whatever they want, by simply
* adding the attribute 'data-library-name' to the script tag. When the time comes in your script
* you simply set Module.Space[Module.Name] = Your Cool Library
*
* Other benefits to the Module object*:
* Module.Tag is the script tag that pulled your script in. You can use this to pull in further data-* attributes for script configuration
* Module.URI contains the URI used to get your script. This can be useful if you want to use script-relative resources, such as SWF files
* You can require jQuery just by setting the jQueryVersion argument.
*
@Fordi
Fordi / informed-atheism.md
Created November 1, 2011 19:15
Informed Atheism is a Rebellion

Informed atheism is a rebellion. Not against God, for you don't rebel against things you treat as nonexistant. It's the expression of a rebellion against a popular view that it's ok to hold a belief that you can't demonstrate as true.

There's simple atheism: just failing to believe in a god for whatever reason: you've never been introduced to the concept; you're "angry" at your concept of god; you simply don't have a reason to believe. These are fine; I welcome the day when nearly everyone is a "simple atheist". These are the atheists that hardly need it as a label.

Informed atheism is a different animal: it's the statement that the existence of a god has been almost entirely excluded from belief by our knowledge. We understand there may be flaws in our knowledge, but the number of flaws necessary to allow a god to be real is staggering.

In short, a simple atheist may be easily turned into a believer - indeed, it's happened at least once to every single religious believer - but an informed atheist is

@Fordi
Fordi / couple.js
Created November 18, 2011 02:12
Library agnostic invokation events for functions
(function () {
"use strict";
/**
* Add event couplings to a function, enabling aspect-oriented design patterns
*
* @return Function Coupled function
**/
Function.prototype.couple = function () {
var fn = this,
events = {before: {}, after: {}};
@Fordi
Fordi / calculating-carbon-intensity.md
Created November 23, 2011 19:15
Calculating carbon intensity

Calculating Carbon Intensity

So terms like "oil" and "coal" are somewhat confusing, when you go to look for properties. These are names for sets of compounds that share similar, but not equivalent characteristics.

So when I went looking for the carbon intensity of oil (that is, mass ratio of CO2 produced to fuel burned for a fuel), I found myself stymied; Wikiepedia did not have a simple number, and the papers on the subject elicited by a google search tended to avoid giving actual numbers on the subject.

Not to be discouraged, I figured you could calculate it yourself, and get something in the right ballpark.

Petroleum is made up of largely "alkanes" - molecules with this ladder-like formula:

@Fordi
Fordi / respiration-v-generation.md
Created November 23, 2011 20:10
Respiration v. Generation

Respiration v. Generation

AGW deniers ask "Hey, we breathe CO2; does that mean we're contributing?" supposing that this makes AGW absurd. The question it begs, though, is more one of, how does CO2 emission via respiration compare to that of power generation, and what are the differential concerns?

Humans

World population: ~ 7 billion humans
[Avearge human CO2 production][humanEmission]: 2T / year
CO2 produced by human respiration: 14GT / year

@Fordi
Fordi / dependency-tree.js
Created January 30, 2012 20:07
Simple dependency tree
var Dependency = (function () {
"use strict";
var Node = function () {
var i, pub = {}, inst = this;
for (i in inst)
if (inst[i] instanceof Function)
pub[i] = (function (i) {
return function () {
return inst[i].apply(inst, arguments);
};