Skip to content

Instantly share code, notes, and snippets.

View Mark-McCracken's full-sized avatar
🏠
Working from home. Obviously.

Mark McCracken Mark-McCracken

🏠
Working from home. Obviously.
View GitHub Profile
@Mark-McCracken
Mark-McCracken / index.test.ts
Created September 23, 2022 10:58
Robot Warehouse code
import { myConst, Robot, Direction } from ".";
describe("Pairing test", () => {
it("runs", () => {
expect(myConst).toBe(true);
});
});
describe("basic robot movement", () => {
it("moves in each direction successfully", () => {
@Mark-McCracken
Mark-McCracken / tables_from_json.tf
Created August 31, 2022 21:32
BigQuery tables from json schema
locals {
tables = {for idx, val in fileset(path.module, "./models/**/*.json"):
"${jsondecode(file("./${val}")).dataset}.${jsondecode(file("./${val}")).tableName}" => jsondecode(file("./${val}")) }
# Creates a map, keys are "dataset.table", values are decoded json.
# Will be unique per project
}
resource google_bigquery_table tables {
for_each = local.tables
depends_on = [
@Mark-McCracken
Mark-McCracken / example_json_schema.json
Last active August 31, 2022 21:18
example json schema
{
"$id": "file://json_schema/table_definition.schema.json",
"type": "object",
"properties": {
"tableName": {
"type": "string",
"minLength": 1,
"maxLength": 300,
"pattern": "^[a-zA-Z_](?:[a-zA-Z0-9_])*$"
},
@Mark-McCracken
Mark-McCracken / example_table_schema.json
Created August 31, 2022 21:01
example table schema
{
"$schema": "../../json_schemas/table_definition.schema.json",
"tableName": "billedusage",
"tableType": "transactional fact",
"dataset": "sid_common",
"description": "Total bill for per customer per month",
"labels": {},
"clusteringColumns": [],
"columns": [
{
@Mark-McCracken
Mark-McCracken / create_music_round.py
Created August 15, 2022 15:11
create_music_round.py
def create_music_round():
prs.slides.add_slide(slide_layouts.get_by_name("MUSIC_ROUND_INTRO"))
def create_song_obj_from_folder(folder):
try:
question = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^question\.(mp3|m4a)$", file_path))
answer = question
try:
answer = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^answer\.(mp3|m4a)$", file_path))
except:
@Mark-McCracken
Mark-McCracken / create_rounds_preview.py
Created August 15, 2022 14:57
create_rounds_preview
ROUNDS = [name.upper() for name in book.sheetnames if name != "Wipeout"]
def create_rounds_preview():
rounds_slide = prs.slides.add_slide(slide_layouts.get_by_name("ROUNDS"))
Q1_idx, Q2_idx, Q3_idx, Q4_idx, Q5_idx, Q6_idx = 10, 11, 12, 13, 14, 15 # defined when creating the objects, can't change these easily
rounds_slide.placeholders[Q1_idx].text = f"1. {ROUNDS[0]} - 10 QUESTIONS"
rounds_slide.placeholders[Q2_idx].text = f"2. {ROUNDS[1]} - 10 QUESTIONS"
rounds_slide.placeholders[Q3_idx].text = f"3. {ROUNDS[2]} - 10 QUESTIONS"
rounds_slide.placeholders[Q4_idx].text = f"4. PICTURE ROUND - 9 QUESTIONS"
@Mark-McCracken
Mark-McCracken / def_create_worded_round.py
Created August 15, 2022 14:56
def_create_worded_round.py
def create_worded_round(round_number):
round_name = ROUNDS[round_number - 1]
questions = [
{"question": pair[0].value, "answer": pair[1].value}
for pair in book.worksheets[round_number - 1]['A2':'B11']
if pair[0].value is not None and pair[1].value is not None
]
assert len(questions) == 10, f"Round {round_number} called {round_name} does not have 10 questions"
round_intro_slide = prs.slides.add_slide(slide_layouts.get_by_name("ROUND_ANNOUNCEMENT"))
round_intro_slide.placeholders[10].text = f"{round_name} ROUND"
@Mark-McCracken
Mark-McCracken / powerpoint_approx_structure.py
Last active August 15, 2022 14:58
powerpoint_approx_structure.py
// imports etc...
book = load_workbook(path.join("questions", "questions.xlsx"), read_only=True)
// ready to read out excel content
prs = Presentation("template.pptx")
slide_layouts = prs.slide_master.slide_layouts
// implementation functions...
@Mark-McCracken
Mark-McCracken / example_refresh_datasource_dag.py
Created May 4, 2021 23:05
An example of using the RefreshDatasourceOperator
from datetime import datetime, timedelta
from airflow import models
from airflow.contrib.operators.bigquery_operator import BigQueryOperator
from airflow.operators.tableau_plugin import RefreshDatasourceOperator
default_dag_args = {
'start_date': datetime(2021, 4, 5),
'owner': 'Mark McCracken',
'retries': 1,
'retry_delay': timedelta(minutes=5),
@Mark-McCracken
Mark-McCracken / refresh_datasource_operator.py
Created May 4, 2021 22:58
Refresh Tableau Data Source airflow operator
from airflow.operators import BaseOperator
from os import environ
from time import sleep
import requests
import xml.etree.ElementTree as ET
class RefreshDatasourceOperator(BaseOperator):
auth_token = None
site_id = None