Skip to content

Instantly share code, notes, and snippets.

'instanceof' tests results on the objects returned from the method/property below.
IE 8
NodeList HTMLCollection StaticNodeList
all X
children X
childNodes X
getElementsByName X
getElementsByTagName X
getElementsByClassName X
@mseeley
mseeley / gist:491782
Created July 27, 2010 05:23
Dynamically create Document objects
// Tested in FF2 && 3.6
var processor = new XSLTProcessor(),
xml = document.implementation.createDocument("", "", null),
xsl = new DOMParser().parseFromString("<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:output method='html' /><xsl:template match='/'><html><head><title></title></head><body></body></html></xsl:template></xsl:stylesheet>", "text/xml");
processor.importStylesheet(xsl);
// Gecko always inserts the character encoding META element (below) in the
// transformed HTML DOM. Manually inserting the META element in the XSL template
@mseeley
mseeley / gist:491800
Created July 27, 2010 05:40
Function enabling creation of dynamic `document` objects
// Function enabling the creation of dynamic `document` objects
var global = window,
doc = global.document;
function createDoc (title) {
var axo = "ActiveXObject",
chd = "createHTMLDocument",
xp = "XSLTProcessor",
@mseeley
mseeley / Encapsulated array walking
Created September 10, 2010 21:43
Encapsulated array walking
function Set (/* varargs */) {
var i = 0,
items = [].slice.call(arguments, 0);
this.item = function (idx) {
var item = items[i];
if (idx != null) {
if (idx in items) {
i = idx;
}
@mseeley
mseeley / easing.scss
Created November 9, 2011 06:19 — forked from tdreyno/easing.scss
Easing functions for Sass 3.1
@function linear() {
@return cubic-bezier(0.250, 0.250, 0.750, 0.750); }
@function ease() {
@return cubic-bezier(0.250, 0.100, 0.250, 1.000); }
@function ease-in() {
@return cubic-bezier(0.420, 0.000, 1.000, 1.000); }
@function ease-in-quad() {
@return cubic-bezier(0.550, 0.085, 0.680, 0.530); }
@mseeley
mseeley / Url.js
Created November 20, 2011 04:52
URL parsing regex
(function () {
// Regexp is based on Crockford's "Javascript, the Good Parts"
// (?:([A-Za-z]+):)? - protocol (http, ftp, etc...) (optional)
// (\/{0,3}) - slash(es)
// (?:(\w+):(\w+)@)? - username:password@ (optional) -- does this need to support hyphens and dots?
// ([\w\-.]+) - host name (shortened from [0-9.\-A-Za-z]+)
// (?::(\d+))? - port number (optional)
// (?:\/([^?#]*))? - match path (optional) (caution, matches all character except ? and #, so it will also match line-ending characters, control character, and lots of other characters)
@mseeley
mseeley / money_tiles.js
Created November 21, 2011 23:16
Node script to grab tiles from http://xkcd.com/980/huge/
var http = require('http'),
fs = require('fs'),
output = './money_tiles7/',
// Tokens and ranges for the 1:1 detail level
zoom = 0,
xmin = 0,
xmax = 48,
ymin = 0,
ymax = 32,
@mseeley
mseeley / truncate.js
Created January 19, 2012 02:37
Truncating a string at word break
/**
* Assumptions:
* Text is a UTF8 string
* Text is without HTML entities and HTML tags
* Suffix is added at nearest word break, excluding punctuation
* Length of the text string is longer than the suffix
* Arguments are assumed present and of correct type
*/
(function (exports) {
@mseeley
mseeley / CssRule.js
Created March 23, 2012 18:35
Easily alter CSS rules via JS
// Allows programmatic altering of CSS rules. Turn this class into a flyweight by enabling modification of the underlying rule property.
function CssRule (selector, stylesheet) {
var rules = stylesheet.rules,
len = rules.length,
i = 0,
rule = null;
for (i; i < len; i++) {
rule = rules[i];
if (rule.selectorText === selector) {
@mseeley
mseeley / LICENSE.txt
Created April 30, 2012 17:12 — forked from jed/LICENSE.txt
Array.prototype.unique
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE