#!/usr/bin/env python # coding: utf-8 # # PyCamp: Next Level # ### Camp MightyMoose # # ![bonfire](./PyCampEventListening/camping.png) # # Camp Description (March - April 2020): # # This camp will show our students just how powerful Python can be! Campers will explore its terminal basics and learn how to find and understand Python packages to make any project they can imagine! Advanced topics will include AI (Artificial Intelligence), Database Operations, and more. Welcome to the real world of programming! # # #### Prerequisites: # Previous Python experience or other text-based programing language (JavaScript, C#, etc.) # ## FAQ # # **Q** What does FAQ mean? # # **A** FAQ means Frequently Asked Questions # # **Q**: What IDE should I use? # # **A**: Try out a bunch! The instructor will show you several. Try Spyder, it comes with [Anaconda](https://www.anaconda.com/downloads). # # **Q**: What version of Python will we need? # # **A**: Python3 or later (not 2.7). I recommend getting Python from [Anaconda](https://docs.conda.io/projects/conda/en/latest/index.html) as we're going to be using [Jupyter Notebooks](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/What%20is%20the%20Jupyter%20Notebook.html) and JupyterLab and these are included in that distro. # # **Q**: What if I'm home from school and want to learn calculus? # # **A**: Here's [a starting place](https://github.com/4dsolutions/School_of_Tomorrow/blob/master/stats_works.ipynb) (one of many). Or lets just [plot some functions](PlotFunctions.ipynb). # # **Q**: Do I need Git? # # **A**: You will have a better experience if you can clone [this repo](https://github.com/4dsolutions/python_camp). Then you can ```git pull``` future updates. On Windows? [Get git](https://gitforwindows.org/) here. # # **Q**: Who's a good Git teacher on Youtube? # # **A**: Daniel Shiffman is an excellent teacher on many subjects. Checkout his [Github for Poets playlist](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZF9C0YMKuns9sLDzK6zoiV). # # **Q**: Who's a good Python teacher on Youtube? # # **A**: The Socratica channel has [many pithy Python videos](https://www.youtube.com/playlist?list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-). Make your own? # # **Q**: Where's a good place to begin with data science? # # **A**: Follow [Jake Vanderplas](http://vanderplas.com/) and study his work. Follow him on [Twitter](https://twitter.com/jakevdp/status/1278757686343917569?s=20) and follow [some he follows](https://twitter.com/jakevdp/following) to get your feet wet with Twitter. # # **Q**: I already have an older version of Python3 that's not Anaconda, will that be OK? # # **A**: In a BYOD camp we leave those decisions up to you. You may be concerned that too many Pythons will leave you with [a tangle](https://xkcd.com/1987/). # # **Q**: I've already done some Object Oriented Programming (OOP), am I too advanced for this course? # # **A**: Do you know [how Python does OO](animals.py)? Coding up ```animals.py``` is one of the many hikes. We won't do them all. Your instructor will get a sense of what hikes might work best, given who shows up in your group. # ## DAY ONE # # Python is used for many purposes in many walks of life. # # We're going to tell stories around the campfire (share lore) and take hikes (work out, go places, see things, try stuff out). # # See **More Campfire Stories** at the end. # # ### Example Workout (hike): # # * Create your Github account (if you don't already have one) # # * Fork this repo # # * Clone the forked repo (your copy) and change at will # # * Clone [this repo](https://github.com/4dsolutions/python_camp) (original) and ```git pull``` for future updates # # * Bookmark the [Git docs](https://git-scm.com/doc) # # * Download the Anaconda distro of Python # # [Looking for games](https://pypi.org/project/freegames/)? # # How about [Pygame](https://pygame.readthedocs.io/en/latest/)? Repl.it lets you try it out. # # ### Hike: # # Run, Fork, Port, Modify any / all of the following: # # * [PyCamp Screen Saver](https://repl.it/@kurner/PyCamp-Screen-Saver) # # * [PyCampEventListening](https://repl.it/@kurner/PyCampEventListening) # # * [FishyDemo2](https://repl.it/@kurner/FishyDemo2) # # If you get serious about Pygame, install it locally (e.g. through [PyCharm](https://www.jetbrains.com/pycharm/)). # ### Examples of Python in Action # # * [Arbitrary Precision Computing](https://github.com/4dsolutions/Python5/blob/master/Extended%20Precision.ipynb) (e.g. "pi to a thousand places") # # * [A Library](https://github.com/4dsolutions/School_of_Tomorrow/blob/master/Flextegrity_Lattice.ipynb) for working with [POV-Ray](http://povray.org) # # * [A Flask website](http://thekirbster.pythonanywhere.com/) # In[1]: # Arbitrary Precision Demo # lets see if your calculator can keep up with Python import decimal with decimal.localcontext() as ctx: # context manager ctx.prec = 1000 n = decimal.Decimal(1e102) e = (1 + 1/n) ** n # euler's number as n->infinity print("{}".format(str(e)[:200])) # Everyday mathematics comes alive in Python's Jupyter Notebooks # In[26]: from primes import * # In[27]: isprime(198829938849585877) # In[28]: factors(198829938849585877) # In[5]: print(eratosthenes(1000)) # For further reading: # # * [The Calculator of Tomorrow: Using Arbitrary Precision](https://medium.com/@kirbyurner/calculator-of-tomorrow-using-arbitrary-precision-8f219b0092d9) # ## DAY TWO # # Some of our skill building topics: # # * downloading and installing [packages](https://pypi.org/) with [conda](https://docs.conda.io/projects/conda/en/latest/index.html) and [pip](https://pypi.org/project/freegames/) # # * importing modules and packages (understanding about ```__init__```) # # * Python and [Unicode](https://codepoints.net/) (printing ranges of unicode characters) # # * sys.argv and passing arguments from the command line # # * many number types in Python (including [3rd party](https://gmpy2.readthedocs.io/en/latest/)) # ### Unicode Section # # Unicode includes almost all the characters needed to encode human languages. Python source code is usually in unicode but doesn't have to be. # # [Show Me the Characters! (Youtube)](https://youtu.be/Z_sl99D2a18) # # Not every browser font is ready to show them all. Your IDE may also have some trouble showing the characters you want. # # Useful websites: # # * [Alan Wood’s Unicode resources](http://www.alanwood.net/unicode/index.html) # * [Python Unicode HOWTO](https://docs.python.org/3/howto/unicode.html) # In[6]: # calling python through the operating system get_ipython().system(' python -m unicode_fun') # In[7]: get_ipython().system(' python -m unicode_fun arabic') # In[8]: get_ipython().system(' python -m unicode_fun food') # [monkey-face](http://unicode.org/emoji/charts/full-emoji-list.html#monkey-face) # In[9]: three_wise_monkeys = ["1F648", "1F649","1F64A"] for monkey in three_wise_monkeys: print(chr(int(monkey, 16))) # see, hear, say no evil # [face-unwell](http://unicode.org/emoji/charts/full-emoji-list.html#face-unwell) # In[10]: print(chr(int("1F637", 16))) # masked face # In[11]: import animals animals.test_dog() # ## DAY THREE # # #### Machine Learning # # Our toolkit: [scikit-learn](https://scikit-learn.org/stable/index.html) # # Lets use a fine specimen of [an on-line tutorial](https://www.codementor.io/@garethdwyer/introduction-to-machine-learning-with-python-s-scikit-learn-czha398p1), forked to add requirements.txt so we can run it in binder. # # Stories about ML / [DL](https://playground.tensorflow.org/) (overview of AI) # # ### Hike: # # * Warm up on [Repl.it](https://repl.it/@kurner/machine-learning-intro) (sentiment analysis) -- you can cut and paste this to your local IDE. # # * Dive in to [sklearn-intro](https://github.com/4dsolutions/sklearn-intro) (headline or clickbait?) -- you might want to clone this one. # # ### Hike: # # * [Hand-written Digit Recognition](https://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html) (runs in binder, see launch bar) # Data Sources: # # * [Kaggle](https://www.kaggle.com/datasets) # * [KDnuggets](https://www.kdnuggets.com/) # * [UCI](http://archive.ics.uci.edu/ml/index.php) # Did you enjoy the headline or clickbait tutorial [by Gareth Dywer](https://www.codementor.io/@garethdwyer/introduction-to-machine-learning-with-python-s-scikit-learn-czha398p1)? He was using a Support Vector Machine classifier. # # Perhaps you would like to read about [Random Forests](https://machinelearningmastery.com/random-forest-ensemble-in-python/)? They're made from a myriad of especially groomed Decision Trees, but of course. # ## DAY FOUR # # #### Database Operations # # Stories about Data Science # # Topics: # # * [context managers](ContextManager.ipynb) in Python (a type of class used with keyword "with") # # * connection versus cursor objects # # * [SQL](https://sqlite.org/index.html) (via sqlite3) # # * [NoSQL](https://en.wikipedia.org/wiki/NoSQL) # # * pandas DataFrame # # ### Hike: # # * Clone or Unzip a Github Repo # # * Skill build around SQL # # * Skill build around Jupyter Notebooks and Jupyter Lab # In[12]: from connector import DB with DB("./data/x_files.db") as db: print(db.conn) print(db.curs) # In[13]: query = "SELECT * FROM ufo_sightings WHERE city = 'Toledo' AND state = 'OH'" with DB("./data/x_files.db") as db: obj = db.curs.execute(query) # use the cursor object to print("SHAPE DATE/TIME") for rec in obj.fetchall(): # result set if not rec[3]: # filter out if no shape continue print("{:15} {:16}".format(rec[3], rec[5])) # In[14]: import usercrud # CRUD: create, retrieve, update, delete import hashlib # In[15]: usercrud.add_one("Charlie", "spam") # In[16]: # pw = input("Please enter your password. > ") pw = "pinkpanther" hashpw = hashlib.sha256(bytes(pw, encoding='utf-8')).hexdigest() print(hashpw) # In[17]: # you might need a cell like this to force recompilation of a module # import imp # imp.reload(usercrud) # In[18]: def table(): print("Users Table") for record in usercrud.fetch_all(): print("{:10} {:256}".format(*record)) # In[19]: table() # In[20]: import pandas as pd import sqlite3 as sql con = sql.connect("./data/x_files.db") data=pd.read_sql_query("SELECT count(*) as how_many, shape " "FROM ufo_sightings GROUP BY shape ORDER BY how_many", con) data.head(10) # For Further Reading: # # [Polyhedrons in a Database](https://github.com/4dsolutions/Python5/blob/master/Polyhedrons%20101.ipynb) # ## DAY FIVE # # #### Pulling It All Together # # Lets build a web server and run it on localhost! # # Stories: # # Python and Websites (some of the solutions) # # Visualization Libraries: # # * [matplotlib](https://matplotlib.org/) # * [Bokeh](https://twitter.com/bokeh) # * [Altair](https://altair-viz.github.io/) # # [Example Website](http://thekirbster.pythonanywhere.com) # # Topics: # # * HTTP # # * JSON, CSV, XML # # # ### Hike: # # * conda install flask # # * conda install requests # # * run and modify the web application(s) # In[21]: import requests # In[22]: myrequest = requests.get("http://thekirbster.pythonanywhere.com/api/elements?elem=H") # In[23]: myrequest.text # ## More Campfire Stories # # One of our campers was able to crack into the users.db table and correctly guess a password (for Charlie I think it was). Software that tests millions of obvious passwords will detect if the sha256 hashcode matches. Score! # # That doesn't mean sha256 is insecure. The hackerware didn't deduce anything from the hexadecimals. Weak passwords are insecure. # # Cybersecurity is as much a personal concern as something bigger organizations also focus on, under the heading of risk management. # # On the other hand, if you're too afraid to make a splash, people might miss out on your most excellent contribution. Like in scuba diving, once you well understand the potential dangers (such as strong currents), you're in a position to have a lot of fun as a sports diver. # # Another camper helped us get [the calculator](camper_program.py) going (it keeps changing as we go). We worked on adding features and debugging it together. # # As camp leader, I even [pinged the teachers](https://mail.python.org/archives/list/edu-sig@python.org/thread/H6KKJR57V7G4CIPDPJ7FUCXWDHMRUYUT/) on [Python.org edu-sig](https://mail.python.org/archives/list/edu-sig@python.org/), a mailman list devoted to the topic of Python in education. # # ![sourvenir](./images/camp_mighty_moose.png) # # ![camp 3](./images/git_talk_whiteboard.png) # # Followup [blog post](https://controlroom.blogspot.com/2020/05/summer-school-update-ocn.html) with embedded Youtube, end of May, 2020 # ![Pi Day](https://media.giphy.com/media/5PhE09AKqBPCHt9QL6/giphy.gif)