Skip to content

Instantly share code, notes, and snippets.


Kevin Berridge kberridge

View GitHub Profile
kberridge /
Created Apr 20, 2020
Invoke-Build direct calling bootstrap script (load or install compatible msbuild version, self updating and support different versions in different projects)
param (
#... other params
function IsVersionCompatible($requiredVersion, $testVersion) {
# same major, and AT LEAST the required minor and build
$testVersion.Major -eq $requiredVersion.Major `
-and $testVersion.Minor -ge $requiredVersion.Minor `
View Command.cs
public interface ICommand
View ElementScopeExtensions.cs
public static bool HasValue(this ElementScope scope, string text, Options options = null)
var f = scope.GetType().GetField("options", BindingFlags.Instance | BindingFlags.NonPublic);
var config = (Options)f.GetValue(scope);
var robustly = new RetryUntilTimeoutRobustWrapper();
return robustly.Robustly(new HasValueQuery(scope, text, options ?? config));
class HasValueQuery : Query<bool>
kberridge / task.cs
Created Dec 17, 2012
How would you slice out the concerns in this object, and what would you name the resulting objects?
View task.cs
public class Task : ActiveRecord
public string Name { get; set; }
public int AssignedTo_UserId { get; set; }
public DateTime DueOn { get; set; }
public Task()
DueOn = DateTime.Now.AddDays(1);
kberridge / nuget-restore.ps1
Created Dec 14, 2012
This powershell script performs the same function as VS's nuget package restore, but it does so without modifying the project files. So shared projects can still be shared between different solutions with different file layouts (or even some doing package restores and some not). The downside is it doesn't integrate with msbuild, so you have to r…
View nuget-restore.ps1
$packageConfigs = dir -r -include packages.config -exclude **\.hg\** | %{ $_.FullName }
$packageConfigs | %{ nuget.exe install $_ }
kberridge / canopy-dynamic-load-contexts.fs
Created Nov 30, 2012
canopy: dynamically find and initialize contexts in all files in a project
View canopy-dynamic-load-contexts.fs
// ContextAttribute.fs
module ContextAttribute
type ContextAttribute() =
inherit System.Attribute()
// example_test_file.fs
module example_test_file
open canopy
kberridge / word-ladder.fsx
Created Jun 10, 2012
F# solution to the word ladder problem
View word-ladder.fsx
let words = System.IO.File.ReadAllLines("four-char-dictionary.txt")
let isWordInDict word =
words |> Seq.exists (fun w -> w = word)
let filterToDict words =
words |> List.filter isWordInDict
let filterNotSeen (seen : Set<string>) words =
words |> List.filter (fun w -> not(seen.Contains(w)))
kberridge / find-connected-graphs.fsx
Created Jun 3, 2012
F# solution to "find connected subgraphs in graph" exercise
View find-connected-graphs.fsx
type 'a Node = 'a * 'a list
type 'a Graph = 'a Node list
let g = [('a', ['b'; 'd']); ('b', ['a'; 'c'; 'd']); ('c', ['b']); ('d', ['a'; 'b']); ('e', ['f']); ('f', ['e'])]
let findConnectedGraph (map : Map<'a, 'a list>) (firstVal : 'a) =
let rec walk (seen : 'a list) (tosearch : 'a list) =
let isSeen n =
seen |> List.exists (fun i -> i=n)
let notSeenOnly (nodes : 'a list) =
nodes |> List.filter (fun i -> not <| isSeen i)
kberridge / gist:2660500
Created May 11, 2012
razor and javascript regex
View gist:2660500
@{var anEmptyRegex = "";}
<script type="text/javascript">
var r = /@anEmptyRegex/i;
-- Razor Output --
<script type="text/javascript">
kberridge / 1-Simplest.cs
Created Feb 5, 2012
The Cost of DI: 4 different versions of the same code, demonstrating the cost of added indirection
View 1-Simplest.cs
public class SpeakerController : Controller
public ActionResult Create(int presentationId, FormCollection data)
var presentation = Presentation.Find(presentationId);
var vm = SpeakerNewViewModel.Build(presentation);
UpdateModel(vm, data);
var presentationApi = new PresentationApi(presentationId);