Skip to content

Instantly share code, notes, and snippets.

View devlead's full-sized avatar

Mattias Karlsson devlead

View GitHub Profile
@devlead
devlead / ConsoleBufferToHtml.ps1
Last active January 30, 2024 22:24
ConsoleBufferToHtml.ps1 - Powershell script to dump console buffer as html to file.
<#
.SYNOPSIS
This is a Powershell script to dump console buffer as html to file.
.DESCRIPTION
This Powershell script will iterate over the current console buffer and
output it as html preserving colors.
.PARAMETER FilePath
@devlead
devlead / parsegitlog.ps1
Created October 29, 2015 17:30
Example working with git log in PowerShell
# Get last 100 log entries as a PowerShell object
$gitHist = (git log --format="%ai`t%H`t%an`t%ae`t%s" -n 100) | ConvertFrom-Csv -Delimiter "`t" -Header ("Date","CommitId","Author","Email","Subject")
# Now you can do iterate over each commit in PowerShell, group sort etc.
# Example to get a commit top list
$gitHist|Group-Object -Property Author -NoElement|Sort-Object -Property Count -Descending
# Example do something for each commit
$gitHist|% {if ($_.Author -eq "Mattias Karlsson") {"Me"} else {"Someone else"} }
@devlead
devlead / README.md
Created April 1, 2015 14:02
Windows 10 aware app.manifest

OSVersion

In windows 8.1 Environment.OSVersion underlying Win32 GetVersionEx function changed to for compatibility reasons report latest version app is compiled for.

The code

Console.WriteLine(
    System.Environment.OSVersion
    );
@devlead
devlead / taskname.cake
Created November 25, 2020 14:19
Example use task setup/teardown to modify build state
public class BuildData
{
public string TaskName { get; set; }
}
Setup(context => new BuildData());
TaskSetup<BuildData>(
(context, data) => data.TaskName = context.Task.Name
);
@devlead
devlead / .gitignore
Last active October 5, 2020 06:07
Fluent Tasks
[Tt]ools/
[Aa]rtifacts/
[Oo]bj/
[Bb]in/
.vscode/
@devlead
devlead / DynamicTest.csproj
Last active August 21, 2020 19:10
Example .NET Core app create objects from type name
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
@devlead
devlead / teardown_errorlog.cake
Last active February 10, 2020 18:06
teardown_errorlog.cake
Task("BOOM")
.Does(() => throw new Exception("BOOM"));
Teardown(ctx => {
for(var i = 1; i <= 15; i++)
{
Information("Teardown {0}", i);
}
});
@devlead
devlead / build.ps1
Last active January 14, 2020 11:42
$CakeVersion = "0.34.1"
if (![string]::IsNullOrWhiteSpace($env:CAKE_VERSION))
{
$CakeVersion = $env:CAKE_VERSION
}
$IsRunningOnUnix = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix
# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ToolPath = Join-Path $PSScriptRoot "tools"
if (!(Test-Path $ToolPath)) {
// Switch expression
static string ToLevel(this Verbosity verbosity)
=> verbosity switch
{
Verbosity.Diagnostic => "[****]",
Verbosity.Verbose => "[*** ]",
Verbosity.Normal => "[** ]",
Verbosity.Minimal => "[* ]",
Verbosity.Quiet => "[ ]",
_ => throw new ArgumentOutOfRangeException(message: "invalid enum value",
@devlead
devlead / PostMessage.ps1
Created January 8, 2015 16:10
Post to slack from PowerShell
$postSlackMessage = @{token="*topsecret*";channel="#general";text="Hello from PowerShell!";username="PowerShell";icon_url="https://pbs.twimg.com/profile_images/1604347359/logo_512x512_normal.png"}
Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage