Skip to content

Instantly share code, notes, and snippets.

View dgowrie's full-sized avatar
🤘

David Gowrie dgowrie

🤘
View GitHub Profile
@dgowrie
dgowrie / css-stats-ack.sh
Created October 1, 2012 20:06 — forked from pjkix/css-stats-ack.sh
shell script to generate some css file statistics
#!/bin/bash
## v1.0.6
## this script will gernerate css stats
### example output
# CSS STATS
# ----------
# Floats: 132
@dgowrie
dgowrie / index.html
Last active August 29, 2015 14:11 — forked from jonnyreeves/index.html
RequireJS demo: OO JavaScript - a 'prototype pattern' modular approach to "Class" definitions. "JavaScript Class Structure using requireJS. The following code shows you how to create a Class definition in one JavaScript file and then import it for use in another."
<!DOCTYPE html>
<html>
<head>
<script data-main="usage" src="http://requirejs.org/docs/release/2.1.15/comments/require.js"></script>
</head>
<body>
<p>Check your JavaScript console for output!</p>
</body>
</head>
@dgowrie
dgowrie / Gruntfile.js
Last active August 29, 2015 14:14 — forked from jamesshore/Gruntfile.js
Michal Svoboda's port of [Automatopia](https://github.com/jamesshore/automatopia) to Grunt. See [this comment thread](http://www.letscodejavascript.com/v3/comments/lab/1#comment-1206272962) for context.
/* global module */
(function() {
"use strict";
module.exports = function(grunt) {
var shellOptions = { stdout: true, stderr: true, failOnError: true };
@dgowrie
dgowrie / index.html
Created January 30, 2015 04:52
Local Storage example, structured with the Revealing Prototype Pattern for a "Class" like usage, also namespaced
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Localstorage demo</title>
</head>
<script src="Scripts/jquery-2.0.3.min.js"></script>
<script src="Scripts/LocalStorageUtility.js"></script>
<script type="text/javascript">
@dgowrie
dgowrie / classlike-prototype-module.js
Last active August 29, 2015 14:14
"Class" like structure for JavaScript - a hybrid of the Module Pattern (a locally scoped object variant) and the Prototype Pattern... similar in result to the 'standard' (if such a thing) "Revealing Prototype Pattern"
// "Class" like module pattern
(function (NS) {
'use strict';
// constructor for the Person "Class", attached to global namespace
var Person = NS.Person = function (name) {
this.name = name;
};
@dgowrie
dgowrie / recursive-alternative.js
Last active February 26, 2021 23:46
How to recursively flatten a nested array.
// alternative using 'instanceof' check
(function() {
'use strict';
var array = [
'l1a',
'l1b',
@dgowrie
dgowrie / recursively-flatten-nested-hash.js
Last active August 29, 2015 14:14
How to recursively flatten a nested hash (object literal) in JavaScript.
// alternative approach for testing if value is an Object
(function() {
'use strict';
var hash = {
level1a: 'l1a',
level1b: 'l1b',
level1c: {
@dgowrie
dgowrie / prototypal-inheritance-crockford
Created February 5, 2015 05:45
Prototypal inheritance in JavaScript as described by Douglas Crockford
Prototypal inheritance in JavaScript is described by Douglas Crockford as: you make prototype objects, and then ... make new instances. Objects are mutable in JavaScript, so we can augment the new instances, giving them new fields and methods. These can then act as prototypes for even newer objects. We don't need classes to make lots of similar objects....Objects inherit from objects. What could be more object oriented than that?
http://javascript.crockford.com/prototypal.html
@dgowrie
dgowrie / extending-prototype.js
Last active August 29, 2015 14:15
Prototypal Inheritance - extending a prototype when creating a 'subclass'
// Demonstrates the side effects of using 'new' to extend a prototype and the reason to use Object.create (with a shim for IE8 support).
//
// It can be a problem to use 'new' when extending a superclass because you're actually running the superclass's constructor.
// Using Object.create() avoids the problem of unintentional side effects from running the superclass constructor.
// see http://www.objectplayground.com/ for details
// Parent class constructor
function Parent() {
alert("side effect!");
}
@dgowrie
dgowrie / revealing-prototype-pattern.js
Last active December 18, 2015 17:40
Public / private members on a "class" via the Pseudoclassical pattern using Prototypal Inheritance combined with the Revealing Module pattern - AKA a "revealing prototype pattern"
// constructor
function Person(name) {
this.name = name;
// etc... but no methods here
}
// prototype for all methods, using an IIFE with a returned object for 'public' methods
Person.prototype = (function() {