This file contains hidden or 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 ModelValidator : AbstractValidator<Model> { | |
public ModelValidator() { | |
RuleFor(x => x.Surname).NotEmpty(); | |
RuleFor(x => x.Forename).NotEmpty().WithMessage("Please specify a first name"); | |
RuleFor(x => x.Discount).NotEqual(0).When(x => x.HasDiscount); | |
RuleFor(x => x.Address).Length(20, 250); | |
RuleFor(x => x.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode"); | |
} | |
} |
This file contains hidden or 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 static void Move<T>(this IList<T> list, int oldIndex, int newIndex) | |
{ | |
var item = list[oldIndex]; | |
list.RemoveAt(oldIndex); | |
if (newIndex > oldIndex) | |
{ | |
newIndex--; | |
} |
This file contains hidden or 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 abstract class XmlDeserializeConfigSectionHandler : IConfigurationSectionHandler | |
{ | |
public XmlDeserializeConfigSectionHandler() : base() | |
{ | |
} | |
public object Create(object parent, object configContext, System.Xml.XmlNode section) | |
{ | |
Type t = this.GetType(); |
This file contains hidden or 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 (MD5 md5 = MD5.Create()) | |
{ | |
using (FileStream stream = File.OpenRead(filename)) | |
{ | |
byte[] bytes = md5.ComputeHash(stream); | |
bool uppercase = false; | |
StringBuilder result = new StringBuilder(bytes.Length * 2); | |
for (int i = 0; i < bytes.Length; i++) |
This file contains hidden or 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 static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> source, int countPerList) | |
{ | |
if (source == null || countPerList <= 0) | |
{ | |
return Enumerable.Empty<IEnumerable<T>>(); | |
} | |
return source | |
.Select((x, i) => new { Index = i, Value = x }) | |
.GroupBy(x => x.Index / countPerList) |
This file contains hidden or 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
function squareRoot(value, precision) | |
{ | |
function calcSeedVal(value, precision) | |
{ | |
var a = 0; | |
var result = 0; | |
if(value > 9) | |
{ | |
a = value / Math.pow(10,precision); |
This file contains hidden or 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
DECLARE @tablename varchar(50) | |
SET @tablename = '' -- <--EDIT THIS VALUE | |
DECLARE @columnname varchar(50) | |
SET @columnname = '' -- <--EDIT THIS VALUE | |
SELECT | |
SCHEMANAME = SCHEMA_NAME(SYSTABLES.SCHEMA_ID), | |
TABLENAME = SYSTABLES.NAME, | |
COLUMNNAME = _SYSCOLUMNS.NAME, |
This file contains hidden or 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
String.prototype.startsWith = function(str) | |
{ | |
return (this.indexOf(str) === 0); | |
}; | |
String.prototype.contains = function(str) | |
{ | |
return (this.indexOf(str, 0) !== -1); | |
}; |
This file contains hidden or 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
function guid() | |
{ | |
var guidTemplate = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'; | |
var guid = guidTemplate.replace(/[xy]/g, function (c) | |
{ | |
var r = Math.random() * 16 | 0; | |
var v = c == 'x' ? r : (r & 0x3 | 0x8); | |
return v.toString(16); | |
}); |
This file contains hidden or 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
if (window.addEventListener) | |
{ | |
// IE9, Chrome, Safari, Opera | |
window.addEventListener("mousewheel", function (e) | |
{ | |
someEventHandler(e); | |
}, false); | |
// Firefox | |
window.addEventListener("DOMMouseScroll", function (e) | |
{ |
NewerOlder