Skip to content

Instantly share code, notes, and snippets.

@zplume
zplume / SP.MDS.OnPageLoad.js
Last active November 11, 2021 13:32
Example code to ensure that a function is executed on all page loads, including MDS page loads (where partial page loading is used for navigation rather than full postbacks).
// define a global function to execute
function $_global_onMDSPageLoad() {
// code to execute on page load goes here
}
ExecuteOrDelayUntilScriptLoaded(function () {
if (typeof asyncDeltaManager != "undefined")
asyncDeltaManager.add_pageLoaded($_global_onMDSPageLoad); // execute on MDS page load
else
$_global_onMDSPageLoad(); // execute on non-MDS page load
using System.IO;
using System.Text;
public static class StreamExtensions
{
public static string ToEncodedString(this Stream stream, Encoding enc = null)
{
enc = enc ?? Encoding.UTF8;
byte[] bytes = new byte[stream.Length];
@zplume
zplume / MutationObserverVsDOMSubtreeModified.js
Created November 6, 2017 11:06
MutationObserver vs DOMSubtreeModified example which allows detecting changes in elements that don't exist yet, by detecting changes in a parent element that does exist at the time the function is executed.
// This example depends on jQuery().on and _.debounce
// Create a MutationObserver to trigger a callback function
// when the element located via document.querySelector(elementSelector) changes
function getMutationObserver(elementSelector, callback) {
var observer = new MutationObserver(callback);
var config = { attributes: true, childList: true, characterData: false };
observer.observe(document.querySelector(elementSelector), config);
return observer;
param(
[Parameter(Mandatory = $true)]
[string]$ListTitle,
[Parameter(Mandatory = $true)]
[int]$ItemId,
[Parameter(Mandatory = $true)]
[string]$Path
)
$imagePath = "$home\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*"
$destinationPath = "$home\OneDrive\Pictures\Lock screen"
Add-Type -AssemblyName System.Drawing
# get images from lock screen folder
$items = Get-ChildItem -Path $imagePath
foreach($item in $items) {
$fileName = $item.Name
function objectToQueryString(paramsObject) {
return Object.keys(paramsObject).reduce((accumulator, currentKey) => {
const prefix = accumulator === "" ? "?" : "&";
return `${accumulator}${prefix}${currentKey}=${encodeURIComponent(paramsObject[currentKey])}`;
}, "");
}
@zplume
zplume / HTMLInputPasswordValidation.html
Last active December 5, 2019 08:16
HTML 5 / Kendo UI client-side validation for a password field with basic complexity requirements
<!--ASP.NET-->
<asp:Textbox runat="server" ClientIdMode="Static" type="password" id="PasswordTextbox" name="PasswordTextbox" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$" validationmessage="Please enter a password which is at least 8 characters long and contains a lowercase character, an uppercase character and a number" required />
<!--HTML-->
<input type="password" id="PasswordTextbox" name="PasswordTextbox" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$" validationmessage="Please enter a password which is at least 8 characters long and contains a lowercase character, an uppercase character and a number" required />
<!--Kendo UI Validator: http://demos.telerik.com/kendo-ui/validator/index -->
using Microsoft.Azure.WebJobs;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LS.DurableFunctions.Examples
{
public static class DurableOrchestrationContextExtensions
{
/// <summary>
@zplume
zplume / CsvHelperExample.cs
Last active May 29, 2019 14:09
Example of using CsvHelper to write a CSV file (up to 10MB in size) to SharePoint Online
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OfficeDevPnP.Core;
using Microsoft.SharePoint.Client;
using System.IO;
using CsvHelper;
using File = Microsoft.SharePoint.Client.File;
using CsvHelper.Configuration.Attributes;
# Original code from https://github.com/slavizh/OMSSearch/blob/master/OMSSearch.psm1
# - Updated/fixed authentication method calls
# - Ensure ADAL DLL is loaded
Function Get-AADToken {
<#
.SYNOPSIS
Get token from Azure AD so you can use the other cmdlets.
.DESCRIPTION
Get token from Azure AD so you can use the other cmdlets.