Skip to content

Instantly share code, notes, and snippets.

View kzu's full-sized avatar

Daniel Cazzulino kzu

View GitHub Profile
/// <summary>
/// A hash combiner that is implemented with the Fowler/Noll/Vo algorithm (FNV-1a). This is a mutable struct for performance reasons.
/// Taken from https://gist.github.com/StephenCleary/4f6568e5ab5bee7845943fdaef8426d2
/// </summary>
public struct FnvHash
{
/// <summary>
/// The starting point of the FNV hash.
/// </summary>
public const ulong Offset = 14695981039346656037;
@attilah
attilah / X.Y.Z.Sources.csproj
Last active April 18, 2024 08:52
X.Y.Z.Sources nuget package
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>contentFiles</ContentTargetFolders>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
@DustinCampbell
DustinCampbell / using-msbuildworkspace.md
Created April 10, 2018 21:36
Using MSBuildWorkspace

Introduction

Roslyn provides a rich set of APIs for analyzing C# and Visual Basic source code, but constructing a context in which to perform analysis can be challenging. For simple tasks, creating a Compilation populated with SyntaxTrees, MetadataReferences and a handful of options may suffice. However, if there are multiple projects involved in the analysis, it is more complicated because multiple Compilations need to be created with references between them.

To simplify the construction process. Roslyn provides the Workspace API, which can be used to model solutions, projects and documents. The Workspace API performs all of the heavy lifting needed to parse SyntaxTrees from source code, load MetadataReferences, and construct Compilations and add references between them.

@AArnott
AArnott / StrongNameTokenFromPublicKey.cs
Last active July 14, 2017 12:39
Demonstrates calculating a strong name token from a public key
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace ConsoleApp43
{
static class Program
{
static void Main(string[] args)
@kzu
kzu / notnull.snippet
Last active March 25, 2020 13:49
ArgumentNullException C# Code Snippet
<?xml version="1.0" encoding="utf-8" ?>
<!--
Template for a null check for a parameter.
Press notnull[TAB][TAB] to get it.
Copy to Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets\notnull.snippet
Restart VS
-->
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*
Replace with your own usename and email:
------------------------------------------------
git config --global user.name "Username"
git config --global user.email "username@example.com"
These next two commands tell Git to use your Windows credentials to store your origin password.
------------------------------------------------
git config --global credential.helper wincred
git config --global credential.helper store
ruby -e "open(`gem which rubygems`.sub(/\.rb\s*\z/, '/ssl_certs/AddTrustExternalCARoot-2048.pem'), 'wb').write %(-----BEGIN CERTIFICATE-----\nMIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU\nMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs\nIFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290\nMB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux\nFDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h\nbCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v\ndDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt\nH7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9\nuMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX\nmk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX\na0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN\nE0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0\nWicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD\nVR0PBAQDAgEGMA8GA1UdEwEB
@kzu
kzu / fact.snippet
Last active July 5, 2016 19:24
Code snippet for creating BDD-style xUnit tests
<?xml version="1.0" encoding="utf-8" ?>
<!-- Download to %userprofile%\Documents\Visual Studio [2010|2012|2013|vNext]\Code Snippets\Visual C#\My Code Snippets -->
<!--
Template for xunit test methods
Press fact[tab][tab] to get it.
-->
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>XUnit test</Title>
@kzu
kzu / Class1.cs
Last active August 28, 2018 07:22
Generates class files from a text file and makes intellisense work
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DynamicIntellisense
{
public class Class1
{