This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ef wordle_guess(guess, answer): | |
"""Given a Wordle guess and the current answer, return the Wordle pattern | |
for that guess. The pattern is a 5-character string | |
containing G, Y, or W for Green, Yellow, or White.""" | |
assert len(guess) == 5 | |
assert len(answer) == 5 | |
pattern = "WWWWW" | |
matched = "" # characters in the guess that are correct-position matches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Get list of Wordle words. | |
""" | |
from datetime import datetime | |
from bs4 import BeautifulSoup | |
import requests | |
WORDLE_URL = "https://www.nytimes.com/games/wordle/" | |
FILENAME = f"wordle-words-{datetime.today().strftime('%Y-%m-%d')}.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Sample app</title> | |
</head> | |
<body> | |
<h1>{{ title }}</h1> | |
<p><a href="/docs">Docs</a></p> | |
<p><a href="/about">About</a></p> | |
<p><a href="/">Home</a></p> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
app = Flask(__name__) | |
@app.route("/") | |
def homepage(): | |
return render_template("page.html", title="HOME PAGE") | |
@app.route("/docs") | |
def docs(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
def print_table(*, cursor=None, table=None, title=None, rows=10): | |
"""Print contents of a table or cursor. | |
This is for quick printing of small data sets for diagnostic purposes, may | |
not work well with large numbers of columns. Takes a sqlite3 cursor and | |
table name as input. Output format and column widths is adjusted to fit | |
the current console line length as needed. | |
""" | |
if not cursor or not table: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { |
NewerOlder