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 Inventory | |
{ | |
public Dictionary<GarmentColor, int> Stock { get; set; } | |
public Inventory() | |
{ | |
Stock = new Dictionary<GarmentColor, int>(); | |
} | |
public void Add(GarmentColor color, int amount) |
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
[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); |
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 TravelingSalesman | |
{ | |
private static readonly Dictionary<string, Dictionary<string, int>> _connections = | |
new Dictionary<string, Dictionary<string, int>>(); | |
public static void PopulateConnections() | |
{ | |
if (_connections.Any()) | |
return; |
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
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 |
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
enum WarriorTalents | |
{ | |
None = 0, | |
Dauntless = 1, | |
Overpower, | |
SweepingStrikes, | |
Shockwave, | |
StormBolt, | |
DoubleTime, |
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 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); |
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
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() |
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
object ret = null; | |
var typeCode = Type.GetTypeCode(type); | |
// Special case simple value types: | |
// - Boolean | |
// - Byte, SByte | |
// - Char | |
// - Decimal | |
// - Int32, UInt32 | |
// - Int64, UInt64 |
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 JwtSecurityToken Generate(string userId, IEnumerable<Claim> claims) | |
{ | |
Requires.NotEmpty(userId, nameof(userId)); | |
// We're using a DateTimeOffset and later using the DateTime property thereof so we don't | |
// have to mess with extension methods to grab UNIX time, as DateTimeOffset has those built in. | |
var timeStamp = DateTimeOffset.UtcNow; | |
var token = new JwtSecurityToken(_options.Issuer, _options.Audience, claims, timeStamp.DateTime, | |
timeStamp.Add(_options.Expiration).DateTime, _options.SigningCredentials); |
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 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)); |
OlderNewer