Skip to content

Instantly share code, notes, and snippets.

@jeroendelfos
jeroendelfos / program_running.py
Created August 16, 2019 09:38
Check if a program is running on your OS
def program_running(program_name):
prgrm = [p.name() for p in psutil.process_iter() if p.name() == program_name]
prgrm_is_running = len(r)>0
return prgrm
@jeroendelfos
jeroendelfos / plot_with_ybreak.py
Created August 15, 2019 11:10
Plot with a break in the y-axis
def bar_with_breakline(x, y, plot_type='bar', height_ratios=[10,1],
figsize=(10,5), title=None, ylabel=None, xlabel=None):
if plot_type == 'bar':
pplot = plt.bar
elif plot_type == 'line':
pplot = plt.plot
else:
sys.exit('Error: plot type not yet supported, closing')
gs = gridspec.GridSpec(2,1, height_ratios=[10,1])
@jeroendelfos
jeroendelfos / show_progress.py
Last active May 31, 2019 07:53
Show progress of a loop on one line
def show_progress(loop, loops):
print('Progress: [{}/{}]'.format(loop, loops), end='\r')
# Example code:
prime_numbers = []
for i in range(1e6):
for j in range(2,i):
if i % j == 0:
break