-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_utils.py
68 lines (48 loc) · 1.6 KB
/
custom_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from IPython.display import Audio, display
from IPython.display import clear_output
from time import sleep
from timeit import default_timer as timer
import pandas as pd
import numpy as np
import os
def printPkgContents(pkg):
"""Pretty prints the contents of a package (skips the dunder ones).
The input param is a package object, can be hierarchical.
E.g.: annalectpy.utils.print_pkg_contents(annalectpy.utils)"""
print("\n===== " + pkg.__name__ + " contents =====")
for i in dir(pkg):
if i[0:2] != '__' and i != pkg.__name__ :
print(i)
print("\n\n")
def soundAlert(duration =0.05):
"""Makes a sound."""
framerate = 44100
#duration=.05
freq=300*3
t = np.linspace(0,duration,round(framerate*duration))
data = np.sin(2*np.pi*freq*t)
sound = Audio(data,rate=framerate, autoplay=True)
display(sound)
# sleep(duration + 0.5)
# clear_output()
def printRunTime(start_time, sound=True, sound_duration=0.1):
end_time = timer()
if sound:
soundAlert(sound_duration)
print("Runtime:", round((end_time - start_time)/60, 2), "min\n")
def read_n4jpass():
"""Reads neo4j connection credentials from .n4jpass file in current folder.
Expects one value per line, ignores comments, e.g.:
# comments here
user=neo4j
password=secretStuff123
"""
cur_folder = os.getcwd()
with open(cur_folder + '/.n4jpass', 'r') as f:
lines = f.readlines()
d = {}
for l in lines:
if l.strip() and (l[0] != '#'):
k, v = l.strip().split('=')
d[k] = v
return d