Skip to content

Instantly share code, notes, and snippets.

View samjones00's full-sized avatar
🎯
Focusing

Sam Jones samjones00

🎯
Focusing
  • London
View GitHub Profile
@samjones00
samjones00 / prepare-commit-msg.sh
Created January 16, 2022 23:17 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
namespace Benchmark.Console
{
public class SumNumbersBenchmark
{
private static readonly ExampleService process = new ExampleService();
[Benchmark]
public void Linq() => process.Linq();
[Benchmark]
using System;
using System.Linq;
namespace Benchmark.Core
{
public class ExampleService
{
public int[] Values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public void Linq()
Method Mean Error StdDev
Linq 44.962 ns 0.5980 ns 0.5594 ns
ForEach 5.291 ns 0.0383 ns 0.0339 ns
using ValueObject.Domain.ValueObjects;
namespace ValueObject.Console
{
class Program
{
static void Main(string[] args)
{
var nullValue = TelephoneNumber.From(null); // throws exception
var emptyValue = TelephoneNumber.From(""); // throws exception
using System;
namespace ValueObject.Exceptions
{
public class InvalidTelephoneNumberFormatException : Exception
{
public InvalidTelephoneNumberFormatException(string value, string message) : base($"Invalid telephone number format: {value}. {message}")
{
}
}
using System;
using System.Text.RegularExpressions;
using ValueObject.Exceptions;
using ValueOf;
namespace ValueObject.Domain.ValueObjects
{
public class TelephoneNumber : ValueOf<string, TelephoneNumber>
{
private const int MinLength = 8;
@samjones00
samjones00 / InvalidTelephoneNumberFormatException.cs
Created October 11, 2021 21:41
A telephone number value object
using System;
namespace ValueObject.Exceptions
{
public class InvalidTelephoneNumberFormatException : Exception
{
public InvalidTelephoneNumberFormatException(string value, string message) : base($"Invalid telephone number format: {value}. {message}")
{
}
}
@samjones00
samjones00 / WeatherService.cs
Created September 16, 2021 14:26
Mocking API Responses - the service making the call
public class WeatherService : IWeatherService
{
private readonly HttpClient _httpClient;
public WeatherService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<WeatherRoot> GetWeatherAsync(WeatherServiceRequest request)
@samjones00
samjones00 / docker-compose.yaml
Created June 27, 2021 12:05
Running event store from docker-compse
version: '3.4'
services:
eventstore.db:
image: eventstore/eventstore:20.10.2-buster-slim
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
- EVENTSTORE_START_STANDARD_PROJECTIONS=true
- EVENTSTORE_EXT_TCP_PORT=1113