SpeedOfSpin
SpeedOfSpin
Reputation Top 1%
Erik Nodland
17 Snippets  (44th place)
Published
0 Channels
Created
8 Channels
Following
4460 points  (24th place)
Reputation
Top 10% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Serious Publisher
Senior Publisher
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Senior Famous Coder
Junior Wise Coder
Senior Popular Coder

Recent Snippets See all snippets by SpeedOfSpin

public by SpeedOfSpin  1140  2  4  0

Mime Types

nix
<system.webServer>
<staticContent>
    <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
    <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
    <mimeMap fileExtension=".ogg" mimeType="video/ogg" />
    <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
    <mimeMap fileExtension=".webm" mimeType="video/webm" />

    <mimeMap fileExtension=".oga" mimeType="audio/ogg" />
    <mimeMap fileExtension=".spx" mimeType="audio/ogg" />

    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />

    <remove fileExtension=".eot" />
    <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    <mimeMap fileExtension=".otf" mimeType="font/otf" />
    <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
</staticContent>
</system.webServer>
;

public by SpeedOfSpin  960  1  4  0

Retry

c#
public class Retry
    {
        /// <summary>
        /// Generic Retry
        /// </summary>
        /// <typeparam name="TResult">return type</typeparam>
        /// <param name="action">Method needs to be executed</param>
        /// <param name="retryInterval">Retry interval</param>
        /// <param name="retryCount">Retry Count</param>
        /// <param name="expectedResult">Expected Result</param>
        /// <param name="isExpectedResultEqual">true/false to check equal 
        /// or not equal return value</param>
        /// <param name="isSuppressException">
        /// Suppress exception is true / false</param>
        /// <returns></returns>
        public static TResult Execute<TResult>(
          Func<TResult> action,
          TimeSpan retryInterval,
          int retryCount,
          TResult expectedResult,
          bool isExpectedResultEqual = true,
          bool isSuppressException = true
           )
          {
            TResult result = default(TResult);

            bool succeeded = false;
            var exceptions = new List<Exception>();

            for (int retry = 0; retry < retryCount; retry++)
            {
                try
                {
                    if (retry > 0)
                        Thread.Sleep(retryInterval);
                    // Execute method
                    result = action();

                    if (isExpectedResultEqual)
                        succeeded = result.Equals(expectedResult);
                    else
                        succeeded = !result.Equals(expectedResult);
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }

                if (succeeded)
                    return result;
            }

            if (!isSuppressException)
                throw new AggregateException(exceptions);
            else
                return result;
        }
    }      
;

public by SpeedOfSpin  2146  3  5  0

SetTimeout Equivalent

var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

Task.Delay(2000).ContinueWith(async (t) =>
{
  //Do stuff
}, cancellationToken);                      
;

public by SpeedOfSpin  236364  2  3  0

Verbose Debugging output on Azure

c#
RoleEnvironment.TraceSource.Switch.Level = SourceLevels.Information;                 
;

public by SpeedOfSpin  2428  2  3  0

Grouping data using Linq

c#
var data = File.ReadAllText("c:\\temp\\ftshorse.csv").FromCsv<List<Horse>>();
var grouped = data.GroupBy(a => new {a.event_date, a.meeting, a.event_time}).Select(a=> new Race()
{
    Meeting = a.Key.meeting, EventDate = a.Key.event_date, EventTime = a.Key.event_time, Horses = a.ToList()
});       
;