Skip to content

Instantly share code, notes, and snippets.

View Sorting's full-sized avatar

Jimmy Sorting Sorting

  • Stegra.io
  • Sweden
View GitHub Profile
type Direction = Up | Right | Down | Left
type State = { map: Map<int * int, int>; pos: (int * int); dir: Direction; }
let manhattanDist x y = (fun (a, b) (c, d) -> abs (a - c) + abs (b - d)) x y
let initState =
{ map = Map.empty<int * int, int> |> Map.add (0, 0) 1
pos = (0, 1)
dir = Up }
@Sorting
Sorting / Advent of Code 2017 - Day 9.fs
Last active January 28, 2018 14:04
Advent of Code 2017 - F# - Day 9 Solution
type State = Group | Garbage | Cancel
type StateContainer = { state : State; level : int; score : int; garbage : int }
let solve stream =
stream
|> Seq.fold (fun current c ->
match (current.state, c) with
| Group, '{' -> { current with state = Group; level = current.level + 1 }
| Group, '<' -> { current with state = Garbage }
| Group, '}' -> { current with level = current.level - 1; score = current.score + current.level; }
using Microsoft.AspNetCore.Mvc;
namespace Sorting.SnakeCase.Controllers
{
public class SnakeCaseTestController : Controller
{
[Route("users")]
[HttpGet]
public IActionResult GetUser(string userName, string firstName, string lastName)
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc(options =>
{
options.ValueProviderFactories.Add(new SnakeCaseQueryValueProviderFactory());
})
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc();
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
});
}
@Sorting
Sorting / SnakeCaseQueryValueProviderFactory.cs
Created July 15, 2017 16:56
SnakeCaseQueryValueProviderFactory
using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Sorting.SnakeCase.Http.Mvc.ModelBinding
{
public class SnakeCaseQueryValueProviderFactory : IValueProviderFactory
{
@Sorting
Sorting / SnakeCaseQueryValueProvider.cs
Created July 15, 2017 16:55
A snake case query value provider that enables model binding of snake cased query parameters to pascal cased parameter names in C# and ASP.NET Core MVC.
using System.Globalization;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Http;
using Sorting.SnakeCase.Extensions;
namespace Sorting.SnakeCase.Http.Mvc.ModelBinding
{
public class SnakeCaseQueryValueProvider : QueryStringValueProvider, IValueProvider
@Sorting
Sorting / StringExtensions.cs
Last active September 14, 2017 18:37
Extension method to parse string to snake cased string
using System.Text;
namespace Sorting.SnakeCase.Utilities
{
public static class StringExtensions
{
public static string ToSnakeCase(this string s)
{
if (string.IsNullOrWhiteSpace(s))
{