Skip to content

Instantly share code, notes, and snippets.

GrahamTheCoder

Block or report user

Report or block GrahamTheCoder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View DictionaryExtensions.cs
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))
@GrahamTheCoder
GrahamTheCoder / GetNewAndEditedLineRangesFromMaster.ps1
Created Jul 1, 2016
Gets a list of line ranges (index and length if more than 1) for files changed since diverging from origin master
View GetNewAndEditedLineRangesFromMaster.ps1
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
You can’t perform that action at this time.