Skip to content

Instantly share code, notes, and snippets.

View devhawk's full-sized avatar

Harry Pierson devhawk

View GitHub Profile
param([Parameter(Mandatory=$true)][string]$filename, [string]$displayname)
$local:windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$local:windowsPrincipal = new-object 'System.Security.Principal.WindowsPrincipal' $local:windowsIdentity
if ($local:windowsPrincipal.IsInRole("Administrators") -ne 1)
{
throw "add-bcd-vhd must be run from an administrator account"
}
$f = resolve-path $filename
@devhawk
devhawk / WinRtAwaiter.cs
Last active December 12, 2025 20:53
Simple C# class to add async/await support for WinRT async operations w/o System.Runtime.WindowsRuntime.
using System.Runtime.CompilerServices;
using Windows.Foundation;
static class WinRtHelper
{
struct VoidValueTypeParameter { }
public static TaskAwaiter GetAwaiter(this IAsyncAction op)
{
var tcs = new TaskCompletionSource<VoidValueTypeParameter>();
@devhawk
devhawk / indent.fs
Created August 4, 2016 17:18
F# Indent
open System
// helper function to indent an indexedTextWriter and automatically un-indent
// when disposed
let indent (itw : System.CodeDom.Compiler.IndentedTextWriter) =
let current = itw.Indent
itw.Indent <- current + 1
{ new IDisposable with
member x.Dispose() = itw.Indent <- current }
@devhawk
devhawk / colorconsole.fs
Created August 4, 2016 17:19
F# Color Console Functions
open System
// helper function to set the console collor and automatically set it back when disposed
let consoleColor (fc : ConsoleColor) =
let current = Console.ForegroundColor
Console.ForegroundColor <- fc
{ new IDisposable with
member x.Dispose() = Console.ForegroundColor <- current }
// printf statements that allow user to specify output color
param
(
[Parameter(Mandatory=$True)][string]$srcPath,
[string]$dstPath = "."
)
$local_path = join-path $env:LOCALAPPDATA "cppwinrt.android"
if (-not (test-path $local_path)) {
mkdir $local_path | out-null
}
class Konsole : IDisposable
{
ConsoleColor _orig_fg;
public static IDisposable Color(ConsoleColor fg)
{
var k = new Konsole()
{
_orig_fg = Console.ForegroundColor
};
function Set-ConsoleColors {
param ([string]$theme = "campbell")
# Following source adapted from https://github.com/Microsoft/console/tree/master/tools/ColorTool
add-type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
namespace ColorTool
{
{
"version": "3.6.5",
"url": "https://github.com/TextAnalysisTool/Releases/raw/master/TextAnalysisTool.NET.zip",
"bin": "TextAnalysisTool.NET.exe"
}
@devhawk
devhawk / install-dotnet.sh
Last active May 11, 2018 19:02
installing dotnet on WSL Debian
# enhancement to https://www.microsoft.com/net/learn/get-started/linux/debian9
# debian WSL appears to need --no-check-certificate for wget from packages.microsoft.com
wget --no-check-certificate -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget --no-check-certificate -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
# need apt-transport-https installed
sudo apt-get update
@devhawk
devhawk / msvc_pch.cmake
Last active October 25, 2018 22:21
cmake function to configure MSVC precompiled header support
function(TARGET_CONFIG_MSVC_PCH target pch_cpp pch_header)
set(pch_output_file "\"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pch\"")
get_target_property(sources ${target} SOURCES)
foreach(file ${sources})
if (${file} STREQUAL ${pch_cpp})
set_source_files_properties(${file}
PROPERTIES
COMPILE_FLAGS " /Yc${pch_header} /Fp${pch_output_file}"