This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
for k in ["MY_PUBLIC_VARIABLE", "MY_SECRET_VARIABLE"]: | |
print(k, os.getenv(k)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
my_component: | |
# Here you can specify an env-file with variables | |
# that can be used in the docker-container, | |
# BUT these variables can not be used here in the | |
# docker-compose using ${...} UNLESS it is a file named | |
# ".env". This file (in the same directory) is always | |
# loaded into the docker-compose, but not into the | |
# docker-containers unless the variables are mapped in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MY_SECRET_VARIABLE = "I'm batman!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.8-alpine | |
COPY app . | |
CMD python -u main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dotenv import load_dotenv | |
import os | |
# by default .env will be loaded | |
load_dotenv() | |
# if we had another file called .env2 | |
# we could load it using | |
# load_dotenv(".env2") | |
# now we can use os.getenv as before: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# first way | |
os.environ['TERM_PROGRAM'] | |
# => 'Apple_Terminal' | |
# a non-existing variable will lead to error | |
os.environ["THIS_VARIABLE_DOESNT_EXIST"] | |
# => KeyError: 'THIS_VARIABLE_DOESNT_EXIST' | |
# second way |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.signal import correlate | |
from scipy.signal import correlation_lags | |
# Function to calculate cross-correlation, | |
# extract the best matching shift and then shift | |
# one of the series appropriately. | |
def shift_for_maximum_correlation(x, y): | |
correlation = correlate(x, y, mode="full") | |
lags = correlation_lags(x.size, y.size, mode="full") | |
lag = lags[np.argmax(correlation)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
# Generate two series that are correlated | |
original_x = pd.Series(np.random.uniform(size=100)) | |
original_y = 1.3*original_x + np.random.normal(0, 0.1, size=100) | |
# Now create shifted versions, | |
# I create two examples, one where x is shifted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
# by default a dict | |
a = defaultdict(dict) | |
assert a[5] == {} | |
a[5]["a"] = 5 | |
assert a[5] == { "a": 5 } | |
# by default a list | |
a = defaultdict(list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import random | |
counter = Counter() | |
# add lists with random number of a, b and c. | |
counter.update([random.choice(["a", "b", "c"]) for _ in range(100)]) | |
counter.update([random.choice(["a", "b"]) for _ in range(100)]) | |
# merge with counts | |
counter.update({ "a": 10000, "b": 1 }) | |
# add directly |
NewerOlder