Skip to content

Instantly share code, notes, and snippets.

View maxali's full-sized avatar

Mohamed Ali maxali

View GitHub Profile
module.exports = function manipulateFilter(filter) {
if (filter && Array.isArray(filter.values)) {
filter.values.forEach(function(value) {
// Add a new property to each object in filter.values
value.newVar = "Some Value";
});
}
return filter;
}
@maxali
maxali / configure-python.sh
Created November 9, 2023 18:37
Configure Python Environment in MacOS
brew install pyenv
# Any modern version python should do. I don't think Python 2 is required any more.
pyenv install 3.10.3
pyenv global 3.10.3
# Add pyenv to your PATH so that you can reference python (not python3)
echo "export PATH=\"\${HOME}/.pyenv/shims:\${PATH}\"" >> ~/.zshrc
source ~/.zshrc
@maxali
maxali / UpdateZeroTier.ps1
Created October 18, 2022 16:08 — forked from wise-io/UpdateZeroTier.ps1
Updates ZeroTier to Latest Version
<#
.SYNOPSIS
Updates ZeroTier
.DESCRIPTION
Install latest version of ZeroTier if ZeroTier is already installed.
.EXAMPLE
./UpdateZeroTier.ps1
./UpdateZeroTier.ps1 -Headless
.NOTES
A UAC prompt may appear during install if -Headless is not used.
@maxali
maxali / InstallZeroTier.ps1
Created October 18, 2022 16:07 — forked from wise-io/InstallZeroTier.ps1
Installs Latest ZeroTier One Client
<#
.SYNOPSIS
Installs ZeroTier
.DESCRIPTION
Install ZeroTier and join/configure ZeroTier network
.EXAMPLE
./InstallZeroTier.ps1 -NetworkID [Network ID]
./InstallZeroTier.ps1 -NetworkID [Network ID] -Token [API Token] -Headless
.NOTES
Requires PowerShell 7 or higher (installed if missing) when using the $Token parameter.
@maxali
maxali / White label Route 53 nameservers.md
Created October 4, 2020 18:18 — forked from blofeldthefish/White label Route 53 nameservers.md
AWS Route 53 white label nameserver setup
@maxali
maxali / Connect-AzureRmAccountWithSP.ps1
Created October 24, 2019 11:40
Connect-AzureRmAccount Cmdlet using Service Principal with Credential
$applicationId = "<your application ID goes here>";
$securePassword = "<your password goes here>" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-AzureRmAccount -ServicePrincipal -Credential $credential -TenantId "tenantId"
@maxali
maxali / PnPStoredCredential.ps1
Last active February 16, 2019 16:39
Windows Credentials Manager with PnP PowerShell
# store your App Password in Windows Credential Manager.
Add-PnPStoredCredential -Name mycredential -Username contosoadmin@contoso.onmicrosoft.com -Password (ConvertTo-SecureString -String "mycontosopass" -AsPlainText -Force)
# use the saved App Password credentials whenever you try to login to pnp
Connect-PnPOnline -Url https://contoso.sharepoint.com -Credentials mycredential
# code snippet from this Stackoverflow answer https://stackoverflow.com/a/33574883
Function Test-IfAlreadyRunning {
<#
.SYNOPSIS
Kills CURRENT instance if this script already running.
.DESCRIPTION
Kills CURRENT instance if this script already running.
Call this function VERY early in your script.
If it sees itself already running, it exits.
$.getJSON(_spPageContextInfo.webAbsoluteUrl + "/_api/sphomeservice/context?$expand=Token,Payload").then( context => {
$.ajax({
url: context.Urls[0] + "/api/v1/sites/feed?start=0&count=3&acronyms=true",
headers: {
"Authorization": "Bearer " + context.Token.access_token,
"sphome-apicontext": context.Payload
}
})
})
#Azure Resource Manager cmdlets to get hold of the dll. https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-4.0.0
Add-Type -Path "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.ApiManagement\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
#Utility function to get Microsoft Graph Access Token. To know more about this, see my post http://www.vrdmn.com/2017/05/authenticating-to-microsoft-graph-api.html
function Get-MSGraphToken($azuretenantADName, $userName, $userPassword)
{
$AzureADAuthority = "https://login.microsoftonline.com/$azuretenantADName/oauth2/v2.0/authorize"
$resourceURL = "https://graph.microsoft.com/"
$powerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2"
$userCreds = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential($userName, $userPassword)