Skip to content

Instantly share code, notes, and snippets.

@iOnline247
iOnline247 / dataMaskingPerf.js
Last active August 31, 2024 02:48
Data masking perf for objects that are logged.
const WARMUP_LOOPS = 100000;
//#region Utils
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
function createUserObj() {
return {
id: 123,
@iOnline247
iOnline247 / boilerplate.ps1
Created November 10, 2022 19:10
P0$H Boilerplate
param(
[ValidateSet("DEV","TEST","PROD")]
[parameter(mandatory=$true)]
[string]$Environment = ("DEV","TEST","PROD")
)
# TODO
# Update with newer code patterns
$path = Split-Path -Path $MyInvocation.MyCommand.Path
$scriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Source)
@iOnline247
iOnline247 / ohmyposhv3-v2.json
Last active September 2, 2022 12:39 — forked from shanselman/ohmyposhv3-v2.json
ohmyposhv3-v2
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#00c7fc",
"foreground": "#000000",
"style": "diamond",
@iOnline247
iOnline247 / for-await-concurrrently.js
Created August 12, 2022 14:41
`for await` examples
async function* iteratorGen(arr) {
for (const i of arr) {
if (typeof i === "function") {
yield i();
} else {
yield i;
}
}
}
# https://stackoverflow.com/a/22558858
Get-ChildItem -Include *.js, *.css, *.html -Recurse | ForEach-Object {
$_ | Select-Object FullName, @{n = "Lines"; e = { Get-Content $_ | Measure-Object -Line | Select-Object -ExpandProperty Lines}}}
@iOnline247
iOnline247 / Compare-DirectoryContents.ps1
Last active November 24, 2020 08:15
Compare checksum of files or directories.
function logMsg($text, $color = [System.ConsoleColor]::green) {
Write-Host $text -foregroundcolor $color
Write-Host "`r`n"
}
<#
function Remove-DirectoryPathInfo ($fileInfo) {
$fileInfo.Path = $fileInfo.Path -replace "$([Regex]::Escape($testFiles[0].Parent.Parent.FullName))\\", ""
$fileInfo.Path = $fileInfo.Path -replace "$([Regex]::Escape($initialFiles[0].Parent.Parent.FullName))\\", ""
# "$([Regex]::Escape($parentDirectoryPath))\\"
@iOnline247
iOnline247 / test.js
Created August 12, 2020 06:10
util.format example
// https://nodejs.org/api/util.html#util_util_format_format_args
// util.format() is a synchronous method that is intended as a debugging tool.
// Some input values can have a significant performance overhead that can block
// the event loop. Use this function with care and never in a hot code path.
const { format } = require("util");
function log(...args) {
// Note the subtle difference in the output. The %j is converted to JSON.
const msg = format("%j %s %s %s", ...args);
@iOnline247
iOnline247 / log4net.ps1
Created April 23, 2020 05:11
log4net in PowerShell
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Push-Location $scriptDir
Add-Type -Path "$scriptDir\dll\log4net.dll"
$FileAppender = New-Object log4net.Appender.FileAppender(
(
[log4net.Layout.ILayout](New-Object log4net.Layout.PatternLayout('%date{yyyy-MM-dd HH:mm:ss.fff} | %level | %property{correlationId} | [%thread] | Department | App_Name | %c | $property{jobId} | %message%n')),
"$scriptDir\LogOutputInConsoleAndFile.log", # $LogFileName
@iOnline247
iOnline247 / ActiveMQ-POST.ps1
Created January 4, 2020 06:04
POST a simple message to an ActiveMQ Topic
$i = 0
while($true) {
$password = ConvertTo-SecureString "admin" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential "admin", $password
$i++
$body = "test$i"
Invoke-RestMethod -Uri "http://activemq:8161/api/message/mqttsignal?type=topic" -Method Post -ContentType "text/plain" -Credential $cred -Body $body
@iOnline247
iOnline247 / register-dependencies.unmin.js
Created January 15, 2018 18:02
SharePoint SP.SOD Helper
;(function() {
// Is MDS enabled?
if ("undefined" != typeof g_MinimalDownload && g_MinimalDownload && (window.location.pathname.toLowerCase()).endsWith("/_layouts/15/start.aspx") && "undefined" != typeof asyncDeltaManager) {
// Register script for MDS if possible
RegisterModuleInit("init.js", init); //MDS registration
init(); //non MDS run
} else {
init();
}