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 zipfile import ZipFile | |
import os | |
EXCLUDE = ['./wandb', './.history', './data', './__pycache__', './results', './models', | |
'./logs', './config.json', './saved_configs', './saved_models', './.ipynb_checkpoints'] | |
INCLUDE = ['.py', '.sh'] | |
def create(filename): | |
not_excluded = lambda root: not any(root.startswith(path) for path in EXCLUDE) |
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
# Ugly Code | |
def set(var, val): | |
if var not in mp: | |
return False | |
mp[var] = val | |
return True | |
if set(count, 1): | |
pass |
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
def check_password(username, password): | |
user = user_model.find_by_username(username) | |
if user.password != password: | |
user.increase_wrong_attempt() # Side Effect | |
return False | |
return 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
def one_argument(*args): | |
pass | |
def two_arguemnts(name, *args): | |
pass | |
def three_arguments(name, count, *args): | |
pass |
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
# Ugly Code | |
add_address(road, block, city, state, country) | |
# Clean Code | |
add_address(address: Address) |
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
# Ugly code | |
def call(arr): | |
arr.append(1) | |
call(arr) | |
# Clean Code | |
def call(arr): | |
arr.append(1) | |
return arr |
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
cnt += batch_size | |
if cnt >= total_row: | |
pds = get_all(files, chunksize=batch_size) | |
cnt = 0 |
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
def data_generator(): | |
total_row = NUMBER_OF_ROWS | |
files = [ | |
'a.csv', | |
'b.csv', | |
'c.csv', | |
'd.csv', | |
] | |
pds = get_all(files, chunksize=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
def merge_all(*args): | |
tmp = None | |
args = args[0] | |
for arg in args: | |
if tmp is None: | |
tmp = arg | |
else: | |
tmp = pd.merge(tmp, arg, how='inner', on=['id']) | |
return tmp |
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
def get_all(*args, chunksize): | |
pds = [] | |
args = args[0] | |
for arg in args: | |
pds.append(pd.read_csv(f'{BASE_PATH}/{arg}', chunksize=chunksize)) | |
return pds |
NewerOlder