Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Threading.Tasks;
namespace RetryPolicies
{
internal sealed class ExponentialRetryPolicy
{
public TimeSpan InitialDelay { get; set; } = TimeSpan.FromSeconds(10);
public int NumberOfRetries{ get; set; } = 5;
(?x)
(?<![0-9])
(?:
[0-9]{12,19} # sequence of digits in the text between [12, 19] length
|
(?:[0-9]{4}[ -]){4}[0-9]{3} # 4-4-4-4-3 pattern
|
(?:[0-9]{4}[ -]){3}[0-9]{4} # 4-4-4-4 pattern
|
(?:[0-9]{4}[ -]){2}[0-9]{5} # 4-4-5 pattern
using System;
public class Program
{
public static void Main()
{
int[] arr = {-2, -3, 4, -1, -2, 1, 5, -3};
var result = LargestSumContiguousSubarray(arr);
Console.Write(result);
}
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
int[] values = {110, 100, 200 };
int[] weights = {10, 20, 30};
int maxWeight = 30;
@kpol
kpol / BinarySearch.cs
Last active September 15, 2020 02:19
public static int BinarySearch(int[] arr, int k)
{
var minIndex = 0;
var maxIndex = arr.Length - 1;
while (minIndex <= maxIndex)
{
var mid = (minIndex + maxIndex) / 2;
if (k == arr[mid])
public interface IMemoryCacheExtended : IMemoryCache
{
TItem GetOrCreate<TItem>(object key, Func<ICacheEntry, TItem> factory);
Task<TItem> GetOrCreateOnceAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory);
}
public class MemoryCacheExtended : IMemoryCache
{
private readonly MemoryCache _memoryCache;
@kpol
kpol / Kata09.cs
Last active April 15, 2019 02:28
Kata09: Back to the Checkout
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
var product = new Product(1) { Price = 10 };
@kpol
kpol / IsValidCreditCardNumber.cs
Last active December 11, 2018 21:34
Checks number against Luhn algorithm/
private static bool IsValidCreditCardNumber(string creditCardNumber)
{
// based on Luhn algorithm
// https://en.wikipedia.org/wiki/Luhn_algorithm
if (creditCardNumber == null) throw new ArgumentNullException(nameof(creditCardNumber));
// credit card number length must be between [12, 19]
if (creditCardNumber.Length < 12 || creditCardNumber.Length > 19)
{
@kpol
kpol / SwaggerXTypeEnumConsolidator.cs
Last active January 30, 2019 22:21
Consolidates enums for Swagger file
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace OpenApi.Extensions
{
/// <summary>
/// Consolidates enums based on <code>x-type-fullname</code> vendor extension.
/// <example>
/// {
@kpol
kpol / SwashbuckleFilters.cs
Last active October 3, 2018 03:01
Swashbuckle filters to add enum type into Swagger (OpenAPI) spec file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Description;
using Newtonsoft.Json.Serialization;
using Swashbuckle.Swagger;
namespace Swagger.Configurations
{
public class SwashbuckleDocument