Skip to content

Instantly share code, notes, and snippets.

@mamedshahmaliyev
Last active December 8, 2020 10:13
Show Gist options
  • Save mamedshahmaliyev/b5adec2713194445a9f6853601c6b8d7 to your computer and use it in GitHub Desktop.
Save mamedshahmaliyev/b5adec2713194445a9f6853601c6b8d7 to your computer and use it in GitHub Desktop.
diffrent ad-hoc tasks in python
# pickle save and load
import pickle
pickle.dump(obj, open(file, 'wb'))
obj = pickle.load(open(file, 'rb'))
# datetime tasks
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# get execution time
import time
def getDuration(start_time, end_time):
d = round(end_time - start_time)
h = d // (60 * 60)
m = d // 60 % 60
s = d % 60
msg = ''
if h > 0: msg += str(h) + ' hours '
if m > 0: msg += str(m) + ' minutes '
msg += str(s) + ' seconds'
return msg
start_time = time.time()
time.sleep(5)
getDuration(start_time, time.time())
# virtual environments
python3 -m venv /d/python_envs/pymupdf
source /d/python_envs/pymupdf/Scripts/activate
deactivate
# run directly
/d/python_envs/pymupdf/bin/python file.py
/d/python_envs/pymupdf/bin/pip install -r requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment