Skip to content

Instantly share code, notes, and snippets.

View nomtrosk's full-sized avatar

Henrik Anker Rasmussen nomtrosk

View GitHub Profile
@nomtrosk
nomtrosk / deep_get.py
Last active December 14, 2023 10:32
Get element safely from nested dict
def deep_get(data:dict[str,Any], keys:list[str]):
try:
key = keys[0]
except IndexError:
return data
try:
return deep_get(data[key], keys[1:])
except (KeyError,TypeError):
return None
@nomtrosk
nomtrosk / cloud_schedule.py
Created April 13, 2020 09:23
Google cloud schedule Python example
from google.cloud.scheduler import CloudSchedulerClient
def create_job(project_id: str, region: str, job_name: str, http_target: str):
"""
Create a job with the name in job_name invoking the url in http_target every one minute
"""
client = CloudSchedulerClient()
location_path = client.location_path(project_id, region)
job_path = client.job_path(project_id, region, job_name)