Skip to content

Instantly share code, notes, and snippets.

View oliver-moran's full-sized avatar

Oliver Moran oliver-moran

View GitHub Profile
@oliver-moran
oliver-moran / Array.prototype.shuffle()
Created February 5, 2014 11:54
Shuffle (randomise) method for JavaScript Array prototype
/**
* Randomize array element order in-place.
* Using Fisher-Yates shuffle algorithm.
*/
Array.prototype.shuffle = function () {
for (var i = this.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = this[i];
this[i] = this[j];
this[j] = temp;
@oliver-moran
oliver-moran / document.getElementsByAttribute()
Last active January 30, 2020 10:39
JavaScript prototype for document.getElementByAttribute (or any element.getElementByAttribute).
// returns an array of elements
// the argument attr (attribute) is reuqired, the argument val (value) is optional:
// - if val passed then only elements where the attribute attr == val will be returned
// - otherise, all element with the attribute attr will be retured
document.getElementsByAttribute = Element.prototype.getElementsByAttribute = function(attr, val) {
var nodeList = this.getElementsByTagName('*');
var nodeArray = [];
for (var i = 0, elem; elem = nodeList[i]; i++) {
@oliver-moran
oliver-moran / js_vb_html4.html
Created September 23, 2012 12:39
Stating the language used in scripts
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- We will set the default scripting language to VBScript. -->
<meta http-equiv="Content-Script-Type" content="text/vbscript" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Stating the language used in scripts</title>