Skip to content

Instantly share code, notes, and snippets.

View csdear's full-sized avatar

Stuart Dear csdear

  • EBSCO
  • Birmingham AL
View GitHub Profile
@csdear
csdear / js FACADE PATTERN.js
Created January 12, 2015 11:50
Javascript FACADE PATTERN
/*
○ Building blocks for writing modules.
○ A façade is a high level interface to a larger code base that hides the underlying code complexity.
○ The facade exposes an application programming interface (API) which limits the available functionaity we can use and helps encapsulate a lot of the interior code behavior.
Façade Pattern Structure in JavasScript
• the function returns an object
• the object acts a a façade to the inner implementation , which is encapsulated.
*/
@csdear
csdear / Creating a Namespace Using IFEE.js
Created January 6, 2015 12:18
Creating a Namespace Using an IFEE □ (Immediate Function Execution Expression -- run immediately, run once etc. ) □ Adds robustness to the ns with this IFEE language feature. □ Use IFEEs to initialize a namespace once with its relevent functionatily. Wrap the code in an IFEE
var ns;
(function (ns) {
ns.Car = function (type) {
this.speed = 0;
this.type = type || "No Type";
}
ns.Car.prototype = {
drive: function(newSpeed) {
this.speed = newSpeed;
}
@csdear
csdear / Knight and Warlord Javascript Object Summary Play.js
Created January 6, 2015 11:21
Knight and Warlord Javascript Object Summary Play : create prototype base class object, then use object.create to create a regular instance, then creeate a instance that overrides function/properties of prototype object, then use the call/apply/bind functions for correct scoping.
// the prototype object
function Hero(type) {
//properties of this proto object
this.strength = 0;
this.type = type || "No type";
}
// proto function, used by all
Hero.prototype.attack = function(newStrength) {
@csdear
csdear / this Keyword Correct Contexting Functions : Apply, Call and Bind.js
Last active August 29, 2015 14:12
this Keyword Correct Contexting Functions : Apply, Call and Bind call, apply and bind are ways to override the difficulties with the this keyword and context. bind doesn’t work well with legacy browsers, so if you are developing for IE8 etc, use the apply and call functions.
function Car(type) {
this.type = type;
this.speed = 0;
this.func = function() {
return this.type;
}
}
var bmw = new Car("BMW");
@csdear
csdear / PROTO & MONO.js
Last active August 29, 2015 14:12
PROTO & MONO - Using PROTOTYPE to establish inheritence in javascript Objects and MONO - Modular Instance Override. Prototype is used to create base template classes (see Car) and have new instances that inherit those base properties. MONO is spinning off a instance to override its inherited properties/functions and define its own.
// 1. the basic javascript object creation
function Car(type) {
this.speed = 0;
this.type = type || "No type";
this.drive = function(newSpeed) {
this.speed = newSpeed;
}
}
var bmw =new Car("BMW");
@csdear
csdear / Create Javascript Object - new Notation and Constructor Functions.js
Created December 30, 2014 13:47
Create Javascript Object : new Notation and Constructor Functions • constructor function will be used as the blueprint when creating new instances with the new kw • Constructor function special b/c you can refer to an instance by using the this keyword. • Convention to use uppercase at the beginning of a constructor function -- e.g., Car. • Ea i…
function Car(type) {
this.speed = 0;
this.type = type || "No type";
this.drive = function(newSpeed) {
this.speed = newSpeed;
}
}
//creating a new instance of the Car object, the bmw.
var bmw =new Car("BMW");
@csdear
csdear / Transaction - COMMIT & ROLL BACK.sql
Last active August 29, 2015 14:11
Transaction - COMMIT & ROLL BACK A safe guard against mistakes, best practice is to alway wrap changes that are going to affect the table in these transactional code snippets.
--1. BEGIN transaction, write your query and execute.
SELECT *
FROM [stuart_sandbox].[dbo].[Categories]
BEGIN transaction
UPDATE [stuart_sandbox].[dbo].[Categories]
SET Description ='Sushi'
WHERE CategoryID = '8'
--2. Check the results of your query
@csdear
csdear / If Else Shorthand Javascript.js
Created November 18, 2014 16:44
If Else Shorthand Javascript
var modelSeries = $('#seriesName').text();
var gradeLevel = $('#gradeLevel').text();
function seriesFormatter (series, grade) {
var result = (series.indexOf(grade.toLowerCase()) >= 0) ? series : series + " " + grade;
return result;
}
var str = seriesFormatter(modelSeries, gradeLevel);
@csdear
csdear / jQuery : Injecting Content.css
Created November 11, 2014 21:22
jQuery : Injecting Content
p {
color: blue;
margin: 8px;
}
b {
color: red;
}
@csdear
csdear / Preserve Leading Zeroes.sql
Created November 3, 2014 19:56
Preserve leading zeroes when copy and pasting SQL to Excel
--wrap the column name with this...
SELECT '="' + dealer_code + '"', dealer_name
FROM dealers