Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Teaching some Python

Mindy McAdams macloo

💭
Teaching some Python
View GitHub Profile
@macloo
macloo / president.html
Created Mar 18, 2020
Starter template for Flask + Jinja
View president.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ pres["President"] }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
</head>
<body>
@macloo
macloo / pres_video2.py
Created Mar 17, 2020
Basic Flask app before adding templates
View pres_video2.py
from flask import Flask
app = Flask(__name__)
import csv
def convert_to_dict(filename):
datafile = open(filename, newline='')
my_reader = csv.DictReader(datafile)
list_of_dicts = list(my_reader)
datafile.close()
@macloo
macloo / fetch_example.js
Last active Oct 31, 2019
Short and sweet example of using fetch and an API
View fetch_example.js
// from https://frontendmasters.github.io/bootcamp/ajax - more info there
const BREEDS_URL = "https://dog.ceo/api/breeds/image/random";
const promise = fetch(BREEDS_URL);
promise
.then(function(response) {
const processingPromise = response.json();
return processingPromise;
@macloo
macloo / example_README.md
Last active Oct 3, 2019
An outline in GitHub Markdown of a proper and complete README file example for a software project. View RAW to see Markdown.
View example_README.md

project name

(project name) will solve your problem of _____ by providing _____ and allowing _____.

Look how easy it is to use (code example follows):

import project
# get your stuff done
project.do_stuff()
@macloo
macloo / bokeh_export.py
Created Sep 26, 2019
Export HTML and JavaScript of a Bokeh chart
View bokeh_export.py
# assumes you already made a chart with Bokeh and it is assigned to a variable, chart1
# added code for exporting the chart as HTML + JS
# https://bokeh.pydata.org/en/latest/docs/user_guide/embed.html
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html
# create a complete HTML file
html = file_html(chart1, CDN, "bokeh_chart01")
@macloo
macloo / sqlite_first.py
Created Sep 10, 2019
Basic Python 3 for a SQLite db
View sqlite_first.py
import sqlite3
# no need to pip-install; comes w/ Python 3
# from https://www.youtube.com/watch?v=o-vsdfCBpsU
# db connection
# it's fine if the db named here doesn't exist yet - will be created
conn = sqlite3.connect('tutorial.db')
# define cursor
@macloo
macloo / percentiles.py
Created Sep 9, 2019
Some lists and stuff
View percentiles.py
percentiles = [10, 20, 30, 40, 50, 60 ,70, 80, 90]
all_scores = [44, 49, 54, 56, 62, 66, 67, 70, 72, 73, 73, 77, 80, 81, 83, 85, 85, 85, 89, 90, 96]
percentiles_with_scores = {k: [] for k in percentiles}
score_percentiles = tuple(zip(np.percentile(all_scores, percentiles), percentiles))
# let's see what's what
print("Tuples:")
print(score_percentiles)
print("The dictionary:")
@macloo
macloo / function_example.py
Created Sep 2, 2019
A short function lesson for beginners
View function_example.py
# To define a function, you write something in this pattern:
def name_of_function(arg1, arg2):
instructions
instructions
instructions
...
return something
# the number of arguments in parentheses may be none, or one, or any number
@macloo
macloo / d3_first_svg.html
Last active Jul 31, 2019
D3 lesson from FCC No. 10: Learn About SVG in D3 and No. 11: Display Shapes with SVG
View d3_first_svg.html
<style>
svg {
background-color: pink;
}
</style>
<body>
<script>
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
const w = 500;
@macloo
macloo / d3_simple_bar.html
Created Jul 31, 2019
From FCC D3 lessons, No. 8: Update the Height of an Element Dynamically
View d3_simple_bar.html
<style>
.bar {
width: 25px;
height: 100px;
display: inline-block;
background-color: blue;
/* extra style */
margin-right: 5px;
}
</style>
You can’t perform that action at this time.