Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

public class Inventory
{
public Dictionary<GarmentColor, int> Stock { get; set; }
public Inventory()
{
Stock = new Dictionary<GarmentColor, int>();
}
public void Add(GarmentColor color, int amount)
[Subject(typeof(Inventory), "customer swapping garment")]
public class GarmentSpecifications
{
private static Inventory _inventory;
Establish context = () =>
{
// Establish the context for our test case, set up the required objects, etc.
_inventory = new Inventory();
_inventory.Add(GarmentColor.Black, 3);
public static class TravelingSalesman
{
private static readonly Dictionary<string, Dictionary<string, int>> _connections =
new Dictionary<string, Dictionary<string, int>>();
public static void PopulateConnections()
{
if (_connections.Any())
return;
@aevitas
aevitas / lifx.cs
Created May 30, 2016 14:57
LIFX REST
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Lifx.Core.Internal;
using Lifx.Core.Protocol;
using RestSharp;
using RestSharp.Authenticators;
using RestSharp.Serializers;
namespace Lifx.Core
enum WarriorTalents
{
None = 0,
Dauntless = 1,
Overpower,
SweepingStrikes,
Shockwave,
StormBolt,
DoubleTime,
@aevitas
aevitas / Dataflow.cs
Created August 23, 2016 09:24
Extension of the System.Threading.Dataflow library providing pipeline functionality
public static class Dataflow
{
internal static readonly DataflowLinkOptions DefaultLinkOptions = new DataflowLinkOptions {PropagateCompletion = true};
/// <summary>
/// Creates a dataflow from the specified blocks, assuming the first block as the input block, and linking subsequent
/// blocks together.
/// </summary>
/// <typeparam name="TInput">The type of the input.</typeparam>
/// <param name="name">The name.</param>
@aevitas
aevitas / PrimitiveTypeRead.cs
Last active November 25, 2016 11:45
Special type reads LocalProcessMemory
object ret = null;
var typeCode = Type.GetTypeCode(type);
// Special case simple value types:
// - Boolean
// - Byte, SByte
// - Char
// - Decimal
// - Int32, UInt32
// - Int64, UInt64
@aevitas
aevitas / Read`1.cs
Last active November 16, 2016 12:56
public override unsafe T Read<T>(IntPtr address, bool isRelative = false)
{
Requires.NotEqual(address, IntPtr.Zero, nameof(address));
// We can bypass the marshal completely, unless the type we're reading has marshalling
// directives such as a [MarshalAs] attribute.
bool requiresMarshal = MarshalCache<T>.TypeRequiresMarshal;
var size = requiresMarshal ? MarshalCache<T>.Size : Unsafe.SizeOf<T>();
var buffer = ReadBytes(address, size, isRelative);
private static void BenchmarkReadsMarshal()
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(int))];
fixed (byte* b = buffer)
for (int i = 0; i < numIterations; i++)
Marshal.PtrToStructure<int>(new IntPtr(b));
}
private static void BenchmarkReadsUnsafe()
public class TokenProviderOptions
{
public TokenProviderOptions(string path, string issuer, string audience, TimeSpan expiration,
SigningCredentials signingCredentials)
{
Requires.NotEmpty(path, nameof(path));
Requires.NotEmpty(issuer, nameof(issuer));
Requires.NotEmpty(audience, nameof(audience));
Requires.NotNull(signingCredentials, nameof(signingCredentials));