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; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using System.Linq; | |
using Newtonsoft.Json.Linq; | |
using RestSharp; | |
using RestSharp.Deserializers; | |
using RestSharp.Extensions; |
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 StringExtensions | |
{ | |
/// Like linq take - takes the first x characters | |
public static string Take(this string theString, int count, bool ellipsis = false) | |
{ | |
int lengthToTake = Math.Min(count, theString.Length); | |
var cutDownString = theString.Substring(0, lengthToTake); | |
if (ellipsis && lengthToTake < theString.Length) | |
cutDownString += "..."; |
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 CalendarHelpers | |
{ | |
//Google Calender | |
public static string GoogleCalendar(this HtmlHelper helper, string linkText, string what, DateTime start, DateTime? end, string description, string location, string websiteName, string websiteAddress, string attributes) | |
{ | |
//parse dates | |
var dates = start.ToString("yyyyMMddTHHmmssZ"); | |
if (end.HasValue && end > start) | |
{ |
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 DateExtensions | |
{ | |
public static string TimeAgo(this DateTime date) | |
{ | |
if (date <= DateTime.Now) | |
{ | |
var timeSince = DateTime.Now.Subtract(date); | |
if (timeSince.TotalMilliseconds < 1) return "not yet"; | |
if (timeSince.TotalMinutes < 1) return "just now"; | |
if (timeSince.TotalMinutes < 2) return "1 minute ago"; |
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 DownloadableFile ToDownloadableXmlFileForExcel2003(this System.Xml.Linq.XDocument file, string fileName) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8 }; | |
XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings); | |
file.Save(xmlWriter); //.Save() adds the <xml /> header tag! | |
xmlWriter.Close(); //Must close the writer to dump it's content its output (the memory stream) |
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
[EditorBrowsable(EditorBrowsableState.Never)] | |
public interface IFluentInterface { | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
Type GetType(); | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
int GetHashCode(); | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
string ToString(); | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
bool Equals(object obj); |
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 CurrencyHelper | |
{ | |
private static string _currencyRegex = "rhs: \\\"(\\d*.\\d*)"; | |
// slightly modified from: http://www.ashishblog.com/blog/currency-exchange-rate-in-webpage-using-c-asp-net/ | |
// Uses a google api which takes requests in this format: http://www.google.com/ig/calculator?hl=en&q=1AUD%3D%3FUSD | |
public static decimal Convert(decimal amount, string fromCurrency, string toCurrency) | |
{ | |
var web = new WebClient(); |
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 CacheExtensions | |
{ | |
static object sync = new object(); | |
/// <summary> | |
/// Executes a method and stores the result in cache using the given cache key. If the data already exists in cache, it returns the data | |
/// and doesn't execute the method. Thread safe, although the method parametersn't guaranteed to be thread safe. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="cache"></param> |
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace NSpark | |
{ | |
public static class SparkExtensions | |
{ | |
public static String Spark(this string input) |
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 NameFiller : IPropertyFiller<string> | |
{ | |
private Random _rand; | |
private static Regex _combinedRegex = new Regex("name|fullname|firstname|lastname|surname|middlename|maidenname", RegexOptions.IgnoreCase); | |
private static Regex _fullNameRegex = new Regex("name|fullname", RegexOptions.IgnoreCase); | |
private static Regex _firstNameRegex = new Regex("firstname|middlename", RegexOptions.IgnoreCase); | |
private static Regex _surnameRegex = new Regex("lastname|surname|maidenname", RegexOptions.IgnoreCase); | |
private static List<string> _firstNames = new List<string> { "Luke", "John", "Mary" }; |
OlderNewer