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
// guiding principles | |
// 1. to think in command / query separation - there are commands and there are queries | |
// strict CQRS recommends that commands do not return results apart from creation which returns an ID | |
// I can agree with that at a repo events level but not sure about command handlers however that does work here | |
// Useful links | |
// https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/CommandHandlers.cs | |
interface ICommandHandler<Command, ResultType> { | |
// you don't really need this interface but I am enforcing command handler shapes with it |
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
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> | |
<div class="editor"> | |
<h2>Input</h2> | |
<textarea id="editor" name="input-textarea" onchange="update(this)" placeholder="Try ^6hello world"> | |
</textarea> | |
<ul class="examples"> | |
<li><button type="button" onClick="window.rainbow()">Rainbow</button> | |
</ul> | |
</div> |
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
function bowlingScore(frames) { | |
const rolls = frames.split("").filter(function(value, index) { return value != " " }); | |
var frames = getFramesFromRolls(rolls); | |
var score = calculateScoreFromFrames(rolls, frames); | |
return score; | |
} | |
function getFramesFromRolls(rolls) { | |
if (rolls === undefined || rolls.length == 0) { return []; } |
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
function binSearch(arr, toSearch) { | |
var lowerBound = 0, upperBound = arr.length -1; | |
while(true) { | |
var index = Math.floor((upperBound - lowerBound) / 2 + lowerBound); | |
var current = arr[index]; | |
if(current === toSearch) return index; | |
if(current > toSearch) { |
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.Linq; | |
using NUnit.Framework; | |
namespace Alexw.Katas.BinarySearch | |
{ | |
public class BinarySearchTests | |
{ | |
private static readonly DataItem[] Items = | |
{ |
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
Mapper.CreateMap<List<ObjectId>, List<string>>().ConvertUsing(o => o.Select(os => os.ToString()).ToList()); | |
Mapper.CreateMap<List<string>, List<ObjectId>>().ConvertUsing(o => o.Select(os => ObjectId.Parse(os)).ToList()); | |
Mapper.CreateMap<ObjectId, string>().ConvertUsing(o => o.ToString()); | |
Mapper.CreateMap<string, ObjectId>().ConvertUsing(s => ObjectId.Parse(s)); |
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.Net; | |
using RestSharp; | |
namespace Alexw.ParkingAvailable | |
{ | |
public class KibanaClient | |
{ | |
private readonly IRestClient _client; | |
private readonly string _token; |
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.Net; | |
using System.Net.Sockets; | |
// taken from https://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net | |
public static class TcpPorts | |
{ | |
public static int GetFreeTcpPort() | |
{ | |
var l = new TcpListener(IPAddress.Loopback, 0); |
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
/// <summary> | |
/// Loop until a condition is met and your function returns true | |
/// </summary> | |
/// <param name="action">The delegate to run. Return true to exit the loop.</param> | |
/// <param name="delay">Return a timespan for the delay between loops</param> | |
/// <param name="whentoStop">Return true when the loop should stop when catching exceptions or looping</param> | |
public static void DoUntil(Func<bool> action, Func<int, TimeSpan, TimeSpan> delay, Func<int, TimeSpan, bool> whentoStop) | |
{ | |
var startedUtc = DateTime.UtcNow; | |
var amountOfRetriesAllowed = 0; |
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
# Your use statement can do all the work for you | |
app.Use(async (context, next) => | |
{ | |
if (!IsAuthenticated(context)) | |
{ | |
context.Response.StatusCode = 401; | |
var bytes = System.Text.Encoding.UTF8.GetBytes("You are not authorised!"); | |
context.Response.Body.Write(bytes, 0, bytes.Length); | |
await Task.FromResult(context); |
NewerOlder