Skip to content

Instantly share code, notes, and snippets.

View dipta007's full-sized avatar
🏠
Working from home

Shubhashis Roy Dipta dipta007

🏠
Working from home
View GitHub Profile
@dipta007
dipta007 / Backup_model_run.py
Last active May 11, 2022 22:48
Create a backup of all codes during each run for reproducibility
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)
# Ugly Code
def set(var, val):
if var not in mp:
return False
mp[var] = val
return True
if set(count, 1):
pass
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
def one_argument(*args):
pass
def two_arguemnts(name, *args):
pass
def three_arguments(name, count, *args):
pass
# Ugly Code
add_address(road, block, city, state, country)
# Clean Code
add_address(address: Address)
# Ugly code
def call(arr):
arr.append(1)
call(arr)
# Clean Code
def call(arr):
arr.append(1)
return arr
cnt += batch_size
if cnt >= total_row:
pds = get_all(files, chunksize=batch_size)
cnt = 0
def data_generator():
total_row = NUMBER_OF_ROWS
files = [
'a.csv',
'b.csv',
'c.csv',
'd.csv',
]
pds = get_all(files, chunksize=batch_size)
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
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