Skip to content

Instantly share code, notes, and snippets.

View Drawaes's full-sized avatar

Tim Seaward Drawaes

  • Pltfm Limited
  • London
View GitHub Profile
@Drawaes
Drawaes / BigEndianReaders
Created September 17, 2016 13:20
Reader for BigEndian
public class BigEndianReaders
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort ReadUInt16(ref ReadableBuffer buffer)
{
var returnValue = PeekUInt16(buffer);
buffer = buffer.Slice(2);
return returnValue;
}
ReadableBuffer currentPayload;
int expectedPayloadSize = 0;
while (true)
{
var result = await _lowerConnection.Input.ReadAsync();
var buffer = result.Buffer;
try
{
if (buffer.IsEmpty && result.IsCompleted)
{
public static void Main(string[] args)
{
var x = Flip(10000);
var y = FlipNew(10000);
////var bench = new ReverseBench();
////bench.FlipInSets64Bit();
//BenchmarkRunner.Run<ReverseBench>();
}
public unsafe static ulong Flip(ulong val)
class Program
{
private static readonly TestStruct _Account = new TestStruct();
static void Main(string[] args)
{
Console.WriteLine(_Account.MyMoney);
_Account.UpdateValue(100);
Console.WriteLine(_Account.MyMoney);
@Drawaes
Drawaes / Bulk.cs
Last active March 10, 2017 23:00
Cleanup in progress
using System;
using System.Buffers;
using System.Buffers.Pools;
using System.IO.Pipelines;
using System.Runtime.InteropServices;
namespace Leto.BulkCipher
{
public sealed class AeadBulkCipher : IDisposable
{
@Drawaes
Drawaes / PRF.cs
Last active March 11, 2017 20:36
using Leto.Hash;
using System;
using System.Collections.Generic;
using System.Text;
namespace Leto.Hash
{
public static class PsuedoRandomExtensions
{
//https://tools.ietf.org/html/rfc5246#section-4.7
public struct BigEndianSpanReader
{
private Span<byte> _span;
public BigEndianSpanReader(Span<byte> span)
{
_span = span;
}
public int Length => _span.Length;
private async Task WritingLoop()
{
while(true)
{
var reader = Task.WhenAny(_handshakePipe.Reader.ReadAsync(), _inputPipe.Reader.ReadAsync());
RecordType recordType;
if (reader == handshakeReader)
{
recordType = RecordType.Handshake;
}
[Fact]
public void TestSyncBuffer()
{
var bytes = Encoding.UTF8.GetBytes("Hello there");
using (var factory = new PipeFactory())
{
var pipe = factory.Create();
var test = pipe.Writer.Alloc();
test.Write(bytes);
test.Commit();
using System;
using System.Collections.Generic;
namespace ConsoleApp2
{
public class ReloadingCache:IDisposable
{
private List<string> _cachedItems;
private System.Threading.Timer _timer;
private System.Threading.Mutex _mutex = new System.Threading.Mutex();