Skip to content

Instantly share code, notes, and snippets.

View Scooletz's full-sized avatar

Szymon Kulec Scooletz

View GitHub Profile
@Scooletz
Scooletz / BoundChecks.cs
Created December 21, 2019 14:10
A simple case of bound checks skipped with ref and Unsafe.Add
using System;
using System.Runtime.CompilerServices;
public class C
{
public static void A(Span<int> a)
{
a[0] = 1;
a[1] = 2;
a[2] = 3;
@Scooletz
Scooletz / sas.cs
Created March 17, 2018 14:48
Blob SAS Token
public static string GetBlobReadonlySasToken(CloudStorageAccount account)
{
var now = DateTimeOffset.Now;
// to address emulator running on http
var nonHttps = account.BlobEndpoint.ToString().StartsWith("http:");
var sas = account.GetSharedAccessSignature(new SharedAccessAccountPolicy
{
Services = SharedAccessAccountServices.Blob,
@Scooletz
Scooletz / TFChunk.cs
Last active February 15, 2018 07:31
EventStore's TFChunk writing a reversable entry
var workItem = _writerWorkItem;
var buffer = workItem.Buffer;
var bufferWriter = workItem.BufferWriter;
buffer.SetLength(4);
buffer.Position = 4;
record.WriteTo(bufferWriter);
var length = (int) buffer.Length - 4;
bufferWriter.Write(length); // length suffix
buffer.Position = 0;
@Scooletz
Scooletz / json.net.cs
Created February 2, 2018 21:17
JSON.NET serializers Guid
public override void WriteValue(Guid value)
{
InternalWriteValue(JsonToken.String);
string text = null;
#if HAVE_CHAR_TO_STRING_WITH_CULTURE
text = value.ToString("D", CultureInfo.InvariantCulture);
#else
text = value.ToString("D");
@Scooletz
Scooletz / perf-counter-timer-1h.cs
Created August 17, 2017 09:14
This gist provides a test showing that AverageTimer32 handles ticks greater than int.MaxValue
namespace Tests
{
using System;
using System.Diagnostics;
using System.Security;
using System.Threading;
using NUnit.Framework;
public class PerformanceCounterCategoryTest
{
@Scooletz
Scooletz / Program.cs
Last active April 25, 2017 04:48
ProtofbufRaw vs regular protobuf-net
using System;
using System.IO;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using ProtoBuf;
namespace Locals
{
class Program
@Scooletz
Scooletz / Program.cs
Last active April 21, 2017 08:35
ThreadStatic vs stackalloc
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace Locals
{
class Program
{
@Scooletz
Scooletz / CodeCopPossibleBug.cs
Last active March 2, 2016 06:48
Both tests don't work. When a struct is turned into a class, they start to work
using System;
using CodeCop.Core;
using CodeCop.Core.Fluent;
using NUnit.Framework;
namespace CodeCop.Tests
{
public class CodeCopStructBugTests
{
public unsafe struct WithPtr
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
@Scooletz
Scooletz / SqlClientSqlCommandSet.cs
Created September 11, 2015 05:19
System.Data.SqlClient.SqlCommandSet extracted from Data internals, better than NHibernate, as no delegates creation is required beside the first static ctor
public class SqlClientSqlCommandSet : IDisposable
{
private static readonly Type SqlCmdSetType;
private readonly object _instance;
private int _countOfCommands;
private readonly static Action<object, SqlConnection> SetConnection;
private readonly static Func<object, SqlConnection> GetConnection;
private readonly static Action<object, SqlTransaction> SetTransaction;
private readonly static Func<object, SqlCommand> GetCommand;