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 static IEnumerable<string> SplitTrim(this string input, params char[] separator) | |
{ | |
if (input == null) throw new ArgumentNullException("input"); | |
string[] strings = input.Trim().Split(separator); | |
foreach (var s in strings) | |
{ | |
string trimmed = s.Trim(); | |
if (!String.IsNullOrWhiteSpace(trimmed)) | |
yield return trimmed; | |
} |
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
<configSections> | |
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> | |
</configSections> | |
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<extensions> | |
<add assembly="NLog.Targets.Syslog" /> | |
</extensions> | |
<targets async="true"> | |
<target xsi:type="File" name="f" fileName="${basedir}/App_Data/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> | |
<target name="papertrail" type="Syslog" syslogserver="logs.papertrailapp.com" port="*fillin*" facility="Local7" layout="${uppercase:${level}} ${message} ${exception}"/> |
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 static class DumperExtensions | |
{ | |
public static string DumpToString(this object a, int maxDepth = 16, bool breakCircularRefs = false) | |
{ | |
return new Dumper(a, maxDepth, breakCircularRefs).ToString(); | |
} | |
public static T DumpToConsole<T>(this T a, int maxDepth = 16, bool breakCircularRefs = false) | |
{ | |
Console.Out.WriteLine(DumpToString(a, maxDepth, breakCircularRefs)); |
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 static class RouteCollectionExtensions | |
{ | |
public static void MapRedirect(this RouteCollection rc, string url, string dest, bool perm = false) | |
{ | |
rc.Add(new Route(url, new RedirectRouteHandler(dest, perm))); | |
} | |
} | |
public class VirtualPathRouteHandlerBase | |
{ |
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 static class AsteriskValidation | |
{ | |
public static void Validate(this Page page, IValidatableObject validatableObject, ValidationContext context = null) | |
{ | |
foreach (ValidationResult error in validatableObject.Validate(context)) | |
page.Validators.Add(new ErrorValidator(error)); | |
} | |
public static void Validate(this Page page, DbEntityValidationException ex, ValidationContext context = 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
public static TValue GetOrSet<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> create) | |
{ | |
TValue value; | |
return dictionary.TryGetValue(key, out value) ? value : (dictionary[key] = create(key)); | |
} | |
public static TValue GetOrSet<TKey, TValue>(this IDictionary dictionary, TKey key, Func<TKey, TValue> create) | |
{ | |
var value = (TValue) dictionary[key]; | |
if (!Equals(value, default(TValue))) return value; |
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
; Variables definition | |
; ----------------------------------------------------------------------------- | |
EnvGet, userProfile, USERPROFILE | |
Software := userProfile . "\Dropbox\software\" | |
; Launch or toggle program, http://lifehacker.com/5468862/create-a-shortcut-key-for-restoring-a-specific-window | |
; ----------------------------------------------------------------------------- | |
ToggleWinMinimize(WindowTitle) | |
{ | |
SetTitleMatchMode,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
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dic, TKey key, TValue defaultVal = default(TValue)) | |
{ | |
TValue ret; | |
return dic.TryGetValue(key, out ret) ? ret : defaultVal; | |
} | |
public static TValue GetValueOrDefault<TValue>(this StateBag stateBag, string key, TValue defaultValue = default(TValue)) | |
{ | |
object value = stateBag[key]; | |
return Equals(value, null) ? defaultValue : (TValue) value; |
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 static IEnumerable<T> Unpage<T>(Func<int, int, IEnumerable<T>> func, int batchSize) | |
{ | |
int skip = 0; | |
int count; | |
do | |
{ | |
count = 0; | |
foreach (var a in func(skip, batchSize)) | |
{ | |
count++; |