Skip to content

Instantly share code, notes, and snippets.

View Wind010's full-sized avatar

Jeff Tong Wind010

View GitHub Profile
@Wind010
Wind010 / extract_rsa_privatekey.ps1
Last active April 26, 2021 21:05
Wrapper around openssl to extract RSA private key
### Requires openssl (https://www.openssl.org/).
### Usage:
### .\extract_rsa_privatekey.ps1 .\YOUR_CERTIFICATE.pfx (ConvertTo-SecureString "YOUR_STRONG_PASSWORD" -AsPlainText -Force)
param(
[Parameter(Mandatory=$true)][string] $certificatePfxPath,
[SecureString] $password,
[string] $pathToOpenSsl = '.'
)
@Wind010
Wind010 / AreSameFile.ps1
Last active April 28, 2021 19:00
Powershell script to diff two files with SHA256 hash.
<#
.DESCRIPTION
Powershell script to diff two files with SHA256 hash.
.OUTPUTS
System.String. Add-Extension returns a string with the extension or file name.
.EXAMPLE
PS> .\AreSameFile.ps1 .\deployed.json .\expected_different.json
#>
@Wind010
Wind010 / ConvertTo-HexBinByteArr.ps1
Last active April 29, 2021 01:59
Powershell functions to convert from byte array to hex or binary and vice versa.
$bits_in_a_byte = 8
$base2 = 2
$base16 = 16
Function ConvertTo-HexFromByteArray
{
param(
[parameter(Mandatory=$true)]
[Byte[]]
$bytes
@Wind010
Wind010 / Set-AclForCertificate.ps1
Last active August 21, 2024 06:07
Powershell script to add permissions to X509 certificate private key for specific user.
<#
.DESCRIPTION
Powershell script to add permissions to X509 certificate private key for specific user.
.OUTPUTS
Set-Acl result
.EXAMPLE
PS> .\Set-AclForCertificate.ps1 'your_cert_thumbprint' 'domain\username' 'Read'
or
PS> .\Set-AclForCertificate.ps1 'your_cert_thumbprint' 'domain\username' 'FullControl'
@Wind010
Wind010 / Flatten-Json.ps1
Last active April 30, 2024 17:16
Powershell functions to Flatten JSON to the expected Key/Value format used by Azure.
<#
.DESCRIPTION
Powershell functions to Flatten JSON to the expected Key/Value format used by Azure.
.OUTPUTS
HashTable that contains the flattened json properties and values.
.EXAMPLE USAGE
. /Flatten-Json.ps1 # Source the file to load the functions.
$json = Get-Content '.\appSettings.json' -Raw | ConvertFrom-Json
Flatten-Json $json
@Wind010
Wind010 / PingUntil.ps1
Created May 11, 2021 23:48
Powershell script to continuously ping a target host.
<#
.DESCRIPTION
Powershell script to continuously ping a target host.
If logPath is specified, will output rolling logs based off size parameter.
.OUTPUTS
Set-Acl result
.EXAMPLE
PS> .\PingUntil.ps1 'DateTime_to_Stop' 'your_target_host' 'delayInMs' 'logPath' 'maxFileSizeInMB'
or
PS> .\PingUntil.ps1 (Get-Date).AddSeconds(10) 'www.google.com' 100 'C:\somedir\logs\ping.log' 100
@Wind010
Wind010 / random_content_generator.py
Created April 2, 2022 23:08
Script to generate random string content
import sys, getopt, os, random, string
def generate_random_string(character_space: str, size_in_bytes: int) -> str:
return "".join([random.choice(character_space) for i in range(size_in_bytes)])
def generate_random_string_file(filepath: str, size_in_bytes: int) -> None:
"""
Generate big random letters/alphabets to a file.
@Wind010
Wind010 / settings.json
Created June 11, 2022 01:43
VS Code Python Pytest command line args settings
{
"cSpell.ignoreWords": [
"assertpy",
"backfilling",
"checkpointed",
"checkpointing",
"dagrr",
"databricks",
"dataframe",
"dataframes",
@Wind010
Wind010 / create_azure_devops_release_definition.sh
Last active October 11, 2022 22:46
Create an Azure DevOps release definition from file.
#!/bin/bash
# Usage
# ./create_azure_devops_release_definition.sh "YOUR_ORG" "YOUR_PROJECT"
Organization=$1
Project=$2
azureDevOpsTokenUri="https://vssps.dev.azure.com/$Organization"
azureDevOpsReleaseUri="https://vsrm.dev.azure.com/$Organization"
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace CommonTests.Attributes
{
/// <summary>
/// Abstract base class for use with TestMethodWithIgnoreIfSupportAttribute.cs.
/// Interfaces don't
/// </summary>