Skip to content

Instantly share code, notes, and snippets.

@curtis1000
curtis1000 / Bootstrap.php
Created October 12, 2012 20:10
Zend Framework Tab module bootstrap
<?php
/**
* Tab Module Bootstrap
*
* @category ProjectNamespace
* @package Application
* @subpackage Tab
* @author Curtis Branum <cbranum@nerdery.com>
* @version $Id$
@curtis1000
curtis1000 / IndexController.php
Created October 12, 2012 20:15
Zend Framework Tab module Index Controller
<?php
/**
* This controller is the tab index controller
*
* @category ProjectNamespace
* @package Application
* @subpackage Tab
* @author Curtis Branum <cbranum@nerdery.com>
* @version $Id$
@curtis1000
curtis1000 / gist:3881418
Created October 12, 2012 20:51
Zend Framework enable modules in application config
resources.modules = On
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
NERD.FeedPostDialog = {
init: function () {
this.bind();
},
bind: function () {
$(document).on('click', '.feed-post-dialog', function(e){
e.preventDefault();
var params = $(this).data();
params.method = 'feed';
FB.ui(params, NERD.FeedPostDialog.callback);
@curtis1000
curtis1000 / functional_pattern.js
Created May 19, 2013 22:07
The functional pattern, defined in Douglas Crockford's "Javascript: The Good Parts", allows for JavaScript to achieve both inheritance and information hiding (private variables) with a compact syntax.
/**
* The functional pattern, defined in Douglas Crockford's "Javascript: The Good Parts", allows for
* JavaScript to achieve both inheritance and information hiding (private variables) with a compact syntax.
* The specification that is passed in, as well as potentially more vars you may define in each pseudo-class, are not
* accessible from the object that is returned, we consider these private variables. Public vars may
* be added to the "that" return object as desired.
*/
/**
* Person is our base pseudo-class
@curtis1000
curtis1000 / closure.js
Created May 20, 2013 21:34
An example of how closures work, and what makes them special
/**
* We are not assigning a function to myObject, only the result of
* invoking a function. While the returned object (which is assigned
* to "myObject") contains methods that can access the "value" variable,
* the "value" variable cannot be accessed directly through "myObject".
* This is how closures achieve information hiding, a.k.a. private variables.
*
* Information hiding is useful when we want to provide users with an interface,
* and prevent users from tampering with the javascript objects in ways that we
* do not want them to (hacking with private vars).
@curtis1000
curtis1000 / prototypes.js
Created May 20, 2013 21:38
Playing with JavaScript prototypes
// all objects inherit from Object.prototype,
// we can add capabilities like so:
console.log('adding capabilities to Object.prototype');
if (typeof Object.prototype.totalBills != 'function') {
Object.prototype.totalBills = function () {
if (this.bills && this.bills.constructor === Array) {
var total = 0;
for (var i=0; i<this.bills.length; i++) {
@curtis1000
curtis1000 / ConstructorInvocation.js
Last active December 17, 2015 13:19
An example of the Constructor Invocation Pattern in JavaScript
/**
* Constructor Invocation Pattern
* Requires use of the "new" keyword, allows for inheritance, but no information hiding
*/
// create a constructor function for the base class
var Person = function (spec) {
// pseudo-class vars
spec.name = spec.name || '';
this.name = spec.name;
@curtis1000
curtis1000 / BoilerplateModule.js
Created November 5, 2013 02:55
A Simple JS Module Structure
/**
* @fileOverview Boilerplate Module
* @version 2.0
* @depends $ jQuery
*/
/**
* Module definition, wrapped in a closure, any dependencies are passed in
*/
(function ($) {
@curtis1000
curtis1000 / debugger.html
Last active December 28, 2015 02:09
The Debugger Statement
<!DOCTYPE html>
<html>
<head>
<title>The JS Debugger</title>
</head>
<body>
<h1>JS Debugger</h1>
<p>You must have your browser's web inspector open in order to see debugger breakpoints.</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>