Skip to content

Instantly share code, notes, and snippets.

Working from home

Dongbo Wang daxian-dbw

Working from home
  • Microsoft
  • Redmond, WA
View GitHub Profile
daxian-dbw / ColorTest.ps1
Created Feb 20, 2020
Test script to verify the ConsoleColor to VT sequences map is correct.
View ColorTest.ps1
Write-Host "ConsoleColor.Black:`t" -NoNewline; Write-Host "TESTING" -ForegroundColor Black
Write-Host "ConsoleColor.Gray:`t" -NoNewline; Write-Host "TESTING" -ForegroundColor Gray
Write-Host "ConsoleColor.Red:`t" -NoNewline; Write-Host "TESTING" -ForegroundColor Red
Write-Host "ConsoleColor.Green:`t" -NoNewline; Write-Host "TESTING" -ForegroundColor Green
daxian-dbw / RunspaceSynchronizer.cs
Created Apr 13, 2019
Synchronize the loaded modules and global scope variables between two Runspaces
View RunspaceSynchronizer.cs
using System;
using System.Collections.Generic;
using System.Management.Automation;
public class RunspaceSynchronizer
public static bool SourceActionEnabled = false;
private static bool TargetActionEnabled = false;
// 'moduleCache' keeps track of all modules imported in the source Runspace.
View proxy.pac
function FindProxyForURL(url, host) {
if ( host == "" ) {
return "PROXY";
else {
return "DIRECT";
daxian-dbw / outter.cs
Last active Oct 31, 2016
Redirect process output/error using event handler. This project experiments with BlockingCollection<T> and the encapsulation of the output/error data handler.
View outter.cs
using System;
// A test process that write stdout and stderr.
namespace ConsoleApp {
public class Outter {
private static string[] outputs = new string[] { "Hello world",
"This is me",
"I'm here",
"You are awesome",
"Me too",
daxian-dbw / Add-LinkElement.ps1
Created Oct 22, 2016
Add <Link> tags to the '<Compile>', '<None>' and '<EmbeddedResource>' for the *.csproj files in PowerShell/PowerShell. This is to make sure in Visual Studio all file items are organized in the appropriate folders.
View Add-LinkElement.ps1
function Add-LinkElement
daxian-dbw / Consume-Memory.ps1
Last active Oct 30, 2016
A powershell function to consume as much memory as possible
View Consume-Memory.ps1
## A helper to check the memory limit of a PS remote session
function Consume-Memory
## Get the total physical memory size
$totalPhysicalMem = get-ciminstance -class "cim_physicalmemory" | Measure-Object -Sum -Property Capacity | % Sum
Write-Host "Total Free Physical Memory: $($totalPhysicalMem / 1gb) GB" -ForegroundColor Green
## Create a two-dimensional array (20, N)
$array = @(,@(1)) * 20
daxian-dbw / AnalyzeSelectObject.ps1
Last active Jul 24, 2020
AnalyzeSelectObject.ps1: analyze usage of 'Select-Object' to find cases like 'Select-Object -ExcludeProperty value1 -ExpandProperty value2'. SearchGitHub.psm1: search powershell code in GitHub
View AnalyzeSelectObject.ps1
using namespace System.Management.Automation.Language
$Path = Resolve-Path $Path | % Path
function AnalyzeSelectObjectUsage
daxian-dbw / Check-StringReplacementChange.ps1
Last active Jan 7, 2019
Validate string replacement changes that affect large amount of files
View Check-StringReplacementChange.ps1
## Get the diff content of a Github PR, and analyze if the diffs are only caused by the string replacement.
## [Interesting exercise]