Skip to content

Instantly share code, notes, and snippets.

View dmahugh's full-sized avatar

Doug Mahugh dmahugh

View GitHub Profile
@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'}
@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 / 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 / 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 / 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 / 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 / Import JSON data.EXCEL.yaml
Created February 6, 2019 20:41
Imports JSON data into a table.
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 / azure_devops_list_projects.py
Created February 8, 2019 06:37
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:
{
"bugs-read-only": "YOUR-PERSONAL-ACCESS-TOKEN-HERE"
}
"""
import json
@dmahugh
dmahugh / keyvault_get_secret.py
Created February 20, 2019 22:34
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
dmahugh / create_sql_server_user.py
Created December 19, 2019 17:39
example of how to create a new user in Cloud SQL for SQL Server
"""Simple test of connecting to a Cloud SQL for SQL Server instance
and creating a new admin user account.
This script assumes that you've created a Cloud SQL for SQL Server
instance and have the Cloud SQL Proxy running locally and listening
on 127.0.01. For instructions on those setup steps, see
https://github.com/dmahugh/cloud-sql-pyodbc
Note two places below you need to set YOUR-* to your chosen passwords.
"""