Skip to content

Instantly share code, notes, and snippets.

using Microsoft.SharePoint.Client;
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.SharePoint.Client.ClientContextExtensions;
public static class ClientContextExtensions
{
public static async Task ExecuteQueryRetryAsync(this ClientContext clientContext,
// create an object from an array of values with Array.reduce
const objectFromArray = [4,5,6].reduce((output, item, index) => {
output[index] = item; // assign new key/value to output object
return output;
},
{} // initial value - empty object
);
// objectFromArray:
// {0: 4, 1: 5, 2: 6}
@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;
function getQueryStringParam(searchKey) {
// get URI object
var uri = new URI(location.href);
// get query params
var queryParams = uri.getQueryAsObject();
// get queryParam keys
var queryParamKeys = Object.keys(queryParams);
public static class AuthCheck
{
// This Function will return OK if the user is authenticated
[FunctionName("AuthCheck")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]HttpRequestMessage request, TraceWriter log)
{
var response = request.CreateResponse(HttpStatusCode.OK);
Cors.Enable(request, response);
@zplume
zplume / Log.ts
Last active December 12, 2017 13:55
export default class Log {
private prefix: string;
private logSource: object;
private parseArgument(arg: any): string {
return typeof(arg) === "string" ? arg : JSON.stringify(arg);
}
private getMethodName(callingFunction: Function): string {
const methodNames = Object.getOwnPropertyNames(Object.getPrototypeOf(this.logSource));
@zplume
zplume / GetUsers.js
Last active August 24, 2017 09:22
Quick script to get SharePoint user properties (LoginName, Title, Email) for multiple users, via the Chrome console, using async/await, Promise.all, fetch, computed properties and rest parameters.
(async function() {
let userIds = [239, 405];
// computed property name: [prop]:
// rest parameters: ...props
// stolen from: https://stackoverflow.com/a/25554551
function pick(o, ...props) {
return Object.assign({}, ...props.map(prop => ({[prop]: o[prop]})));
}
@zplume
zplume / FormatO365AuditLogs.ps1
Created June 9, 2017 09:29
Converts the bizarre JSON-in-CSV format of O365 audit logs to a more useful CSV of the JSON data. Run the script from the directory containing the $inputFile or specify a full path rather than just a file name.
$inputFile = "AuditLog_2017-05-18_2017-05-27.csv"
$outputFile = "AuditLogData.csv"
Import-Csv -Path $inputFile | ForEach-Object { $_.AuditData } | ConvertFrom-Json | Export-Csv -Path $outputFile -NoTypeInformation
Param(
[Parameter(Mandatory=$True)]
$AppPrincipalId,
[Parameter(Mandatory=$True)]
$TenantId,
[string]$ClientSecret
)