Skip to content

Instantly share code, notes, and snippets.

@jamiekt
jamiekt / demo_xcom_problem.py
Created April 14, 2024 20:30
Airflow XCom problem - solved
import datetime
from typing import Sequence
from airflow.decorators import task, dag
from airflow.providers.amazon.aws.operators.emr import EmrServerlessCreateApplicationOperator
class JamietEmrServerlessCreateApplicationOperator(EmrServerlessCreateApplicationOperator):
template_fields: Sequence[str] = ["config"]
def __init__(self, **kwargs) -> None:
@jamiekt
jamiekt / demo_xcom_problem.py
Last active April 14, 2024 20:29
Airflow XCom problem
import datetime
from airflow.decorators import task, dag
from airflow.providers.amazon.aws.operators.emr import EmrServerlessCreateApplicationOperator
@dag(
dag_id="demo-xcom-problem",
start_date=datetime.datetime(2021, 1, 1),
catchup=False
)
@jamiekt
jamiekt / query.sql
Last active October 22, 2022 16:41
ARRAY() with SELECT AS STRUCT
SELECT c.borough,c.year,
ARRAY(
select as struct c2.month,sum(value) crime_tally
from `bigquery-public-data.london_crime.crime_by_lsoa` as c2
where c.borough = c2.borough
and c.year = c2.year
group by c2.month
) as monthly_summary
FROM (
select distinct borough,year
return {
match.group(0)
for matched_policy in matched_policies
if (match := re.search(r"p\d{6}", matched_policy)) is not None
}
prefixes = set()
for matched_policy in matched_policies:
search_result = re.search(r_search, matched_policy)
assert search_result is not None
prefixes.add(search_result.group(0))
return prefixes
import re
matched_policies = {...} #some logic to derive a set
return {
re.search(r"p\d{6}", matched_policy).group(0)
for matched_policy in matched_policies
}
[tool.poetry]
name = "real-time-event-processor"
version = "0.1.0"
description = ""
authors = []
[tool.poetry.dependencies]
python = "^3.9, <3.10"
Flask = "^2.0.1"
➜ poetry env info
Virtualenv
Python: 3.8.2
Implementation: CPython
Path: NA
System
Platform: darwin
OS: posix
@jamiekt
jamiekt / .pre-commit-config.yaml
Last active June 15, 2022 21:03
select python interpreter in poetry
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: black
@jamiekt
jamiekt / get-role-members.sh
Last active May 27, 2022 15:42
Useful gcloud IAM commands
gcloud projects get-iam-policy project-id \
--filter="bindings.role:roles/workflows.editor" \
--flatten="bindings[].members" \
--format="table(bindings.members)"
#### output
# group:group-name@example.com
# user:user-name@example.com
# servceAccount:service-account-name@project-id.iam.gserviceaccount.com