Skip to content

Instantly share code, notes, and snippets.

View LineCount.ps1
# 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 Nov 24, 2020
Compare checksum of files or directories.
View Compare-DirectoryContents.ps1
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 Aug 12, 2020
util.format example
View test.js
// 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 Apr 23, 2020
log4net in PowerShell
View log4net.ps1
$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 Jan 4, 2020
POST a simple message to an ActiveMQ Topic
View ActiveMQ-POST.ps1
$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
View register-dependencies.unmin.js
;(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();
}
@iOnline247
iOnline247 / Create-ADUsers.ps1
Created Nov 29, 2017
SP2016 Installation Scripts
View Create-ADUsers.ps1
$pathToOU = 'OU=SP Accounts,DC=fahq,DC=local'
$password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
New-ADUser -SamAccountName "sp_wf" -Name "sp_wf" -DisplayName "sp_wf" -Path $pathToOU -Enabled $true -AccountPassword $password -ChangePasswordAtLogon $false -PasswordNeverExpires $true
@iOnline247
iOnline247 / utils.js
Last active Sep 22, 2021
JavaScript Utilities and Example Usage
View utils.js
/*
* Helpful JS utils & example usage.
*/
const prop = (k) => (o) => o[k];
const props = (ks) => (o) => ks.map((k) => o[k]);
const map = (f) => (a) => a.map(f);
const filter = (f) => (a) => a.filter(f);
const split = (delim) => (s) => {
s = String(s);
return s.split(delim);
@iOnline247
iOnline247 / clear-spd-cache.ps1
Last active Nov 14, 2018
Clears SPD's cache and restarts the program.
View clear-spd-cache.ps1
$spd = Get-Process | ? {$_.ProcessName -eq 'SPDESIGN'}
$spdPath = ${env:ProgramFiles(x86)} + '\Microsoft Office\Office15\SPDESIGN.EXE'
if ($spd -ne $null) {
$spdPath = if ($spd.Path) { $spd.Path } # Else { ${env:ProgramFiles(x86)} + '\Microsoft Office\Office15\SPDESIGN.EXE' }
$spd.Kill();
while(!$spd.HasExited) {
Start-Sleep 1000
}
@iOnline247
iOnline247 / querystrings.js
Last active Mar 16, 2021
Get QueryStrings from URL (default) or string
View querystrings.js
function getQueryStrings(v) {
const result = {};
const rstripLeadingQuery = /^(:?\?|#)/;
const queryString = (v ? String(v) : window.location.search).replace(
rstripLeadingQuery,
''
);
const re = /([^&=]+)=([^&]*)/g;
let m;