Skip to content

Instantly share code, notes, and snippets.

let nsxServer = location.host;
let xsrfToken = await fetch(`https://${nsxServer}/api/v1/reverse-proxy/usersessionInfo`).then(r => r.text()).then(r => JSON.parse(r).xsrfToken);
let pageSize = 500;
// NSX groups with effective VM members
fetch(`https://${nsxServer}/policy/api/v1/search/aggregate?page_size=${pageSize}&cursor=0&sort_by=display_name&sort_ascending=true`, {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "en-US",
"content-type": "application/json;charset=UTF-8",
function natualSort {
PARAM(
[System.Collections.ArrayList]$Array,
[switch]$Descending
)
Add-Type -TypeDefinition @'
using System;
using System.Collections;
using System.Collections.Generic;
@changbowen
changbowen / Test-RPC.ps1
Created October 11, 2019 09:05
modified version of the Test-RPC from Ryan Ries
# Author: Ryan Ries [MSFT]
# Origianl date: 15 Feb. 2014
#Requires -Version 3
Function Test-RPC {
[CmdletBinding(SupportsShouldProcess = $True)]
Param(
[Parameter(ValueFromPipeline = $True)][String[]]$ComputerName = 'localhost',
[int[]]$Ports = $null
)
BEGIN {
@changbowen
changbowen / yaml.json
Last active September 11, 2019 07:42
VS Code Ansible snippets
{
"Insert new variable": {
"prefix": ": ",
"body": [
": \"{{ ${2:value} }}\"$0"
],
"description": "Insert new ansible variable"
},
"Insert conditional list": {
"prefix": "cond",
@changbowen
changbowen / auto_default_gateway_metric.ps1
Last active November 7, 2024 01:38
PowerShell script that monitors for IP changes and updates route metric according to internet reachability
function ipChangeHandler {
Write-Host "Detected an IP change..."
Write-Host "Collecting connections information..."
$connObjs = New-Object System.Collections.ArrayList
$ints = Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp -AddressState Preferred
foreach ($int in $ints) {
$_alias = $int.InterfaceAlias
$_index = $int.InterfaceIndex
$_ipaddr = $int.IPAddress
$intCfg = $int | Get-NetIPConfiguration
@changbowen
changbowen / remove_dameware.ps1
Created August 20, 2019 03:46
remove devices leftover from a dameware uninstall
################################
# Script created by Carl Chang #
################################
$devcon = 'path\to\devcon_x64.exe'
# uninstall dameware products
wmic product where "name like '%%dameware%%'" call uninstall
# remove left-over devices
@changbowen
changbowen / CycleWallpaperWithDate.ps1
Last active November 17, 2023 14:22
PowerShell script to be used with bginfo.exe that cycles wallpaper based on date
param(
# The folder containing the images
[Parameter()][string]$imgPath = $env:imgPath,
[Parameter()][string]$bgiPath = $env:bgiPath
)
if ([string]::IsNullOrEmpty($imgPath) -or [string]::IsNullOrEmpty($bgiPath)) {
throw "You need to set imgPath and bgiPath environment variables or pass them in."
}
#region function definitions
@changbowen
changbowen / Python.xml
Last active August 5, 2019 07:22
Python live templates for PyCharm
<templateSet group="Python">
<template name="for" value="for $VAR$ in $ITERABLE$:&#10; $END$" description="Iterate (for ... in ...)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="&quot;iterable&quot;" alwaysStopAt="true" />
<variable name="VAR" expression="collectionElementName(ITERABLE)" defaultValue="&quot;item&quot;" alwaysStopAt="true" />
<context>
<option name="Python" value="true" />
</context>
</template>
<template name="fori" value="for $INDEX$, $VAR$ in enumerate($ITERABLE$):&#10; $END$" description="Iterate (for ... in enumerate)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="" alwaysStopAt="true" />
@changbowen
changbowen / DpiImage.cs
Last active September 18, 2019 06:49
WPF Image control that does not scale with system DPI
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ZipImageViewer
{
public class DpiImage : Image
{