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
dmahugh / excel_to_json.py
Last active Sep 13, 2019
convert XLSX file to JSON
View excel_to_json.py
"""Example of how to convert an xlsx file to JSON.
Requirements:
- Python 3.7 or higher
- openpyxl (pip install openpyxl)
Assumptions:
- 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
dmahugh / keyvault_get_secret.py
Created Feb 20, 2019
Minimal Python code to read secrets from Azure Key Vaults
View keyvault_get_secret.py
# 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
dmahugh / azure_devops_list_projects.py
Created Feb 8, 2019
Azure Devops REST API example: list projects in an instance
View azure_devops_list_projects.py
"""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:
{
"bugs-read-only": "YOUR-PERSONAL-ACCESS-TOKEN-HERE"
}
"""
import json
@dmahugh
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: {}
script:
content: |
$("#import-json-data").click(() => tryCatch(importJsonData));
async function importJsonData() {
await Excel.run(async (context) => {
@dmahugh
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: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
@dmahugh
dmahugh / convert_snippets.py
Created Apr 19, 2018
Extract code snippets from Markdown files and write to YAML files, in support of Office referencee content migration
View convert_snippets.py
"""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
dmahugh / randomcircles.py
Last active Sep 13, 2019
WIN32 automation of PowerPoint
View randomcircles.py
"""Requires pypiwin32 - see installation instructions at https://github.com/mhammond/pywin32
"""
import random
import win32com.client
# for other shape types, see MsoAutoShapeTypeEnumeration:
# https://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/msoautoshapetype-enumeration-office
SHAPE_OVAL = 9
# for other layout options, see PpSlideLayout Enumeration:
@dmahugh
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
dmahugh / comparision.py
Created May 23, 2017
comparison of asynchronous HTTP requests (aiohttp/asyncio) and traditional sequential requests (with Requests library)
View comparision.py
"""Comparison of fetching web pages sequentially vs. asynchronously
Requirements: Python 3.5+, Requests, aiohttp, cchardet
For a walkthrough see this blog post:
http://mahugh.com/2017/05/23/http-requests-asyncio-aiohttp-vs-requests/
"""
import asyncio
from timeit import default_timer
@dmahugh
dmahugh / norwescon_data.py
Last active May 18, 2016
download the Norwescon attendance data, remove blank lines
View norwescon_data.py
"""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.