Skip to content

Instantly share code, notes, and snippets.

@jsonmez
jsonmez / original.cs
Last active August 29, 2015 14:18
Removing comments example: before
internal static void SplitDirectoryFile(string path, out string directory, out string file)
{
directory = null;
file = null;
// assumes a validated full path
if (path != null)
{
int length = path.Length;
int rootLength = GetRootLength(path);
@jsonmez
jsonmez / spartan-todo.js
Last active August 29, 2015 14:07
Spartan TODO List: JavaScript
Items = new Meteor.Collection("items");
if (Meteor.isClient) {
Template.list.helpers({
items: function() {
return Items.find();
},
doneClass: function() {
if(this.done)
return "done";
@jsonmez
jsonmez / spartan-todo.html
Last active August 29, 2015 14:07
Spartan TODO List: Hard coded HTML UI
<head>
<title>Spartan TODO</title>
</head>
<body>
<h1>DO OR DIE!</h1>
{{> list}}
{{> controls }}
</body>
@jsonmez
jsonmez / CustomerAPI.cs
Created May 15, 2014 16:38
Using reasonable defaults and optional parameters
public void LoginAsCustomer(LoginInfo loginInfo, CustomerType customerType = CustomerType.NEW_CUSTOMER, int numberOfTries = 3)
{
// ...
}
var loginInfo = new LoginInfo("Darth Vader", "ihatewookes");
LoginAsCustomer(loginInfo);
// What if we need to override a default? No problem.
@jsonmez
jsonmez / AgeExmaple.cs
Created May 15, 2014 16:31
Age Example
public void ValidateCustomer(int maximumAge)
{
//...
}
ValidateCustomer(25);
// Using an Age class to restrict values
public class Age
@jsonmez
jsonmez / CustomerAPI.cs
Created May 15, 2014 15:41
Using enumerations to restrict choices in customer API
public enum CustomerType
{
NEW_CUSTOMER,
REWARDS_CUSTOMER,
REGULAR_CUSTOMER
}
public void LoginAsCustomer(LoginInfo loginInfo, CustomerType customerType, int numberOfTries)
{
// ...
@jsonmez
jsonmez / CustomerAPI.cs
Last active August 29, 2015 14:01
Reduced parameter count customer API
public void LoginAsCustomer(LoginInfo loginInfo, string customerType, int numberOfTries)
{
// ...
}
var loginInfo = new LoginInfo("Darth Vader", "ihatewookes");
LoginAsCustomer(loginInfo, "New Customer", 3);
@jsonmez
jsonmez / CustomerAPI.cs
Last active August 29, 2015 14:01
Bulky LoginAsCustomer API
public void LoginAsCustomer(string userName, string password, string customerType, int numberOfTries)
{
// ...
}
// Code to call the method
LoginAsCustomer("Darth Vader", "ihatewookies", "New Customer", 3);