Skip to content

Instantly share code, notes, and snippets.

@stevencohn
stevencohn / git-issue-commenters.ps1
Created September 25, 2025 23:16
Get top commenters for all issues in specified repo
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[string] $owner = $env:GITHUB_USER,
[string] $token = $env:GITHUB_TOKEN,
[string] $repo = 'OneMore',
[string] $since = "$((Get-Date).Year)-01-01"
)
Begin
{
@stevencohn
stevencohn / remove-regions.cs
Created December 25, 2021 14:49
Remove all #region and #endregion lines from all *.cs files under a root folder
void Main()
{
// remove all occurances of #region and #endregion from CS files under a root folder
var root = @"C:\Users\steve\Downloads\System_Windows_Forms_Calendar_003";
var files = Directory.EnumerateFiles(root, "*.cs", SearchOption.AllDirectories);
if (files.Any())
{
var regex = new Regex(@"^\s*#(?:end)?region.*$");
@stevencohn
stevencohn / github-asset-downloads.cs
Created November 16, 2021 23:03
Report GitHub asset downloads, LinqPad snippet
async Task Main()
{
var releases = new List<Release>();
var page = 1;
while (await GetReleases(releases, page++));
releases.Dump();
}
/*
* Replaces the default xmlns namesapce for the given XElement and its descendants
* with the specified target namespace
*/
private static XElement RewriteNamespace(XElement element, XNamespace ns)
{
RewriteChildNamespace(element, ns);
// cannot change ns of root element directly so must rebuild it
@stevencohn
stevencohn / PruneXml.cs
Created December 22, 2020 13:40
Prune XML hierarchy branches that do not contain specific element
// Given an XElement, remove all leaf nodes that do NOT contain a specific node.
// Also removes ancestor branches that do not result in the specific leaf node.
// Useful for pruning hierarchies, such as a disk directory structure that only shows
// directory paths that contain files
void Prune(XElement element)
{
if (element.Elements().Any(e => e.Name.LocalName == "Page"))
{
return;