Skip to content

Instantly share code, notes, and snippets.

View dmahugh's full-sized avatar

Doug Mahugh dmahugh

View GitHub Profile
@dmahugh
dmahugh / Blank snippet.yaml
Created November 6, 2018 01:59
Shared with Script Lab
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 April 19, 2018 22:13
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
dmahugh / randomcircles.py
Last active December 1, 2021 08:13
WIN32 automation of PowerPoint
"""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 June 12, 2017 16:20
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.
"""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 17:21
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:
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 16:35
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.
@dmahugh
dmahugh / unicode_vscode.py
Created May 3, 2016 04:43
enabling Unicode support in VS Code's console
# If you're scanning the file system in Python, you will eventually come across filenames
# that can't be displayed in the VS Code console because they contain characters that
# will raise a UnicodeDecode Error. Opening sys.stdout as shown below fixes this problem.
# this ensures the console will handle Unicode characters
import sys
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
# the following print() statement crashes in the VS Code console window with a
# UnicodeDecodeError if you DON'T set sys.stdout as shown above
@dmahugh
dmahugh / remove_github_urls.py
Created March 22, 2016 22:38
Python function to remove URL bloat from JSON returned by GitHub V3 API
def remove_github_urls(dict_in):
"""Remove URL entries (as returned by GitHub API) from a dictionary.
1st parameter = dictionary
Returns a copy of the dictionary, but with no entries named *_url or url.
"""
return {key: dict_in[key] for key in dict_in if \
not key.endswith('_url') and not key == 'url'}