A Capital One celebration of Pi Day
Pi Day celebration with pie and PYthon
No matter how you spell it (or slice it), most of us can agree - it’s the best! To celebrate Pi Day, and the fact that Capital One Tech is hiring engineers and developers, we compiled a recipe book of everyone’s favorite PIES from some of our main people centers. And to make it extra festive we asked four of our engineers to write each recipe in everyone’s favorite programming language: PYthon.
Boston Cream, Pecan, Apple Crumb, and Peanut Butter pies... easy as 3.14. Make one or make them all, just be sure to send us a piece (or at least share a picture with us)!
Boston cream pie by sr distinguished engineer, Chris Fauerbach
Pie + Capital One Boston campus = wicked good
# Boston Cream Pie
"""
Julia Childs once said... something great about food.
Don't know if she ever talked about Boston Cream Pie
... but it's my favorite. Annual birthday cake/pie from
my wonderful wife, to whom I dedicate this recipe
"""
import logging
from enum import Enum
# import time
def sleep(seconds):
print(f"Fake sleeping for {seconds} seconds.")
class Oven():
ROOM = 65
def __init__(self):
self.temperature_fahrenheit = Oven.ROOM
self.target_temperature = None
self.cooked_items = []
def isPreHeated(self):
print(f"Temperature is just {self.temperature_fahrenheit}, waiting till we're at {self.target_temperature}")
if not self.target_temperature:
print("Target temperature is not set.")
return False
retval = self.temperature_fahrenheit >= self.target_temperature
self.temperature_fahrenheit = self.target_temperature # hack
return retval
def bake(self, containers):
while not self.isPreHeated():
print("Not pre-heated yet!")
# time.sleep(1)
sleep(1)
print("Cooking!")
# time.sleep(30)
sleep(30)
print("Cooking is done!")
for container in containers:
self.cooked_items.append(container)
for itm in self.cooked_items:
itm.cooked()
class Measurements(Enum):
CUP = 0
OUNCE = 1
TBSP = 2
TSP = 3
class Oils(Enum):
CRUDE_OIL = 0
COOKING_OIL = 1
MOTOR_OIL = 2
LIGHT_OIL = 3
HEAVY_OIL = 4
LUBRICANT = 5
PETROLEUM = 6
class Ingredients(Enum):
MILK = 0
VANILLA_PUDDING_PACKET = 1
CREAM_WHIPPED = 2
CHOCOLATE_BAKING_UNSWEETENED = 3
BUTTER = 4
SUGAR_POWDERED = 5
class Ingredient():
def __init__(self, ingredient, quantity, measurement):
self.ingredient = ingredient
self.quantity = quantity
self.measurement = measurement
class CakeMix():
def __init__(self, cooked_version):
self.cooked_version = cooked_version
def mix(self):
return self
class BakedGood():
def __init__(self, description):
self.description = description
self.baked_good = None
self.filling = None
self.decoration = None
def __str__(self):
fillings = ", ".join(self.filling)
decorations = ", ".join(self.decoration)
return f"A {self.description} containing a filling made of {fillings} and topped with a decoration of {decorations}"
class Pan():
def __init__(self):
self.batch = None
self.cake = None
def spray(self, oil):
print(f"Basking in the glow of {oil.name}")
def cooked(self):
print("Cooked!")
self.cake = BakedGood(self.batch.cooked_version)
def fill(self, batch):
self.batch = batch
class Plate():
def __init__(self):
self.baked_good = None
class Microwave():
HIGH = 1
LOW = 0
OFF = None
def __init__(self):
self.level = None
def nuke(self, item, seconds):
print("Setting up the microwave...")
print(f"Pressing start on the microwave. Hang tight for {seconds} seconds")
# time.sleep(seconds)
sleep(seconds)
print("beep beep beep. Microwave done!")
def fillPans(pans, mix):
for pan in pans:
pan.fill(mix)
def assemble(plates, containers, filling):
for container, plate in zip(containers, plates):
plate.baked_good = container.cake
plate.baked_good.filling = filling
print("Assembled item.")
def decorate(baked_goods, decoration):
for bg in baked_goods:
bg.decoration = decoration
def mainMethod():
"""Main methods are where we start."""
pans = [Pan(), Pan()]
mix = CakeMix("yellow cake").mix()
for pan in pans:
pan.spray(Oils.COOKING_OIL)
fillPans(pans, mix)
oven = Oven()
oven.target_temperature = 350
oven.bake(pans)
filling = { 'milk': Ingredient(Ingredients.MILK, 1.0, Measurements.CUP)
,'puddin': Ingredient(Ingredients.VANILLA_PUDDING_PACKET, 3.4, Measurements.OUNCE)
,'whipped cream': Ingredient(Ingredients.CREAM_WHIPPED, 0.5, Measurements.CUP)
}
plates = [Plate(), Plate()]
assemble(plates, pans, filling)
glaze = { 'unsweet baking chocolate': Ingredient(Ingredients.CHOCOLATE_BAKING_UNSWEETENED, 1.0, Measurements.OUNCE)
,'butter': Ingredient(Ingredients.BUTTER, 1.0, Measurements.TBSP)
,'powdered sugar': Ingredient(Ingredients.SUGAR_POWDERED, 1.0, Measurements.CUP)
,'milk': Ingredient(Ingredients.MILK, 1.0, Measurements.TBSP)
}
microwave = Microwave()
microwave.level = Microwave.HIGH
microwave.nuke(glaze, 60)
decorate([plate.baked_good for plate in plates], glaze)
print("Refrigerate!")
# time.sleep(3600)
sleep(3600)
print("Time to eat!")
for plate in plates:
print(f"{plate.baked_good}")
if __name__ == "__main__":
mainMethod()
Pecan pie by software engineer, Richard Shi
Everything is bigger in Texas - including the pecan pies and our Plano campus.
# Pecan Pie
from ingredients import Flour, Salt, Shortening, Butter, Water, Pecans, LightCornSyrup, Eggs, Sugar, VanillaExtract
from measurements import Pinch, Teaspoon, Tablespoon, Cup, Unit, Inch
from appliances import Oven
from kitchenware import LargeBowl, SmallBowl, Fork, WireRack
from bakeware import PiePan
class PecanPie:
def __init__(self):
self.ingredients = {
'pie_crust': {
'flour': Flour( Cup( 1 ) ),
'salt': Salt( Teaspoon( 1/4 ) ),
'shortening/butter': [
Shortening( Cup( 1/3 ) ),
Butter( Cup( 1/3 ) )
],
'water': Water( Tablespoon( 3 ), 'cold' )
},
'filling': {
'pecans': Pecans( Cup( 1 + 1/4 ) ),
'light_corn_syrup': LightCornSyrup( Cup( 1 ) + Tablespoon( 1 ) ),
'eggs': Eggs( Unit( 3 ), 'large' ),
'sugar': Sugar( Cup( 1/2 ) + Tablespoon( 1 ) ),
'vanilla_extract': VanillaExtract( Tablespoon( 1 + 1/2 ) ),
'salt': Salt( Pinch() )
}
}
def make(self):
ingredients = self.ingredients
# Step 1
oven = Oven.preheat(temperature=350, unit='Fahrenheit')
# Step 2
pie_crust = LargeBowl.combine([ ingredients['pie_crust']['flour'],
ingredients['pie_crust']['salt'] ])
# Step 3
while pie_crust.texture is not 'crumbly':
pie_crust.cut_in( ingredients['pie_crust']['shortening/butter'] )
# Step 4
while pie_crust.texture is not 'dough':
pie_crust.add( ingredients['pie_crust']['water'], 'slowly' )
pie_crust.toss_with( Fork() )
# Step 5
pie_pan = PiePan( Inch( 9 ) )
pie = pie_pan.emplace( pie_crust.roll_out(until='fits') )
# Step 6
pie_crust.trim_beyond_edge( Inch( 1/2 ) )
pie_crust.crinkle_edges(with=Fork())
# Step 7
pie_crust.lay_evenly( ingredients['filling']['pecans'] )
# Step 8
filling = SmallBowl.beat([ ingredients['filling']['light_corn_syrup'],
ingredients['filling']['eggs'],
ingredients['filling']['sugar'],
ingredients['filling']['vanilla_extract'],
ingredients['filling']['salt'] ],
until='well_combined')
# Step 9
filling.pour_over(pie)
# Step 10
oven.bake(pie,
temperature=350, temp_unit='Fahrenheit',
duration=[45, 50], duration_unit='minutes',
until='knife_inserted_in_center_comes_out_clean')
# Step 11
WireRack.cool(pie)
def main():
pecan_pie = PecanPie()
pecan_pie.make()
# Step 11
pecan_pie.enjoy()
Apple crumb pie by lead software engineer, Steven Lott
Our people center in the Big Apple is calling your name… and so is a slice of this pie.
# Apple Crumb Pie
"""
I look at Pie as part of my daily serving of good, wholesome, fruit. And Python is good, wholesome programming. Programming should be like dessert, a nice way to cap off understanding the problem and how it should be solved.
"""
from typing import NamedTuple, Union
from fractions import Fraction
from kitchen import Bowl, Oven, Foil, Timer, WireRack, Combination
class Ingredient(NamedTuple):
amount: Union[int, Fraction]
unit: str
yummy_thing: str
class PyShell:
def __init__(self, diameter: int, unit: str) -> None:
self.size = diameter
self.unit = unit
self.filling: Combination
self.topping: Combination
def fill(self, bowl: Bowl) -> None:
self.filling = bowl.content()
def sprinkle(self, bowl: Bowl) -> None:
self.topping = bowl.content()
class AppleCrumbPie:
shell = PyShell(9, "inch")
filling = [
Ingredient(6, "cups", "thinly sliced apples"),
Ingredient(1, "tbsp", "lemon juice"),
Ingredient(Fraction(3, 4), "cup", "white sugar"),
Ingredient(2, "tbsp", "all-purpose flour"),
Ingredient(Fraction(1, 2), "tsp", "ground cinnamon"),
Ingredient(Fraction(1, 8), "tsp", "nutmeg"),
]
crumb_topping = {
"flour": Ingredient(Fraction(1, 2), "cup", "all purpose flour"),
"sugar": Ingredient(Fraction(1, 2), "cup", "packed brown sugar"),
"butter": Ingredient(3, "tbsp", "butter"),
}
def __init__(self, oven: Oven, large_bowl: Bowl, small_bowl: Bowl) -> None:
self.oven = oven
self.large_bowl = large_bowl
self.small_bowl = small_bowl
self.foil = Foil()
def steps(self) -> None:
self.preheat()
self.pie_combine()
self.transfer()
self.topping_combine()
self.until_crumbly()
self.sprinkle()
self.bake()
self.cool()
def preheat(self) -> None:
self.oven.temp = 375
self.oven.on()
def pie_combine(self) -> None:
self.large_bowl.combine(*self.filling)
while not self.large_bowl.even():
self.large_bowl.mix()
def transfer(self) -> None:
self.shell.fill(self.large_bowl)
def topping_combine(self) -> None:
self.small_bowl.combine(
self.crumb_topping["flour"],
self.crumb_topping["sugar"],
)
def until_crumbly(self) -> None:
self.small_bowl.cut_in(self.crumb_topping["butter"])
while not self.small_bowl.crumbly():
self.small_bowl.cut()
def sprinkle(self) -> None:
self.shell.sprinkle(self.small_bowl)
self.foil.cover(self.shell)
def bake(self) -> None:
with Timer(25) as timer:
self.oven.bake(timer, self.shell)
self.foil.uncover()
with Timer(25) as timer:
self.oven.bake(timer, self.shell)
while not (
self.shell.topping.golden_brown()
and self.shell.filling.bubbly()
):
with Timer(1) as timer:
self.oven.bake(timer, self.shell)
self.oven.off()
def cool(self) -> None:
self.rack = WireRack()
self.rack.cool(self.shell)
if __name__ == "__main__":
pie = AppleCrumbPie(Oven(), Bowl(4), Bowl(2))
pie.steps()
Peanut butter by software engineer, Ariel Diamond
They say Virginia is for lovers. And peanut butter pie.
# Peanut Butter
from time import sleep
ingredients: dict = {
"eggs": {
"name": "eggs",
"status": "beaten",
"quantity": "2",
"measurement": "",
"step_number": "1"
},
"creamy_peanut_butter": {
"name": "creamy peanut butter",
"status": "",
"quantity": "1/3",
"measurement": "cup",
"step_number": "1"
},
"white_sugar": {
"name": "white sugar",
"status": "",
"quantity": "1/3",
"measurement": "cup",
"step_number": "1"
},
"light_corn_syrup": {
"name": "light corn syrup",
"status": "",
"quantity": "1/3",
"measurement": "cup",
"step_number": "1"
},
"dark_corn_syrup": {
"name": "dark corn syrup",
"status": "",
"quantity": "1/3",
"measurement": "cup",
"step_number": "1"
},
"butter": {
"name": "butter",
"status": " melted",
"quantity": "1/3",
"measurement": "cup",
"step_number": "1"
},
"vanilla_extract": {
"name": "vanilla extract",
"status": "",
"quantity": "1",
"measurement": "tsp",
"step_number": "1"
},
"salted_peanuts": {
"name": "salted peanuts",
"status": "",
"quantity": "1",
"measurement": "cup",
"step_number": "2"
},
"crust": {
"name": "pie crust",
"status": " unbaked",
"quantity": "1",
"measurement": "9-inch",
"step_number": "3"
}
}
class Oven():
def __init__(self):
self.temp: str = ""
self.dial_on: bool = False
self.timer: int = 0
self.contains: list = []
def set_temp(self, new_temp: str):
print(f"Oven temp set to {new_temp}. Preheating...")
sleep(1)
print(f"Oven temperature has reached {new_temp}. Ready to bake!")
sleep(1)
self.temp = new_temp
def turn_dial(self):
self.dial_on = True if self.dial_on == False else False
sleep(1)
def put_in_oven(self, bakeable: object):
self.contains.append(bakeable)
sleep(1)
def remove_from_oven(self, bakeable: object):
bakeable.is_baked = True
self.contains.pop(0)
self.dial_on = False
self.temp = ""
sleep(1)
def set_timer(self, baketime: int):
self.timer = baketime
def start_timer(self):
while self.timer:
timer = f"{self.timer}:00"
print(timer, end="\r")
sleep(1)
self.timer -= 5
print("DING The pie is ready!")
sleep(1)
def status(self):
print(f"My oven's current status: {self.__dict__}")
sleep(1)
class Bowl():
def __init__(self):
self.contents: dict = {}
self.is_mixed: bool = False
def mix_it(self):
self.is_mixed = True
print("All ingredients in bowl are now mixed together.")
sleep(1)
def add_ingredients(self, ingredients: dict, step: str):
for item in ingredients:
obj = ingredients[item]
if obj.get('step_number') == step:
self.contents[item] = obj
print(
f"Bowl now contains {obj.get('quantity')} {obj.get('measurement')}{obj.get('status')} {obj.get('name')}.")
sleep(1)
def status(self):
print(f"My bowl's current status: {self.__dict__}")
sleep(1)
class Pie():
def __init__(self):
self.is_filled: bool = False
self.is_assembled: bool = False
self.is_baked: bool = False
def make_crust(self, ingredients: dict):
crust = ingredients['crust']
print(f"{crust.get('name')} is ready to be filled!")
sleep(1)
def fill_crust(self, filling):
self.is_filled = True
self.is_assembled = True
print("Pie has been filled with everything in the bowl!")
sleep(1)
def status(self):
print(f"My pie's current status: {self.__dict__}")
sleep(1)
class Bakery():
def bake_pie(self, temp: str, ingredients: dict, time: str):
my_oven = Oven()
my_oven.status()
my_bowl = Bowl()
my_bowl.status()
my_pie = Pie()
my_pie.status()
my_oven.set_temp(temp)
my_oven.turn_dial()
my_bowl.add_ingredients(ingredients, "1")
my_bowl.mix_it()
my_bowl.add_ingredients(ingredients, "2")
my_bowl.mix_it()
my_pie.make_crust(ingredients)
my_pie.fill_crust(my_bowl.contents)
my_pie.status()
my_oven.put_in_oven(my_pie)
my_oven.status()
my_oven.set_timer(time)
my_oven.start_timer()
my_oven.remove_from_oven(my_pie)
my_oven.status()
my_pie.status()
my_bakery = Bakery()
my_pie = my_bakery.bake_pie("375", ingredients, 30)
Capital One engineers rave about Pi, pie, and Py
Chris Fauerbach
"We know Python is the best programming language out there, as further evidenced by its name starting with PIE. Like Python, pies are generally simple and straightforward. I can either make it from scratch, or import crust."
Read more by Chris here - How Do I Choose the Right Programming Language for My Team? → Choosing the right pie recipe can be hard, choosing the right programming language doesn’t have to be.
Richard Shi
A Haiku About Py:
“Python is simple
and easy to work with too
but mind your spaces.”
Read more by Richard Shi - 3 New Year’s Resolutions for Your Tech Career. → Your fourth resolution? More pie.
Steven Lott
“I look at Pie as part of my daily serving of good, wholesome, fruit. And Python is good, wholesome programming. Programming should be like dessert, a nice way to cap off understanding the problem and how it should be solved.”
More py by Steven Lott - A Five-Point Framework For Python Performance Management
Ariel Diamond
“I love pie because it is easy and fun to share -- it brings people together. Python is my favorite language to work in because it also brings people together! Any problem you have, your Python friends will help you solve it. And if you're feeling lazy, you can always get some prebaked Python that you can consume right away.”
More from Ariel Diamond - AWS Glue: An ETL Solution With Huge Potential. → Potential almost as huge as your pie baking skills.