Skip to content

Instantly share code, notes, and snippets.

View macloo's full-sized avatar
💭
Teaching some Python

Mindy McAdams macloo

💭
Teaching some Python
View GitHub Profile
@macloo
macloo / example_README.md
Last active October 3, 2019 16:44
An outline in GitHub Markdown of a proper and complete README file example for a software project. View RAW to see Markdown.

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 September 26, 2019 14:58
Export HTML and JavaScript of a Bokeh chart
# 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 September 10, 2019 15:34
Basic Python 3 for a SQLite db
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 September 9, 2019 20:14
Some lists and stuff
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 September 2, 2019 15:57
A short function lesson for beginners
# 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 July 31, 2019 22:38
D3 lesson from FCC No. 10: Learn About SVG in D3 and No. 11: Display Shapes with SVG
<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 July 31, 2019 21:45
From FCC D3 lessons, No. 8: Update the Height of an Element Dynamically
<style>
.bar {
width: 25px;
height: 100px;
display: inline-block;
background-color: blue;
/* extra style */
margin-right: 5px;
}
</style>
@macloo
macloo / make_list_from_file.py
Created April 16, 2019 18:12
Take a list of state abbreviations in a text file and put them into a Python list
# copy a column from a table into a plain-text file in Atom, save it
# mine is named states.txt
# here's how to get each line in that file into Python as a list of items
myfile = open('states.txt')
states_raw = myfile.readlines()
# now states_raw holds a list made from lines in states.txt
myfile.close()
@macloo
macloo / romy_scrape1.py
Last active April 12, 2019 17:36
Example of stripping and splitting text
from bs4 import BeautifulSoup
import requests
url = 'http://whc.unesco.org/en/list/937'
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
# <div class="alternate">
box = soup.find( "div", {"class":"alternate"} )
# print(box)
@macloo
macloo / headless_selenium.py
Last active April 9, 2019 23:46
Run Chrome headless with Selenium
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
chrome_options = Options()
chrome_options.add_argument("--headless")
# fill in your own path to installed chromedriver
driver = webdriver.Chrome(executable_path='/Users/dirname/dirname/dirname//chromedriver',
options=chrome_options)