Skip to content

Instantly share code, notes, and snippets.

View sharwell's full-sized avatar
🏠
Working from home

Sam Harwell sharwell

🏠
Working from home
View GitHub Profile
@sharwell
sharwell / Wrapping.cs
Created January 29, 2014 17:24
Infinite loop, or clean wrapper?
static class Helper
{
public static T WrapCall<T>(Func<T> func)
{
Console.WriteLine("Calling function");
return func();
}
}
class Foo
@sharwell
sharwell / FunnyCalls.cs
Created January 29, 2014 18:36
The assertions in the test method all pass. Read carefully :)
[TestMethod]
public void TestCalls()
{
FooDerived foo = new FooDerived();
Func<int> method = foo.Bar;
Assert.AreEqual(1, method());
method = foo.FooBar();
Assert.AreEqual(1, method());
@sharwell
sharwell / CaseInsensitiveStringStream.cs
Created February 19, 2014 05:10
Case-insensitive ANTLRStringStream for ANTLR 3
using Antlr.Runtime;
public class CaseInsensitiveStringStream : ANTLRStringStream
{
// the string used for lookahead (performance improvement by not having to call Char.ToLowerInvariant())
private readonly string _lastring;
public CaseInsensitiveStringStream(string input, string sourceName)
: base(input, sourceName)
{
@sharwell
sharwell / Test.cs
Created April 20, 2014 18:16
Reversing an RFC 6570 URI Template
namespace Testing.Rfc6570
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rackspace.Net;
[TestClass]
public class SampleTest
{
[TestMethod]
@sharwell
sharwell / SoftLayerIdentityProvider.cs
Created August 12, 2014 19:03
SoftLayer Identity Provider Example (WIP)
namespace net.openstack.Providers.SoftLayer
{
using System;
using System.Linq;
using net.openstack.Core.Caching;
using net.openstack.Core.Domain;
using net.openstack.Core.Providers;
using net.openstack.Providers.Rackspace;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
param(
[string]$Assembly,
[string]$ExpectedKey,
[string]$Build = $null
)
function Get-PublicKeyToken() {
param([string]$assembly = $null)
if ($assembly) {
$bytes = $null
@sharwell
sharwell / IOutputWindowPane.cs
Created August 31, 2012 09:17
MEF support for the Output Window in Visual Studio 2010: IOutputWindowPane
namespace JavaLanguageService.Panes
{
using System;
public interface IOutputWindowPane : IDisposable
{
string Name
{
get;
set;
@sharwell
sharwell / IOutputWindowDefinitionMetadata.cs
Created August 31, 2012 09:21
MEF support for the Output Window in Visual Studio 2010: IOutputWindowDefinitionMetadata
namespace JavaLanguageService.Panes
{
internal interface IOutputWindowDefinitionMetadata
{
string Name
{
get;
}
}
}
@sharwell
sharwell / OutputWindowService.cs
Created August 31, 2012 09:22
MEF support for the Output Window in Visual Studio 2010: OutputWindowService
namespace JavaLanguageService.Panes
{
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using JavaLanguageService.Extensions;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
@sharwell
sharwell / ServiceProviderExtensions.cs
Created August 31, 2012 09:24
MEF support for the Output Window in Visual Studio 2010: ServiceProviderExtensions
namespace JavaLanguageService.Extensions
{
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
public static class ServiceProviderExtensions
{