Skip to content

Instantly share code, notes, and snippets.

View keithelliott's full-sized avatar

Keith Elliott keithelliott

View GitHub Profile
@keithelliott
keithelliott / exampleTest.js
Created July 23, 2012 23:58
Jasmine Example
describe("Chatham's Url Loader", function(){
it("takes a string and returns a url", function(){
expect("index").toBe("www.chathamfinancial.com");
});
});
@keithelliott
keithelliott / SpecRunner.html
Created July 24, 2012 17:45
Example Jasmine SpecRunner html file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
@keithelliott
keithelliott / namespace.js
Created July 25, 2012 19:03
Creating javascript namespaces
// Chatham Namespace for exposing javascript functionality
// We can expose all of our functionality via this one global var
var CHATHAM = CHATHAM || {};
CHATHAM.namespace = function (namespace_name_string) {
var parts = namespace_name_string.split('.'),
parent = CHATHAM,
i, cnt;
// remove the first part of the string which will be 'CHATHAM'
@keithelliott
keithelliott / example_namespace_usage.js
Created July 25, 2012 19:26
use a javascript namespace
//uses the following syntax to create an object with private properties
// and functions. You expose the properties and functions you need publicly in the
// return object.... The immediate function allows us to have private scope for
// certain things
// Create a new namespace
CHATHAM.namespace('CHATHAM.utils.gridmgr');
CHATHAM.utils.gridmgr = (function(){
@keithelliott
keithelliott / global-example.js
Created August 13, 2012 15:59
Deal with Global Functions and Properties
// Example 1: Wrapping function and passing in global variables
// self-executing function that passes in the global context via this when the file loads
(function myGlobalExample(global){
return {
testFn: function(){
var doIt = global.doItTimes(5);
return doIt;
}
};
@keithelliott
keithelliott / statements.js
Created August 14, 2012 14:16
Example of JavaScript statements
// End each statement with a semicolon
// example 1 - var that is assigned to a function
var foo = function(){
// do some stuff
}; // semicolon required to end statement
// Example 2 - no semicolon needed
@keithelliott
keithelliott / timeoutexample.js
Created August 14, 2012 14:29
using setTimeout
// When using setTimeout, use one of the following patterns
//ex1
var fn1 = function(){
// do something
};
setTimeout(fn1, 0);
//ex2
@keithelliott
keithelliott / WineUtils.h
Created March 2, 2013 16:27
Utils for Wine sample app
static int const CURRENT_YEAR = 2013;
static int const MAX_YEARS = 20;
@interface WineUtils : NSObject
@property(nonatomic, strong) NSDictionary *wineRegionsDict;
@property (nonatomic, strong) NSArray *wineTypes;
@property (nonatomic, strong) NSArray *wineYears;
- (NSArray *)wineRegionsForCountry:(NSString *)country;
@keithelliott
keithelliott / AddRatingViewController.h
Created March 2, 2013 16:31
AddRatingController - view controller for adding a rating
#import <UIKit/UIKit.h>
@class ChooserViewController;
static int const HIGHEST_RATING = 5;
static int const LOWEST_RATING = 1;
static int const CHOOSER_VIEW = 5000;
@keithelliott
keithelliott / ChooserViewController.h
Created March 2, 2013 16:33
ChooserViewController
#import <UIKit/UIKit.h>
@class WineUtils;
static int const COMPONENTS_IN_REGION = 2;
static int const COMPONENTS_DEFAULT = 1;
typedef enum ChooserUIEnum{
CTYear,
CTRegion,
CTType