Skip to content

Instantly share code, notes, and snippets.

View Wind010's full-sized avatar

Jeff Tong Wind010

View GitHub Profile
@Wind010
Wind010 / FormatPem.ps1
Last active February 8, 2023 23:51
Format oneline PEM private key to multiline format.
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$false)]
[string]
$privateKey,
[Parameter(Mandatory=$false, Position=1, ValueFromPipeline=$false)]
[string]
$delim = "\r\n"
)
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$false)]
[string]
$secret,
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$false)]
[string]
$message
)
@Wind010
Wind010 / settings.json
Last active September 5, 2020 07:07
Windows Terminal Custom Settings
// This file was initially generated by Windows Terminal 1.2.2381.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@Wind010
Wind010 / CreditCardUtilities.ps1
Created September 24, 2020 03:03
Credit card utilities
Enum PaymentTypes
{
Visa
MasterCard
AmericanExpress
Discover
JapanCreditBureau
DinersClub
}
@Wind010
Wind010 / bfg_replace.txt
Last active October 5, 2020 23:21
BFG Replace Examples
SomePassword # Replace literal string 'SomePassword' with '***REMOVED***' (default)
SomePassword==>examplePass # Replace with 'examplePass' instead
SomePassword==> # Replace with the empty string
regex:password=\w+==>password= # Replace, using a regex
regex:\r(\n)==>$1 # Replace Windows newlines with Unix newlines
regex:(?i)(passsWord)==> # Replace "password" insensitively
regex:\"Number\":\s+\"\d+\"==>"Number: "***REMOVED***" # Remove number after "Number":
# Ensure that multi-line flag is used (java -jar bfg.jar --multi-line-regex --replace-text bfg_replace.txt)
regex:(?s)-----BEGIN RSA PRIVATE KEY-----(.+)-----END RSA PRIVATE KEY-----==>REMOVED
@Wind010
Wind010 / SearchAndReplaceRegEx.ps1
Last active October 8, 2020 17:52
Snippet to search and replace in file via regex certain patterns.
# Already case-insensitive. Use -cmatch and -creplace for case-sensitive matching and replacement.
(Get-Content input.json) `
-replace '\d{15,19}', {'*' * ($_.Value.Length-4) + $_.Value.Substring($_.Value.Length - 5, 4)} `
-replace '(\"expirationMonth\":)(\s*)("\d{1,2}")', '$1$2"**"' `
-replace '(\"expirationYear\":)(\s*)("\d{2,4}")', '$1$2"****"' `
-replace '(\"cvn\":)(\s*)("\d{3,4}")', '$1$2"***"' |
Out-File output.json
# Where $1 is the first group for example "CVN": and $2 is the second group (zero or more spaces) and $3 is the value.
function Base62Encode([string] $inputStr = [Guid]::NewGuid().ToString())
{
[byte[]] $byteArr = [system.Text.Encoding]::UTF8.GetBytes($inputStr)
$converted = BaseConvert $byteArr 256 62
$sb = [System.Text.StringBuilder]::new()
for ($i = 0; $i -lt $converted.Length; $i++) {
$sb.Append($CharacterSet[$converted[$i]]) | Out-Null
}
@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
@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
-- 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);