Skip to content

Instantly share code, notes, and snippets.

View cicdw's full-sized avatar

Chris White cicdw

View GitHub Profile
@cicdw
cicdw / dask_delayed_example.py
Last active November 10, 2017 16:10
Code snippets for Medium blog post
from dask import delayed
# won't be evaluated until we call .compute()
fast_predict_over_time = delayed(fast_predict_over_time)
## using the same numpy arrays from above...
%%timeit -n 100
_ = fast_predict_over_time(x, y, z, False, res).compute()
@cicdw
cicdw / dask_task_graph_example.py
Created November 10, 2017 16:11
Code snippets for Medium blog post
@delayed
def predict_another_thing(x, y, z):
# model scoring code goes here
pass
@delayed
def complicated_feature_b(x, y):
# lets imagine this feature is *very* expensive to create
# and takes a full minute to process
@cicdw
cicdw / dask_timing.py
Last active November 10, 2017 17:06
Code snippets for Medium blog post
%%timeit -n 100
_, _ = dask.compute(results['w_overlay'],
results['predict_another_thing'])
# 100 loops, best of 3: 1.61 ms per loop

Test

$$ \langle X, X + Y \rangle \leq 2 $$

@cicdw
cicdw / post_standup.py
Last active July 30, 2019 04:26
Non-Prefect pieces of the post standup workflow
import datetime
from google.cloud.firestore import Client
import os
import random
import requests
def get_standup_date():
"""
Returns the current date, formatted, which maps
@cicdw
cicdw / add_prefect.md
Last active February 22, 2019 20:20
Diff after adding in Prefect code
- import os
...
+ import prefect
+ from prefect import Flow, Parameter, task
+ from prefect.client import Secret
+ from prefect.schedules import CronSchedule

+ @task
def get_standup_date():
@cicdw
cicdw / flow_deployment.py
Last active February 27, 2019 16:23
Create Prefect environment and deploy Flow
from prefect.environments import DockerEnvironment
env = DockerEnvironment(
base_image="python:3.6",
registry_url="XXXXXXXX",
python_dependencies=["google-cloud-firestore"],
files={"~/google-creds.json": "/root/google-creds.json"},
env_vars={"GOOGLE_APPLICATION_CREDENTIALS": "/root/google-creds.json"},
)
@cicdw
cicdw / reminder_flow.py
Last active July 30, 2019 04:27
choppy version of the Prefect reminder Flow
@task
def get_collection_name():
"""
Returns the current date, formatted, which maps
to a Google Firestore collection name.
"""
date_format = "%Y-%m-%d"
now = prefect.context["scheduled_start_time"]
return now.strftime(date_format)
@cicdw
cicdw / mapping_snippet.py
Created February 23, 2019 19:35
Extract of the mapping code from the reminder flow
reminder_flag = is_reminder_needed.map(get_team, unmapped(updates))
res = send_reminder.map(reminder_flag)
@cicdw
cicdw / post_standup_flow.py
Created February 25, 2019 01:02
complete code of the standup Prefect flow
import datetime
from google.cloud.firestore import Client
import random
import requests
import prefect
from prefect import Flow, Parameter, task
from prefect.client import Secret
from prefect.schedules import CronSchedule