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
[HttpPost] | |
public HttpResponseMessage CreateCustomer(string name, string billingInfo) | |
{ | |
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo); | |
Result<CustomerName> customerNameResult = CustomerName.Create(name); | |
return Result.Combine(billingInfoResult, customerNameResult) | |
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value)) | |
.OnSuccess(() => new Customer(customerNameResult.Value)) | |
.OnSuccess( |
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 System; | |
using System.Collections.Generic; | |
using System.Threading; | |
using Topshelf; | |
namespace ConsoleApplication | |
{ | |
public interface IProcess | |
{ | |
void Perform(); |
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 System; | |
using System.Collections.Generic; | |
using System.Threading; | |
using Topshelf; | |
namespace ConsoleApplication | |
{ | |
public interface IProcess | |
{ | |
void Perform(); |
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 System; | |
using System.Collections.Generic; | |
using System.Timers; | |
using Topshelf; | |
namespace ConsoleApplication | |
{ | |
public interface IProcess | |
{ | |
void ProcessHandler(object o, ElapsedEventArgs args); |
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
// insert into the same Frame | |
f.AddColumn("Column_CMA", Stats.expandingMean(f.GetColumn<double>("Column"))); | |
f.AddColumn("Column_MVA3", Stats.movingMean(3, f.GetColumn<double>("Column"))); | |
f.AddColumn("Column_MVA7", Stats.movingMean(7, f.GetColumn<double>("Column"))); | |
// or as extension method | |
public static void AddMovingAverage(this Frame<DateTime, string> source, string column, int length) | |
{ | |
if (length < 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
SELECT | |
Date | |
,Value | |
,CAST(ROUND(100 * (Value / LAG(Value, 1, Value) OVER (ORDER BY Date) - 1), 2) AS NUMERIC(16, 2)) AS 'Return' | |
FROM Totals | |
ORDER BY Date; |
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
-- Cumulative Moving Average (CMA) and Simple Moving Average (SMA) | |
SELECT | |
d.Value, | |
AVG(d.Value) OVER (PARTITION BY d.MetricId ORDER BY d.Id) AS 'CMA', | |
AVG(d.Value) OVER (PARTITION BY d.MetricId ORDER BY d.Id ROWS 2 PRECEDING) AS 'SMA(3)', | |
AVG(d.Value) OVER (PARTITION BY d.MetricId ORDER BY d.Id ROWS 6 PRECEDING) AS 'SMA(7)' | |
FROM DailyTotals AS d | |
WHERE | |
d.DateId >= '20150101' | |
AND d.MetricId = 2; |
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
private static void LowLatencyDemo() | |
{ | |
GCLatencyMode oldMode = GCSettings.LatencyMode; | |
System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); | |
try | |
{ | |
GCSettings.LatencyMode = GCLatencyMode.LowLatency; | |
// Run your code here... | |
} | |
finally |
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 class MovingAverageExtensions | |
{ | |
public static IEnumerable<decimal> CumulativeMovingAverage(this IEnumerable<decimal> source) | |
{ | |
ulong count = 0; | |
decimal sum = 0; | |
foreach (var d in source) | |
{ | |
yield return (sum += d) / ++count; |