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 datetime | |
from typing import Optional, List | |
from pydantic import BaseModel | |
class PlaidBalance(BaseModel): | |
current: float | |
available: Optional[float] | |
iso_currency_code: Optional[str] | |
limit: Optional[float] |
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 random import randint | |
import pandas as pd | |
num_observations = 500 | |
dates = pd.to_datetime([f"{randint(2018, 2020)}-{randint(1, 12)}-{randint(1, 27)}" | |
for _ in range(num_observations)]).unique() | |
df = pd.DataFrame({"date": dates, | |
"balance": [randint(0, 10000) | |
for _ in range(len(dates))] | |
}) |
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
# set first (oldest balance as index entry) | |
new_indexes = [0] | |
# choose columns that are not the date column | |
cols = [d for d in df.columns if d != "date"] | |
# iterate over rows | |
for i, row in df.iterrows(): | |
if i == 0: #skip 0 index since it has no previous balance | |
continue | |
# if not all values of the previous row/date is not equal to current - then we have new observation | |
if not (df.iloc[i-1][cols] ==row[cols]).all(): |
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 functools import reduce | |
values = df.values | |
new_values = [] | |
cols = [df.columns.get_loc(d) for d in df.columns if d != "date"] | |
new_values.append(values[0]) | |
def compress_helper(x, y): | |
if (x[cols] == y[cols]).all(): | |
return x |
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
cols = [d for d in df.columns if d != "date"] | |
compressed_df = df.loc[~(df[cols].shift() == df[cols]).all(axis=1)].reset_index(drop=True) |
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 | |
#cast as object to be able to set np.nan and handle different types | |
arr = df[cols].values.astype(object) | |
# build shifted array | |
shifted = np.roll(arr, 1) | |
shifted[0] = np.nan | |
# choose indexes based on shift comparaison |
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
# https://apple.stackexchange.com/questions/175215/how-do-i-assign-a-keyboard-shortcut-to-an-applescript-i-wrote | |
on run {input, parameters} | |
tell application "System Events" | |
key code 123 using command down | |
keystroke "print(" | |
key code 124 using command down | |
keystroke ")" | |
end tell |
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 torch | |
import torch.nn as nn | |
import pytorch_lightning as pl | |
class NCE(pl.LightningModule): | |
""" | |
This implementation is taken from https://github.com/Spijkervet/SimCLR/blob/master/simclr/modules/nt_xent.py | |
The mask_correlated_samples funtion has been modified to be much faster to compute | |
and therefore be able to be called at train time without a predifined batch size. | |
""" |
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 torch | |
import torch.nn as nn | |
import pytorch_lightning as pl | |
class BoringModel(pl.LightningModule): | |
def __init__( | |
self | |
): | |
super(BoringModel, self).__init__() | |
self.automatic_optimization = False |
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
for name in $(aws dynamodb list-tables | jq .TableNames) | |
do | |
l=${#name} | |
if [ ${#name} -le 3 ]; then echo "Skipping name!" | |
else | |
short=${name:1:l-2} # clean json string representation of dataset | |
if [ "${short: -1}" == '"' ] | |
then short=${name:1:l-3} | |
fi | |
echo "Updating Table: ${short}" |
OlderNewer