Skip to content

Instantly share code, notes, and snippets.

View StephenFordham's full-sized avatar

Stephen Fordham StephenFordham

View GitHub Profile
@StephenFordham
StephenFordham / Example_1_call_method_Part C.py
Created February 12, 2022 11:39
Unusual ways to control attrbute access in Python, Example 1
emp = Employees('stephen', 'bournemouth', 30)
for key, value in emp.__dict__.items():
print('{} = {}'.format(key, value))
emp('Simon')
print('#####################################')
for key, value in emp.__dict__.items():
@StephenFordham
StephenFordham / Example_1_call_method_Part B.py
Last active February 12, 2022 11:28
Unusual ways to control attrbute access in Python, Example 1
class Employees(object):
def __init__(self, name, location, age):
self._name = name
self._age = age
self._location = location
# attribute re-assignment
def __call__(self, *args, **employee_info):
if hasattr(self, '_name') and len(args) == 1:
self._name = args[0]
@StephenFordham
StephenFordham / Example_1_call_method_Part A.py
Created February 12, 2022 11:16
Unusual ways to control attrbute access in Python, Example 1
class Employees(object):
def __init__(self, name, location, age):
self._name = name
self._age = age
self._location = location
emp = Employees('stephen', 'bournemouth', 30)
for key, value in emp.__dict__.items():
print('{} = {}'.format(key, value))
@StephenFordham
StephenFordham / jinja_templating_logout.html
Created November 6, 2021 20:48
jinja_templating_logout
<!--
...if block above...
-->
{% else %}
<h1>Explore BacGenomePipeline</h1>
{% with messages = get_flashed_messages(category_filter=['success']) %}
{% if messages %}
{% for message in messages %}
<h5 class="col-lg-4 col-sm-12 alert alert-success" role="alert" >{{message}}</h5>
@StephenFordham
StephenFordham / logout_flask_with_flash.py
Created November 6, 2021 20:38
logout_flask_with_flash
@app.route('/logout')
@login_required
def logout():
logout_user()
flash('You have successfully logged out', category='success')
session['username'] = None
return redirect(url_for('landing_page'))
@StephenFordham
StephenFordham / jinja_templating_logic.html
Created November 6, 2021 20:26
jinja_templating_logic
<div class="container">
<div class="carousel-caption text-start">
{% if active_user %}
<h1>Welcome {{ active_user }}</h1>
<h1>Explore BacGenomePipeline</h1>
<p>Raw reads to annotated bacterial Genome</p>
{% else %}
<h1>Explore BacGenomePipeline</h1>
{% with messages = get_flashed_messages(category_filter=['success']) %}
@StephenFordham
StephenFordham / landing_page.py
Created November 6, 2021 20:18
landing_page
@app.route('/', methods=['GET', 'POST'])
def landing_page():
try:
active_user = session['username']
active_user = re.findall('[A-Z][^A-Z]*', active_user)
active_user = ' '.join(active_user)
return render_template('landing_page.html', active_user=active_user)
except (KeyError, TypeError):
return render_template('landing_page.html')
@StephenFordham
StephenFordham / flask_login.py
Created November 6, 2021 19:49
flask_login
@app.route('/login', methods=['POST', 'GET'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is None:
flash('Please register to gain access', category='danger')
return redirect(url_for('register'))
@StephenFordham
StephenFordham / plotting_animated_bar.py
Created June 23, 2021 14:15
plotting_animated_bar
fig = px.bar(plot_df, x='Provider County', y="Observed Prescribing Rate per 100 Visits", color="Provider County",
animation_frame="Year", animation_group="Provider County", range_y=[3, 70],
title='Antibiotic Prescribing rates in US counties')
fig.show()
keys = [i for i in range(65)]
all_dataframes = {}
for i, county in zip(keys, df['Provider County'].unique()):
df2 = df[df['Provider County'] == county].sort_values('Year', ascending=True)
all_dataframes[i] = df2
master_df = []
for i in all_dataframes:
master_df.append(all_dataframes[i])