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
public class LazyDictionary<TKey, TValue> | |
{ | |
private readonly Func<TKey, TValue> _factory; | |
private readonly Dictionary<TKey, TValue> _cache; | |
public LazyDictionary(Func<TKey, TValue> factory) | |
{ | |
_factory = factory; | |
_cache = new Dictionary<TKey, TValue>(); | |
} |
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
var person = new Person(name: "James", age: 27); | |
var update = new PersonUpdate { age = 28 }; | |
var changes = Map.MapWithChanges(update, person); // Theoretical API | |
if(changes.Any()) | |
_db.Save(person); | |
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
public class CircularBuffer<T> | |
{ | |
private readonly int _size; | |
private readonly T[] _items; | |
private int _writeLocation = -1; | |
private readonly object _lock = new object(); | |
public CircularBuffer(int size) |
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
public class TestDependencyResolver : IDependencyResolver | |
{ | |
private readonly Dictionary<Type, Props> _registrations = new Dictionary<Type, Props>(); | |
public void Register<T>(Props instance) | |
{ | |
_registrations.Add(typeof(T), instance); | |
} | |
public Type GetType(string actorName) |
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
public static class DeterministicGrouping | |
{ | |
public static bool IsSelected(Guid entropy, ulong numerator, ulong denominator = 100) | |
{ | |
if(numerator > denominator) | |
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator cannot be larger than the denominator."); | |
if (numerator <= 0) | |
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator must be a positive non-zero value."); | |
if (denominator <= 0) | |
throw new ArgumentOutOfRangeException(nameof(denominator), "The denominator must be a positive non-zero value."); |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<configuration> | |
<system.webServer> | |
<rewrite> | |
<rules> | |
<rule name="BlockInvalidHosts" patternSyntax="Wildcard" stopProcessing="true"> | |
<match url="*" /> | |
<conditions> | |
<add input="{HTTP_HOST}" pattern="*.justgiving.com" negate="true" /> | |
</conditions> |
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
<?php | |
class Controller | |
{ | |
function getData(Period $period) | |
{ | |
return Model::where('created_at', '>', Carbon::create($period->year, $period->month, 1)); | |
} | |
} |
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
<template> | |
<div> | |
<model-overview | |
:title="title" | |
:models="models" | |
@select="changeModel" | |
@add="createModel" | |
/> | |
<complex-form |
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
use itertools::Itertools; | |
use std::fs; | |
fn main() { | |
let lines = fs::read_to_string("input.txt").expect("Couldn't read input file."); | |
let values: Vec<u32> = lines | |
.lines() | |
.map(|val| val.parse::<u32>().expect("Invalid value in input file!")) | |
.collect(); |
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
use indoc::indoc; | |
use itertools::Itertools; | |
fn main() { | |
let lines = include_str!("input"); | |
dbg!(part_one(lines)); | |
dbg!(part_two(lines)); | |
} |
OlderNewer