Skip to content

Instantly share code, notes, and snippets.

View AArnott's full-sized avatar

Andrew Arnott AArnott

View GitHub Profile
@ryanrousseau
ryanrousseau / OAuth2Authorize.cs
Created June 22, 2012 13:30
OAuth2 Authorize Attribute for MVC Web API
using System;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.ServiceModel.Channels;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
@bradwilson
bradwilson / gist:4215933
Last active August 17, 2020 16:46
.gitconfig
[user]
name = Brad Wilson
email = dotnetguy@gmail.com
[alias]
a = add -A
abort = rebase --abort
amend = commit --amend -C HEAD
bl = blame -w -M -C
br = branch
cat = cat-file -t
@nguerrera
nguerrera / DelegateToStaticWithFirstArg.cs
Last active August 29, 2015 14:05
Creating a delegate bound to a static method with first argument in verifiable IL
// And this program can be writen in C# after all if you use an extension method!
// (And the codegen is exactly as the optimal hand-written IL below.)
//
// Thanks to Vladimir Sadov on the compiler team for teaching me about it!
static class Program
{
static void Main()
{
var f = new Func<string>("World".StaticMethod);
@geraintluff
geraintluff / base64-web-safe.js
Created October 9, 2015 15:36
Convert base64 to and from web-safe variant
// Convert from normal to web-safe, strip trailing "="s
function webSafe64(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
// Convert from web-safe to normal, add trailing "="s
function normal64(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
}
@vbfox
vbfox / ExtractNestedClassesToSeparateFiles.fs
Last active November 3, 2015 00:00
Extract nested classes/struct/enums to their own files
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp
open Microsoft.CodeAnalysis.CSharp.Syntax
open Microsoft.CodeAnalysis.MSBuild
open Microsoft.CodeAnalysis.Formatting
open System.IO
module FluentRoslynLite =
let (!!) t = Async.AwaitTask t
let emptyFile = SyntaxFactory.CompilationUnit()
@kzu
kzu / vsmef.linq
Created July 8, 2016 15:58
VSMEF Components
var xmlns = new XmlNamespaceManager(new NameTable());
xmlns.AddNamespace("vsx10", "http://schemas.microsoft.com/developer/vsx-schema/2010");
xmlns.AddNamespace("vsx11", "http://schemas.microsoft.com/developer/vsx-schema/2011");
var vsix = from file in Directory.EnumerateFiles(@"C:\Program Files (x86)\Microsoft Visual Studio 14.0", "extension.vsixmanifest", SearchOption.AllDirectories)
where File.ReadAllLines(file)[0].StartsWith("<")
select file;
var mef = vsix
.Select(x => XDocument.Load(x))
@joyrexus
joyrexus / README.md
Last active February 24, 2024 15:16
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
@trippwill
trippwill / Microsoft.PowerShell_profile.ps1
Created December 9, 2019 16:57
PowerShell Core Profile
### Customize Prompt for Visual Studio Developer PowerShell
# Get the current prompt
$defaultPrompt = (Get-Item function:prompt).ScriptBlock
# Setup the custom prompt
function prompt {
$pr = if (Test-Path env:/VSINSTALLDIR) { "[VS $env:VisualStudioVersion]:" }
else {''}
Write-Host $pr -NoNewline -ForegroundColor DarkMagenta
@jiripolasek
jiripolasek / ReflectionExtensions.cs
Last active November 23, 2020 04:45
Detect init-only property using reflection
public static class ReflectionExtensions
{
/// <summary>
/// Gets a value indicating whether property has init accessor declared.
/// </summary>
/// <param name="propertyInfo"></param>
/// <returns>Returns <c>true</c> if the property is declared as init-only; otherwise returns <c>false</c>.</returns>
public static bool IsInitOnly(this PropertyInfo propertyInfo)
{
if (propertyInfo == null)
@AlexVallat
AlexVallat / msbuild-itemgroup-intersection.md
Created March 4, 2021 18:20
MSBuild ItemGroup Intersection

It's not obvious how to produce an intersection of two itemgroups in MSBuild. There's this brainteaser solution based on tricky metadata behaviour, but it only works inside a <target> due to it's use of metadata.

There is another way. Algebra tells us that A ∩ B = A ∖ (A∖B): intersection of A and B is A excluding (A excluding B). This can be expressed in MSBuild as:

<ItemGroup>
	<A Include="1" />
	<A Include="2" />
	<A Include="3" />