Skip to content

Instantly share code, notes, and snippets.

View Wind010's full-sized avatar

Jeff Tong Wind010

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 = '.'
)
-- Setup
CREATE TABLE Test_INT ([Id] [int] NOT NULL primary key clustered,
[col1] [int] NULL,
[col2] [int] NULL,
[col3] [varchar](50) NULL);
CREATE TABLE Test_GUID ([Id] [uniqueidentifier] NOT NULL primary key clustered,
[col1] [int] NULL,
[col2] [int] NULL,
[col3] [varchar](50) NULL);
@Wind010
Wind010 / azure-pipelines.yml
Created March 3, 2021 21:52
Example azure-pipelines.yml that restores, builds, tests, code coverage report, Snyk scan, publishes artifacts. Stage for source and docker image build and publish.
# .NET Core Function App to Windows on Azure
# Build a .NET Core function app and deploy it to Azure as a Windows function App.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core
name: $(Date:yyyyMMdd)$(Rev:.r)-$(SourceBranchName)
trigger:
- master
- develop
@Wind010
Wind010 / JobEngine.cs
Created January 11, 2021 18:10
Wrapper around TPL for spawning multiple threads calling the passed in method returning an IEnumerable of the results.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Misc.Engines
{
/// <summary>
/// Meant for CPU bound operations. Long running I/O operations should be run