Skip to content

Instantly share code, notes, and snippets.

View bittersweetryan's full-sized avatar

Ryan Anklam bittersweetryan

View GitHub Profile
@bittersweetryan
bittersweetryan / Person.cfc
Created June 29, 2012 22:02 — forked from cfvonner/Person.cfc
Sample Components for CFKoans Mocking tests
<cfscript>
component displayname="Person" hint="I am a person object." output="false" accessors="true"
{
// Define the properties for this component
property name="personID" type="numeric" getter="true" setter="false" hint="Unique numeric id assigned by the database.";
property name="firstName" type="string" getter="true" setter="true" hint="The first name of the person.";
property name="lastName" type="string" getter="true" setter="true" hint="The last name of the person.";
property name="dateOfBirth" type="date" getter="true" setter="true" hint="The date of birth of the person.";
@bittersweetryan
bittersweetryan / gist:2919074
Created June 12, 2012 18:09
Mocking and Stubbing in MXUnit
<cfscript>
//stubbing
public void function testSavingPerson()
output=false hint=""{
//create the mock of your dao
var mockPersonDAO = mock("PersonDAO","typeSafe");
//tell the mock that when save is called with the cut to return void
mockPersonDAO.save(variables.Person).returns();
//add it to the cut
@bittersweetryan
bittersweetryan / gist:2890286
Created June 7, 2012 17:44
deferred to control animation timings
displayMessage: function(ev){
var id = ev.currentTarget.id,
dfd = $.Deferred(),
self = this,
statusCell = this.getStatusCell($(ev.currentTarget));
this.model.set('id',id);
if(statusCell.find('img').attr('alt') === 'unread'){
/**
* @mxunit:decorators mxunit.framework.decorators.OrderedTestDecorator
*/
component extends="Koans.BaseKoan" {
private boolean function isTruthy(Any myVar){
if(isBoolean(arguments.myVar)){
return (arguments.myVar) ? true : false;
}
@bittersweetryan
bittersweetryan / gist:2787854
Created May 25, 2012 12:44
Flatten a JavaScript Object into a Flat Object With Dot Notation Prop Names
function flatten(obj,prefix){
var propName = (prefix) ? prefix + '.' : '',
ret = {};
for(var attr in obj){
if(_.isArray(obj[attr])){
var len = obj[attr].length;
ret[attr] = obj[attr].join(',');
@bittersweetryan
bittersweetryan / hack.sh
Created March 31, 2012 15:00 — forked from rwaldron/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
<cfscript>
//returns all active, non-delted people
list();
//returns only active, non-deleted people
list({active = false});
//returns only inacvie, delted people
list({active = false, deleted = true});
<cfscript>
public Array function list(Struct options = {})
output=false hint="I return a list of active, non-deleted people by default."{
//create our default options
var defaults = {
deleted = false,
active = true
};
//now combine this struct with the options
@bittersweetryan
bittersweetryan / gist:2028645
Created March 13, 2012 13:06
Functional Extend in ColdFusion (think jQuery.extend())
<cfscript>
public Struct function extend()
output=false hint="I take structs and add their keys"{
var ret = {};
for(var i = 1; i <= arrayLen(arguments); i++){
for(key in arguments[i]){
ret[key] = arguments[i][key];
}
}
<cfscript>
public void function testStringsShouldBeEqual(){
var result = "Foo";
//in the koans __ represents a value that you need to fill in to make the test return true
//in some cases you'll want to keep the "" and in some you wont (see next example)
assertEquals(result,"__");
}
</cfscript>