Skip to content

Instantly share code, notes, and snippets.

View waldekmastykarz's full-sized avatar
🥑
Microsoft 365

Waldek Mastykarz waldekmastykarz

🥑
Microsoft 365
View GitHub Profile
@waldekmastykarz
waldekmastykarz / cli.sh
Created July 17, 2020 13:39
Run CLI for Microsoft 365 with specific AAD app
OFFICE365CLI_AADAPPID= OFFICE365CLI_TENANT= m365 login
@waldekmastykarz
waldekmastykarz / archive-mail.sh
Created August 6, 2020 18:19
Move Outlook emails from Inbox to Archive
OFFICE365CLI_AADAPPID=31... OFFICE365CLI_TENANT=b4... m365 outlook message list --folderName inbox -o json --query '[].id' > emails.txt
i=0
cat emails.txt | jq -c '.[]' | while read msgId; do
i=$((i+1))
echo "Archiving $i..."
OFFICE365CLI_AADAPPID=31... OFFICE365CLI_TENANT=b4... m365 outlook message move --sourceFolderName inbox --messageId $msgId --targetFolderName archive
done
@waldekmastykarz
waldekmastykarz / index.js
Created August 30, 2020 12:34
Get GitHub repo contributors from last month
const axios = require('axios').default;
// define date ranges to process commits
const now = new Date();
const pastMonthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1));
const currentMonthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
console.log('Retrieving PRs...');
axios
.get(`https://api.github.com/repos/pnp/cli-microsoft365/pulls?state=closed&sort=updated&direction=desc&per_page=100`)
@waldekmastykarz
waldekmastykarz / index.js
Created September 2, 2020 17:43
Remove method from a class in a .ts file
const ts = require('typescript');
const path = require('path');
const fs = require('fs');
function getAsEnumerable(file, node) {
const nodes = [node];
node.getChildren(file).forEach(n => {
nodes.push(...getAsEnumerable(file, n));
});
@waldekmastykarz
waldekmastykarz / index.js
Created September 2, 2020 17:44
Reformat docs
const fs = require('fs');
const os = require('os');
const path = require('path');
function readdirR(dir) {
return fs.statSync(dir).isDirectory()
? Array.prototype.concat(...fs.readdirSync(dir).map(f => readdirR(path.join(dir, f))))
: dir;
};
@waldekmastykarz
waldekmastykarz / convert-imagetowebp.ps1
Created December 21, 2020 14:33
Convert multiple images to .webp
$now = Get-Date
Get-ChildItem | ? {
($now - $_.LastWriteTime).totalhours -le 1
} | % {
cwebp $_.Name -o $($_.BaseName+".webp")
}
@waldekmastykarz
waldekmastykarz / profile.sh
Created January 6, 2021 18:10
Profile node application
# https://nodejs.org/en/docs/guides/simple-profiling/
NODE_ENV=production node --prof app.js
node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt
@waldekmastykarz
waldekmastykarz / CacheMiddleware.js
Created April 8, 2021 09:34
Sample cache middleware for Microsoft Graph JS SDK
export function CacheMiddleware(expirationConfig) {
this.nextMiddleware = undefined;
this.expirationConfig = expirationConfig;
const getHeaders = (headers) => {
const h = {};
for (var header of headers.entries()) {
h[header[0]] = header[1];
}
return h;
@waldekmastykarz
waldekmastykarz / cwebp-images.mjs
Created May 24, 2021 14:21
Convert images modified in the last hour to cwebp
#!/usr/bin/env zx
const fs = require('fs'),
path = require('path');
const nonWebPFiles = fs
.readdirSync(process.cwd())
.filter(file => !file.endsWith('.webp'));
const lastHour = new Date();
lastHour.setHours(lastHour.getHours() - 1);
@waldekmastykarz
waldekmastykarz / remove-permissionrequests.mjs
Last active June 1, 2021 12:01
Removes all pending SharePoint API permission requests
#!/usr/bin/env zx
$.verbose = false;
console.log('Retrieving permission requests...');
const permissionRequests = JSON.parse(await $`m365 spo sp permissionrequest list -o json`);
for (let i = 0; i < permissionRequests.length; i++) {
const request = permissionRequests[i];
console.log(`Removing request ${request.Resource}/${request.Scope} (${request.Id})...`);
try {