This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User | |
{ | |
public string UserId{ protected get; set; } | |
protected string PasswordHash { get; set; } | |
public void SetPassword(string password) | |
{ | |
PasswordHash = CryptoHelper.CreateHashWithRandomSalt(password); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NonNullable, the logical inverse of Nullable. Prevents a reference type from being null. | |
// Implicit conversions to and from the wrapped type provide transparency. | |
// Usage: Wrap method arguments and/or return values with NonNullable | |
// | |
public struct NonNullable<T> where T : class | |
{ | |
public readonly T Item; | |
public NonNullable(T item) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Template t = new Template("My {pet} {name} has fleas"); | |
string[] keys = {"dog", "name"}; | |
IEnumerable<string> missing, unrecognized; | |
bool isValid = t.Validate(keys, out missing, out unrecognized); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsharp> | |
<set var='isPrime'><true/></set> | |
<set var='i'><int>3</int></set> | |
<set var='root'> | |
<call class='Math' method='Sqrt'> | |
<get var='numberToTest'/> | |
</call> | |
</set> | |
<while> | |
<and> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected T LoadFromConfigOrDefault<T>(Func<T> @default = null) | |
{ | |
@default = @default ?? (() => (T)Activator.CreateInstance(typeof(T))); | |
string configKey = ConfigKeyFromType(typeof(T)); | |
var configTypeName = ConfigurationManager.AppSettings[configKey]; | |
if (!String.IsNullOrEmpty(configTypeName)) | |
{ | |
return InstanceFromTypeName<T>(configTypeName); | |
} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ProtoContract(ImplicitFields = ImplicitFields.AllFields)] | |
[Serializable] | |
public abstract class JournalEntry | |
{ | |
public readonly long Id; | |
public readonly DateTime Created; | |
public JournalEntry(long id, DateTime? created = null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class FibonacciKillerKata : IFibonacciKillerKata | |
{ | |
public int Fibonacci(int n) | |
{ | |
if (n <= 1) return n; | |
else return Fibonacci(n-1) + Fibonacci(n-2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
protobuf-net failing test case. This has got to be a bug! | |
*/ | |
[TestMethod] | |
public void IsDefined_on_empty_model_should_return_false() | |
{ | |
var typeModel = RuntimeTypeModel.Create(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Worker | |
{ | |
ILogger _logger; | |
public Worker() | |
{ | |
//dependency inversion take #1 | |
var logFactory = new LogFactory(); | |
_logger = logFactory.CreateLog(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Classify using the kNN algorithm | |
* @param item The item to classify | |
* @return The predicted class of the item | |
*/ | |
public double classify(T item) { | |
int numItems = items.size(); | |
// calculated distances in same order as the items list | |
double[] distances = new double[numItems]; |
OlderNewer