Skip to content

Instantly share code, notes, and snippets.

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];
$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])}`;
}, "");
}
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;
const queryStrings = window.location.search.substring(1).split("&").reduce((output, item, index) => {
if(item === "")
return output;
const keyValue = item.split("=");
output[decodeURIComponent(keyValue[0])] = keyValue[1] !== undefined ?
decodeURIComponent(keyValue[1]) :
true; // return true for query strings with no value
param(
# Credentials paramter should be a variable containing the result of Get-Credential
[Parameter(Mandatory = $true)]
[pscredential]$Credentials,
[Parameter(Mandatory = $true)]
[string]$ConfigFile
)
$ErrorActionPreference = "Stop"
@zplume
zplume / FunctionAppMap.ps1
Last active December 16, 2018 22:11
Get-AzureFunctionKeys.ps1 retrieves Azure Function auth. codes for the Functions specified in FunctionAppMap.ps1, using the Azure REST API and user credentials. This script uses Get-AADToken.ps1 (https://gist.github.com/zplume/574e133b43ecf3037473286580ed524e) to retrieve an Azure access token.
# Map Function App friendly name to URL
return @{
DEV = @{
"CreateTenderSite" = "https://dev-createtendersite.azurewebsites.net";
"CopyDocuments" = "https://dev-copydocuments.azurewebsites.net";
"Notifications" = "https://dev-notifications.azurewebsites.net";
"PermissionAssignment" = "https://dev-permissions.azurewebsites.net"
};
TEST = @{
# 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.
param(
[Parameter(Mandatory = $true)]
[string]$ListTitle,
[Parameter(Mandatory = $true)]
[int]$ItemId,
[Parameter(Mandatory = $true)]
[string]$Path
)