Skip to content

Instantly share code, notes, and snippets.

Doug Mahugh dmahugh

Block or report user

Report or block dmahugh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dmahugh /
Last active Sep 13, 2019
convert XLSX file to JSON
"""Example of how to convert an xlsx file to JSON.
- Python 3.7 or higher
- openpyxl (pip install openpyxl)
- the active worksheet contains a rectangular array of data,
with column names in the first row
- the data fits in memory (makes the code below a bit simpler)
dmahugh /
Created Feb 20, 2019
Minimal Python code to read secrets from Azure Key Vaults
# dependencies: azure-common, azure-keyvault
from azure.common.credentials import ServicePrincipalCredentials
from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
def get_secret(secret_name, key_vault_uri, client_id, secret, tenant):
"""Get a secret from Key Vault.
credentials = ServicePrincipalCredentials(
client_id=client_id, secret=secret, tenant=tenant)
dmahugh /
Created Feb 8, 2019
Azure Devops REST API example: list projects in an instance
"""Azure Devops REST API example: list the projects in an instance
To run this example, create an ..\_private folder with an azuredevops.json file
in it that contains a PAT:
import json
dmahugh / Import JSON data.EXCEL.yaml
Created Feb 6, 2019
Imports JSON data into a table.
View Import JSON data.EXCEL.yaml
name: Import JSON data
description: Imports JSON data into a table.
host: EXCEL
api_set: {}
content: |
$("#import-json-data").click(() => tryCatch(importJsonData));
async function importJsonData() {
await (context) => {
dmahugh / Blank snippet.yaml
Created Nov 6, 2018
Shared with Script Lab
View Blank snippet.yaml
name: Blank snippet
description: ''
author: dmahugh
host: WORD
api_set: {}
content: |
$("#run").click(() => tryCatch(run));
async function run() {
dmahugh /
Created Apr 19, 2018
Extract code snippets from Markdown files and write to YAML files, in support of Office referencee content migration
"""Convert code snippets for use in auto-generated docs.
import glob
REPO_FOLDER = 'C:/temp/office-js-docs' # local cloned copy of repo
def main():
"""Extract snippets for each platform/folder."""
# note we're not doing Shared for now
for platform in ['Excel', 'OneNote', 'Outlook', 'Visio', 'Word']:
dmahugh /
Last active Sep 13, 2019
WIN32 automation of PowerPoint
"""Requires pypiwin32 - see installation instructions at
import random
import win32com.client
# for other shape types, see MsoAutoShapeTypeEnumeration:
# for other layout options, see PpSlideLayout Enumeration:
dmahugh / sample Python app for Microsoft Graph
Created Jun 12, 2017
This sample is part of our exploration of various approaches to starter samples for working with Microsoft Graph. It requires Requests, Bottle, and Python 3.x. It's a work in progress - we'll be publishing a more comprehensive version with complete documentation soon, but posting this here for anyone who'd like to try it out.
View sample Python app for Microsoft Graph
"""Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
import base64
import json
import os
import time
import urllib.parse
import uuid
dmahugh /
Created May 23, 2017
comparison of asynchronous HTTP requests (aiohttp/asyncio) and traditional sequential requests (with Requests library)
"""Comparison of fetching web pages sequentially vs. asynchronously
Requirements: Python 3.5+, Requests, aiohttp, cchardet
For a walkthrough see this blog post:
import asyncio
from timeit import default_timer
dmahugh /
Last active May 18, 2016
download the Norwescon attendance data, remove blank lines
"""Functions for manipulating Norwescon attendance data.
Query functions:
attended_all() ---------> Get attendees of a specified list of conventions.
attended_one() ---------> Get attendees of a specified convention.
Data-scrubbing functions:
download_data() --------> Download data file and save a local copy.
fixups() ---------------> Apply various fixups to the live data file.
progressbar() ----------> Display progress bar showing completion status.
You can’t perform that action at this time.