Skip to content

Instantly share code, notes, and snippets.

View GrahamTheCoder's full-sized avatar

Graham GrahamTheCoder

View GitHub Profile
@GrahamTheCoder
GrahamTheCoder / GetNewAndEditedLineRangesFromMaster.ps1
Created July 1, 2016 17:48
Gets a list of line ranges (index and length if more than 1) for files changed since diverging from origin master
function Get-LinesChanged() {
$diffFromCommonBase = git diff origin/master...HEAD --unified=0 --dst-prefix=""
$linesByFile = @{}
$currentLines = New-Object System.Collections.ArrayList
foreach ($diffLine in $diffFromCommonBase ) {
if ($diffLine.StartsWith("+++")) {
#e.g. "+++ Path/to/file.cs" -> "Path/to/file.cs"
$currentFile = $diffLine.Substring(4)
$currentLines = $linesByFile[$currentFile] = New-Object System.Collections.ArrayList
@GrahamTheCoder
GrahamTheCoder / DictionaryExtensions.cs
Created September 26, 2019 09:48
DictionaryExtensions
public static class DictionaryExtensions
{
public static TValue Get<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))