Skip to content

Instantly share code, notes, and snippets.

View jcansdale's full-sized avatar

Jamie Cansdale jcansdale

View GitHub Profile
@jcansdale
jcansdale / GetAssemblies.cs
Last active August 14, 2016 21:57
.NET Core implementation of AppDomain.GetAssemblies()
public Assembly[] GetAssemblies()
{
var assemblies = new List<Assembly>();
foreach(ProcessModule module in Process.GetCurrentProcess().Modules)
{
try
{
var assemblyName = AssemblyLoadContext.GetAssemblyName(module.FileName);
var assembly = Assembly.Load(assemblyName);
assemblies.Add(assembly);
@jcansdale
jcansdale / gist:7fa50ede36d712b54b77c746e3f54bdf
Created July 22, 2016 11:07
Some utility methods for poking around .NET Core.
namespace Utilities
{
using System;
using System.Collections;
using System.Collections.Generic;
public static class NetCoreUtilities
{
public static string[] GetTrustedPlatformAssemblies()
{
static string getNamePreserveCase(EnvDTE.Document doc)
{
var name = doc.Name;
var fullName = doc.ProjectItem.FileNames[0];
name = fullName.Substring(fullName.Length - name.Length, name.Length);
return name;
}
@jcansdale
jcansdale / details.md
Last active August 12, 2016 08:55
Using `<details>` in GitHub

Using <details> in GitHub

Suppose you're opening an issue and there's a lot noisey logs that may be useful.

Rather than wrecking readability, wrap it in a <details> tag!

<details>
 <summary>Summary Goes Here</summary>
 ...this is hidden, collapsable content...
@jcansdale
jcansdale / gist:2af856d3a6451d67d734fffe4a65e830
Created September 9, 2016 13:53
Compile vs manual evaluation
```ini
Host Process Environment Information:
BenchmarkDotNet.Core=v0.9.9.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-4500U CPU 1.80GHz, ProcessorCount=4
Frequency=2338341 ticks, Resolution=427.6536 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=32-bit ?
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1586.0
@jcansdale
jcansdale / ExpressionInvokerBenchmark.md
Created September 9, 2016 13:54
Compile vs manual evaluation
Host Process Environment Information:
BenchmarkDotNet.Core=v0.9.9.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-4500U CPU 1.80GHz, ProcessorCount=4
Frequency=2338341 ticks, Resolution=427.6536 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=32-bit ?
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1586.0
@jcansdale
jcansdale / ExpressionUtilities.cs
Created September 9, 2016 17:31
Helper methods to quickly evaluate simple expressions
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq.Expressions;
public static class ExpressionUtilities
{
public static object GetValue(Expression expression)
{
return getValue(expression, true);
@jcansdale
jcansdale / TestDrivenBenchmarks.cs
Created September 15, 2016 14:34
How to quickly preview benchmarks using TestDriven.Net.
// Add the `BenchmarkDotNet.TestDriven` NuGet package.
using System;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.TestDriven;
// Let TestDriven.Net know how to run benchmarks.
[assembly: BenchmarkTestRunner(typeof(FastAndDirtyConfig))]
@jcansdale
jcansdale / NuGet.config
Created September 15, 2016 15:10
How to setup a `LocalPackages` folder for NuGet
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="LocalPackages" value="./LocalPackages" />
</packageSources>
<activePackageSource>
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
@jcansdale
jcansdale / challenge.md
Last active January 24, 2020 19:56
Unit testing challenge

I'm looking for the cleanest way to make the test below pass.

The rules are:

  1. It must be a unit test (so don't touch the file system).
  2. The public signature for CodeUnderTest must not be changed. can be extended not reduced
  3. You're allowed to use DI/your favorite mocking framework.
  4. You can only add code where you see /**/.