Skip to content

Instantly share code, notes, and snippets.

View alexander-williamson's full-sized avatar

Alexander Williamson alexander-williamson

View GitHub Profile
@alexander-williamson
alexander-williamson / gist:4f0726f3d31f38c16c284f164b46c5f9
Created November 27, 2017 21:12 — forked from efbenson/gist:4259486
Automapper for MongoDB ObjectIds
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));
using System;
using System.Linq;
using NUnit.Framework;
namespace Alexw.Katas.BinarySearch
{
public class BinarySearchTests
{
private static readonly DataItem[] Items =
{
@alexander-williamson
alexander-williamson / mario.js
Created August 27, 2019 14:50
Binary Search Kata in Javascript
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) {
@alexander-williamson
alexander-williamson / javascript.js
Last active September 10, 2019 22:25
Javascript Bowling Kata
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 []; }
<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>
// 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