Skip to content

Instantly share code, notes, and snippets.

@vkhorikov
vkhorikov / CustomerController.cs
Last active May 25, 2024 19:53
Handling failures and input errors in a functional way
[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(
@colmmacc
colmmacc / shardcalc.py
Last active August 7, 2023 11:05
Calculate the blast radius of a shuffle shard
import sys
# choose() is the same as computing the number of combinations. Normally this is
# equal to:
#
# factorial(N) / (factorial(m) * factorial(N - m))
#
# but this is very slow to run and requires a deep stack (without tail
# recursion).
#
@CyrusJavan
CyrusJavan / justify_text.go
Created October 23, 2020 21:23
Justify Text - techincal interview question and answer written in Golang with many comments explaing the answer.
package main
import (
"fmt"
"strings"
)
func main() {
text := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras " +
"venenatis, quam et dapibus porttitor, nisi mauris maximus sapien, a " +