├── .gitignore ├── Atom-Python └── Test-Project │ └── test-module.py ├── Automation └── rename.py ├── BeautifulSoup ├── scrape.py └── simple.html ├── Closure ├── html_closure.js └── html_closure.py ├── Closures ├── closure.js ├── closure.py └── example.log ├── Combinations-Permutations ├── comb_perm.py └── examples.py ├── Cron-Tasks └── snippets.txt ├── Datetime └── dates.py ├── Decorators ├── decorators.py └── snippets.txt ├── Django_Blog ├── 01-Getting-Started │ └── django_project │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ └── manage.py ├── 02-Application-And-Routes │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ └── manage.py ├── 03-Templates │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ └── manage.py ├── 04-Admin-Page │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ └── manage.py ├── 05-Database-Models │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ └── manage.py ├── 06-User-Registration-Form │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ └── __init__.py │ │ ├── models.py │ │ ├── templates │ │ └── users │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 07-Login-Logout-Authentication │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ └── pic.jpg │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 08-Profile-And-Images │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ └── pic.jpg │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 09-Update-User-Profile │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ └── home.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ ├── large.jpg │ │ │ ├── large_rbSbk8j.jpg │ │ │ └── pic.jpg │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 10-Posts-Create-Update-Delete │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ ├── home.html │ │ │ │ ├── post_confirm_delete.html │ │ │ │ ├── post_detail.html │ │ │ │ └── post_form.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ ├── large.jpg │ │ │ ├── large_rbSbk8j.jpg │ │ │ └── pic.jpg │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 11-Pagination │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ ├── home.html │ │ │ │ ├── post_confirm_delete.html │ │ │ │ ├── post_detail.html │ │ │ │ ├── post_form.html │ │ │ │ └── user_posts.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ ├── large.jpg │ │ │ ├── large_rbSbk8j.jpg │ │ │ └── pic.jpg │ │ ├── posts.json │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py ├── 12-Password-Reset │ └── django_project │ │ ├── blog │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── static │ │ │ └── blog │ │ │ │ └── main.css │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── about.html │ │ │ │ ├── base.html │ │ │ │ ├── home.html │ │ │ │ ├── post_confirm_delete.html │ │ │ │ ├── post_detail.html │ │ │ │ ├── post_form.html │ │ │ │ └── user_posts.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── db.sqlite3 │ │ ├── django_project │ │ ├── __init__.py │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ │ ├── manage.py │ │ ├── media │ │ ├── default.jpg │ │ └── profile_pics │ │ │ ├── large.jpg │ │ │ ├── large_rbSbk8j.jpg │ │ │ └── pic.jpg │ │ ├── posts.json │ │ └── users │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ ├── models.py │ │ ├── signals.py │ │ ├── templates │ │ └── users │ │ │ ├── login.html │ │ │ ├── logout.html │ │ │ ├── password_reset.html │ │ │ ├── password_reset_complete.html │ │ │ ├── password_reset_confirm.html │ │ │ ├── password_reset_done.html │ │ │ ├── profile.html │ │ │ └── register.html │ │ ├── tests.py │ │ └── views.py └── snippets │ ├── add_posts.txt │ ├── article.html │ ├── main.css │ ├── main.html │ ├── navigation.html │ ├── posts.json │ └── profile.html ├── EAFP └── eafp.py ├── Ex-Machina └── ex-machina.py ├── Exceptions ├── currupt_file.txt ├── exceptions.py └── test_file.txt ├── FC_Functions └── fc_functions.py ├── For_Else ├── find.py └── test_while.py ├── Generators ├── mem_profile.py ├── mem_profile.pyc ├── people.py └── square_nums.py ├── Idempotence ├── methods.txt └── test.py ├── List_Comp └── comprehensions.py ├── Logging-Advanced ├── employee.py └── log-sample.py ├── Logging-Basics ├── employee.py ├── log-sample.py └── snippets.txt ├── Memoization └── sample.py ├── Mutable ├── code.py ├── concat.py └── mutable.py ├── NamedTuples ├── code.py └── named_tuples.py ├── Object-Oriented ├── 1-FirstClasses │ └── oop.py ├── 2-Class-Instance-Variables │ └── oop.py ├── 3-Class-Static-Methods │ └── oop.py ├── 4-Inheritance │ ├── oop-finish.py │ └── oop.py ├── 5-SpecialMethods │ └── oop_test.py └── 6-property-decorator │ └── oop.py ├── Python-CSV ├── names.csv ├── new_names.csv └── parse_csv.py ├── Python-Conditionals ├── intro.py └── snippets.txt ├── Python-Context-Managers ├── Sample-Dir-One │ ├── mydoc.txt │ ├── todo.txt │ └── work.txt ├── Sample-Dir-Two │ ├── demo.txt │ ├── sample.txt │ └── test.txt ├── cm_demo.py ├── sample.txt └── snippets.txt ├── Python-Decorator-Arguments ├── decorator-finish.py ├── decorator-start.py └── flask-hello.py ├── Python-Dicts └── intro.py ├── Python-Files ├── Files.py ├── README.txt └── test.txt ├── Python-Functions ├── intro.py └── snippets.txt ├── Python-Future-Date ├── credit.py ├── subs.py └── weight.py ├── Python-Imports ├── intro.py └── my_module.py ├── Python-Ints ├── intro.py └── snippets.txt ├── Python-JSON ├── api.py ├── json_demo.py ├── new_states.json └── states.json ├── Python-Lists ├── intro.py └── snippets.txt ├── Python-Loops └── intro.py ├── Python-Patreon-CSV ├── parse_csv.py └── patrons.csv ├── Python-Random ├── random_data.py └── random_demo.py ├── Python-Regular-Expressions ├── data.txt ├── emails.py ├── simple.py ├── snippets.txt └── urls.py ├── Python-SQLite ├── employee.db ├── employee.py ├── snippets.txt └── sqlite_demo.py ├── Python-Strings └── intro.py ├── Python-Unit-Testing ├── calc.py ├── employee.py ├── snippets.txt ├── test_calc.py └── test_employee.py ├── Python ├── Flask_Blog │ ├── 01-Getting-Started │ │ └── flaskblog.py │ ├── 02-Templates │ │ ├── flaskblog.py │ │ ├── static │ │ │ └── main.css │ │ └── templates │ │ │ ├── about.html │ │ │ ├── home.html │ │ │ └── layout.html │ ├── 03-Forms-and-Validation │ │ ├── flaskblog.py │ │ ├── forms.py │ │ ├── site.db │ │ ├── static │ │ │ └── main.css │ │ └── templates │ │ │ ├── about.html │ │ │ ├── home.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ └── register.html │ ├── 04-Database │ │ ├── flaskblog.py │ │ ├── forms.py │ │ ├── site.db │ │ ├── static │ │ │ └── main.css │ │ └── templates │ │ │ ├── about.html │ │ │ ├── home.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ └── register.html │ ├── 05-Package-Structure │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ └── main.css │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ └── register.html │ │ └── run.py │ ├── 06-Login-Auth │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ └── main.css │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ └── register.html │ │ └── run.py │ ├── 07-User-Account-Profile-Pic │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ └── default.jpg │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ └── register.html │ │ └── run.py │ ├── 08-Posts │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ └── default.jpg │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── create_post.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ ├── post.html │ │ │ │ └── register.html │ │ └── run.py │ ├── 09-Pagination │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ └── default.jpg │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── create_post.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ ├── post.html │ │ │ │ ├── register.html │ │ │ │ └── user_posts.html │ │ ├── posts.json │ │ └── run.py │ ├── 10-Password-Reset-Email │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── forms.py │ │ │ ├── models.py │ │ │ ├── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ └── default.jpg │ │ │ └── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── create_post.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ ├── post.html │ │ │ │ ├── register.html │ │ │ │ ├── reset_request.html │ │ │ │ ├── reset_token.html │ │ │ │ └── user_posts.html │ │ └── run.py │ ├── 11-Blueprints │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── main │ │ │ │ ├── __init__.py │ │ │ │ └── routes.py │ │ │ ├── models.py │ │ │ ├── posts │ │ │ │ ├── __init__.py │ │ │ │ ├── forms.py │ │ │ │ └── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 7ef894751d31a45b.png │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ ├── ddd3ffe2e3271c40.jpg │ │ │ │ │ └── default.jpg │ │ │ ├── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── create_post.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ ├── post.html │ │ │ │ ├── register.html │ │ │ │ ├── reset_request.html │ │ │ │ ├── reset_token.html │ │ │ │ └── user_posts.html │ │ │ └── users │ │ │ │ ├── __init__.py │ │ │ │ ├── forms.py │ │ │ │ ├── routes.py │ │ │ │ └── utils.py │ │ └── run.py │ ├── 12-Error-Pages │ │ ├── flaskblog │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── errors │ │ │ │ ├── __init__.py │ │ │ │ └── handlers.py │ │ │ ├── main │ │ │ │ ├── __init__.py │ │ │ │ └── routes.py │ │ │ ├── models.py │ │ │ ├── posts │ │ │ │ ├── __init__.py │ │ │ │ ├── forms.py │ │ │ │ └── routes.py │ │ │ ├── site.db │ │ │ ├── static │ │ │ │ ├── main.css │ │ │ │ └── profile_pics │ │ │ │ │ ├── 2e32b4c96a8d8f10.jpg │ │ │ │ │ ├── 7798432669b8b3ac.jpg │ │ │ │ │ ├── 7ef894751d31a45b.png │ │ │ │ │ ├── 85ed1b444539873d.png │ │ │ │ │ ├── b6e1c53325f88b74.png │ │ │ │ │ ├── ddd3ffe2e3271c40.jpg │ │ │ │ │ └── default.jpg │ │ │ ├── templates │ │ │ │ ├── about.html │ │ │ │ ├── account.html │ │ │ │ ├── create_post.html │ │ │ │ ├── errors │ │ │ │ │ ├── 403.html │ │ │ │ │ ├── 404.html │ │ │ │ │ └── 500.html │ │ │ │ ├── home.html │ │ │ │ ├── layout.html │ │ │ │ ├── login.html │ │ │ │ ├── post.html │ │ │ │ ├── register.html │ │ │ │ ├── reset_request.html │ │ │ │ ├── reset_token.html │ │ │ │ └── user_posts.html │ │ │ └── users │ │ │ │ ├── __init__.py │ │ │ │ ├── forms.py │ │ │ │ ├── routes.py │ │ │ │ └── utils.py │ │ └── run.py │ ├── quickstart-windows.bat │ └── snippets │ │ ├── account.html │ │ ├── article.html │ │ ├── blueprint_imports.txt │ │ ├── main.css │ │ ├── main.html │ │ ├── navigation.html │ │ └── posts.json ├── Python-Environment-Variables │ └── env_vars.py └── Python-Sets │ ├── sets.py │ └── snippets.txt ├── README.md ├── Regular-Expressions ├── data.txt ├── emails.txt ├── simple.txt ├── snippets.txt └── urls.txt ├── Scope └── scope.py ├── Slicing └── slicing.py ├── Starting_Code ├── calc.py └── employee.py ├── Str_Repr ├── test.py └── test2.py ├── String Interpolation └── test.py ├── String-Formatting └── formatting.py ├── Terminal └── Grep │ ├── Personel │ ├── emails.txt │ └── phone_numbers.txt │ ├── grep-commands.txt │ ├── memo.txt │ └── names.txt ├── conda_auto_env.sh ├── mem_profile.py ├── mem_profile_old.py └── random_data.py /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | __pycache__/ 3 | *.pyc 4 | 5 | # Video Scripts 6 | s.txt 7 | script.txt 8 | -------------------------------------------------------------------------------- /Atom-Python/Test-Project/test-module.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | """A sample Employee class""" 4 | 5 | def __init__(self, first, last): 6 | self.first = first 7 | self.last = last 8 | 9 | print('Created Employee: {} - {}'.format(self.fullname, self.email)) 10 | 11 | @property 12 | def email(self): 13 | return '{}.{}@email.com'.format(self.first, self.last) 14 | 15 | @property 16 | def fullname(self): 17 | return '{} {}'.format(self.first, self.last) 18 | 19 | 20 | emp_1 = Employee('John', 'Smith') 21 | -------------------------------------------------------------------------------- /Closure/html_closure.js: -------------------------------------------------------------------------------- 1 | function html_tag(tag) { 2 | function print_tag(text) { 3 | return '<'+tag+'>'+text+'' 4 | }; 5 | return print_tag 6 | }; 7 | 8 | h1_tag = html_tag('h1') 9 | 10 | console.log(h1_tag('This is a Headline!')) -------------------------------------------------------------------------------- /Closure/html_closure.py: -------------------------------------------------------------------------------- 1 | def outer(): 2 | x = 10 3 | def inner(): 4 | y = 20 5 | inner() 6 | return x + y 7 | 8 | my_func = outer 9 | 10 | print my_func() 11 | 12 | # h1_tag = html_tag('h1') 13 | # print h1_tag 14 | 15 | # def html_tag(tag): 16 | # def print_tag(text): 17 | # return '<{0}>{1}'.format(tag,text) 18 | # return print_tag 19 | 20 | # h1_tag = html_tag('h1') 21 | # print h1_tag('This is a headline!') 22 | -------------------------------------------------------------------------------- /Closures/closure.js: -------------------------------------------------------------------------------- 1 | 2 | function html_tag(tag){ 3 | function wrap_text(msg){ 4 | console.log('<' + tag +'>' + msg + '') 5 | } 6 | return wrap_text 7 | } 8 | 9 | print_h1 = html_tag('h1') 10 | 11 | print_h1('Test Headline!') 12 | print_h1('Another Headline!') 13 | 14 | 15 | print_p = html_tag('p') 16 | print_p('Test Paragraph!') -------------------------------------------------------------------------------- /Closures/closure.py: -------------------------------------------------------------------------------- 1 | 2 | # Closures 3 | 4 | import logging 5 | logging.basicConfig(filename='example.log', level=logging.INFO) 6 | 7 | 8 | def logger(func): 9 | def log_func(*args): 10 | logging.info( 11 | 'Running "{}" with arguments {}'.format(func.__name__, args)) 12 | print(func(*args)) 13 | return log_func 14 | 15 | 16 | def add(x, y): 17 | return x+y 18 | 19 | 20 | def sub(x, y): 21 | return x-y 22 | 23 | add_logger = logger(add) 24 | sub_logger = logger(sub) 25 | 26 | add_logger(3, 3) 27 | add_logger(4, 5) 28 | 29 | sub_logger(10, 5) 30 | sub_logger(20, 10) 31 | -------------------------------------------------------------------------------- /Closures/example.log: -------------------------------------------------------------------------------- 1 | INFO:root:Running "add" with arguments (3, 3) 2 | INFO:root:Running "add" with arguments (4, 5) 3 | INFO:root:Running "sub" with arguments (10, 5) 4 | INFO:root:Running "sub" with arguments (20, 10) 5 | -------------------------------------------------------------------------------- /Combinations-Permutations/comb_perm.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | my_list = [1,2,3] 4 | 5 | # combinations = itertools.combinations(my_list, 2) 6 | # for c in combinations: 7 | # print c 8 | 9 | permutations = itertools.permutations(my_list, 2) 10 | for p in permutations: 11 | print p -------------------------------------------------------------------------------- /Combinations-Permutations/examples.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | # my_list = [1,2,3,4,5,6] 4 | 5 | # combinations = itertools.combinations(my_list, 3) 6 | # permutations = itertools.permutations(my_list, 3) 7 | 8 | # print [result for result in combinations if sum(result) == 10] 9 | 10 | word = 'sample' 11 | my_letters = 'plmeas' 12 | 13 | combinations = itertools.combinations(my_letters, 6) 14 | permutations = itertools.permutations(my_letters, 6) 15 | 16 | for p in permutations: 17 | # print p 18 | if ''.join(p) == word: 19 | print 'Match!' 20 | break 21 | else: 22 | print 'No Match!' -------------------------------------------------------------------------------- /Cron-Tasks/snippets.txt: -------------------------------------------------------------------------------- 1 | # ┌───────────── minute (0 - 59) 2 | # │ ┌───────────── hour (0 - 23) 3 | # │ │ ┌───────────── day of month (1 - 31) 4 | # │ │ │ ┌───────────── month (1 - 12) 5 | # │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday; 6 | # │ │ │ │ │ 7 is also Sunday on some systems) 7 | # │ │ │ │ │ 8 | # │ │ │ │ │ 9 | # * * * * * command_to_execute 10 | 11 | 12 | 13 | ###### Sample crontab ###### 14 | 15 | # Empty temp folder every Friday at 5pm 16 | 0 5 * * 5 rm -rf /tmp/* 17 | 18 | # Backup images to Google Drive every night at midnight 19 | 0 0 * * * rsync -a ~/Pictures/ ~/Google\ Drive/Pictures/ 20 | -------------------------------------------------------------------------------- /Django_Blog/01-Getting-Started/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/01-Getting-Started/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/01-Getting-Started/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/01-Getting-Started/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/01-Getting-Started/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/01-Getting-Started/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/02-Application-And-Routes/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/02-Application-And-Routes/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.http import HttpResponse 3 | 4 | 5 | def home(request): 6 | return HttpResponse('

Blog Home

') 7 | 8 | 9 | def about(request): 10 | return HttpResponse('

Blog About

') 11 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/02-Application-And-Routes/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/02-Application-And-Routes/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/02-Application-And-Routes/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/03-Templates/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/03-Templates/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | posts = [ 4 | { 5 | 'author': 'CoreyMS', 6 | 'title': 'Blog Post 1', 7 | 'content': 'First post content', 8 | 'date_posted': 'August 27, 2018' 9 | }, 10 | { 11 | 'author': 'Jane Doe', 12 | 'title': 'Blog Post 2', 13 | 'content': 'Second post content', 14 | 'date_posted': 'August 28, 2018' 15 | } 16 | ] 17 | 18 | 19 | def home(request): 20 | context = { 21 | 'posts': posts 22 | } 23 | return render(request, 'blog/home.html', context) 24 | 25 | 26 | def about(request): 27 | return render(request, 'blog/about.html', {'title': 'About'}) 28 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/03-Templates/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/03-Templates/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/03-Templates/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/04-Admin-Page/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/04-Admin-Page/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | posts = [ 4 | { 5 | 'author': 'CoreyMS', 6 | 'title': 'Blog Post 1', 7 | 'content': 'First post content', 8 | 'date_posted': 'August 27, 2018' 9 | }, 10 | { 11 | 'author': 'Jane Doe', 12 | 'title': 'Blog Post 2', 13 | 'content': 'Second post content', 14 | 'date_posted': 'August 28, 2018' 15 | } 16 | ] 17 | 18 | 19 | def home(request): 20 | context = { 21 | 'posts': posts 22 | } 23 | return render(request, 'blog/home.html', context) 24 | 25 | 26 | def about(request): 27 | return render(request, 'blog/about.html', {'title': 'About'}) 28 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/04-Admin-Page/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/04-Admin-Page/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/04-Admin-Page/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/05-Database-Models/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/05-Database-Models/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | 5 | 6 | class Post(models.Model): 7 | title = models.CharField(max_length=100) 8 | content = models.TextField() 9 | date_posted = models.DateTimeField(default=timezone.now) 10 | author = models.ForeignKey(User, on_delete=models.CASCADE) 11 | 12 | def __str__(self): 13 | return self.title 14 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Post 3 | 4 | 5 | def home(request): 6 | context = { 7 | 'posts': Post.objects.all() 8 | } 9 | return render(request, 'blog/home.html', context) 10 | 11 | 12 | def about(request): 13 | return render(request, 'blog/about.html', {'title': 'About'}) 14 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/05-Database-Models/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/05-Database-Models/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/05-Database-Models/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | 5 | 6 | class Post(models.Model): 7 | title = models.CharField(max_length=100) 8 | content = models.TextField() 9 | date_posted = models.DateTimeField(default=timezone.now) 10 | author = models.ForeignKey(User, on_delete=models.CASCADE) 11 | 12 | def __str__(self): 13 | return self.title 14 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Post 3 | 4 | 5 | def home(request): 6 | context = { 7 | 'posts': Post.objects.all() 8 | } 9 | return render(request, 'blog/home.html', context) 10 | 11 | 12 | def about(request): 13 | return render(request, 'blog/about.html', {'title': 'About'}) 14 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | 5 | 6 | class UserRegisterForm(UserCreationForm): 7 | email = forms.EmailField() 8 | 9 | class Meta: 10 | model = User 11 | fields = ['username', 'email', 'password1', 'password2'] 12 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/06-User-Registration-Form/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/templates/users/register.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Join Today 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Already Have An Account? Sign In 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/06-User-Registration-Form/django_project/users/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.contrib import messages 3 | from .forms import UserRegisterForm 4 | 5 | 6 | def register(request): 7 | if request.method == 'POST': 8 | form = UserRegisterForm(request.POST) 9 | if form.is_valid(): 10 | form.save() 11 | username = form.cleaned_data.get('username') 12 | messages.success(request, f'Account created for {username}!') 13 | return redirect('blog-home') 14 | else: 15 | form = UserRegisterForm() 16 | return render(request, 'users/register.html', {'form': form}) 17 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | 5 | 6 | class Post(models.Model): 7 | title = models.CharField(max_length=100) 8 | content = models.TextField() 9 | date_posted = models.DateTimeField(default=timezone.now) 10 | author = models.ForeignKey(User, on_delete=models.CASCADE) 11 | 12 | def __str__(self): 13 | return self.title 14 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Post 3 | 4 | 5 | def home(request): 6 | context = { 7 | 'posts': Post.objects.all() 8 | } 9 | return render(request, 'blog/home.html', context) 10 | 11 | 12 | def about(request): 13 | return render(request, 'blog/about.html', {'title': 'About'}) 14 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | 5 | 6 | class UserRegisterForm(UserCreationForm): 7 | email = forms.EmailField() 8 | 9 | class Meta: 10 | model = User 11 | fields = ['username', 'email', 'password1', 'password2'] 12 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/07-Login-Logout-Authentication/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | 4 | 5 | class Profile(models.Model): 6 | user = models.OneToOneField(User, on_delete=models.CASCADE) 7 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 8 | 9 | def __str__(self): 10 | return f'{self.user.username} Profile' 11 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/templates/users/profile.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | 7 |
8 | 9 |

{{ user.email }}

10 |
11 |
12 | 13 |
14 | {% endblock content %} 15 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/07-Login-Logout-Authentication/django_project/users/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.contrib import messages 3 | from django.contrib.auth.decorators import login_required 4 | from .forms import UserRegisterForm 5 | 6 | 7 | def register(request): 8 | if request.method == 'POST': 9 | form = UserRegisterForm(request.POST) 10 | if form.is_valid(): 11 | form.save() 12 | username = form.cleaned_data.get('username') 13 | messages.success(request, f'Your account has been created! You are now able to log in') 14 | return redirect('login') 15 | else: 16 | form = UserRegisterForm() 17 | return render(request, 'users/register.html', {'form': form}) 18 | 19 | 20 | @login_required 21 | def profile(request): 22 | return render(request, 'users/profile.html') 23 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | 5 | 6 | class Post(models.Model): 7 | title = models.CharField(max_length=100) 8 | content = models.TextField() 9 | date_posted = models.DateTimeField(default=timezone.now) 10 | author = models.ForeignKey(User, on_delete=models.CASCADE) 11 | 12 | def __str__(self): 13 | return self.title 14 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 |
6 | 10 |

{{ post.title }}

11 |

{{ post.content }}

12 |
13 |
14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Post 3 | 4 | 5 | def home(request): 6 | context = { 7 | 'posts': Post.objects.all() 8 | } 9 | return render(request, 'blog/home.html', context) 10 | 11 | 12 | def about(request): 13 | return render(request, 'blog/about.html', {'title': 'About'}) 14 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | 5 | 6 | class UserRegisterForm(UserCreationForm): 7 | email = forms.EmailField() 8 | 9 | class Meta: 10 | model = User 11 | fields = ['username', 'email', 'password1', 'password2'] 12 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/08-Profile-And-Images/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | 4 | 5 | class Profile(models.Model): 6 | user = models.OneToOneField(User, on_delete=models.CASCADE) 7 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 8 | 9 | def __str__(self): 10 | return f'{self.user.username} Profile' 11 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/templates/users/login.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Log In 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Need An Account? Sign Up Now 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/templates/users/profile.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | 7 |
8 | 9 |

{{ user.email }}

10 |
11 |
12 | 13 |
14 | {% endblock content %} 15 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/08-Profile-And-Images/django_project/users/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.contrib import messages 3 | from django.contrib.auth.decorators import login_required 4 | from .forms import UserRegisterForm 5 | 6 | 7 | def register(request): 8 | if request.method == 'POST': 9 | form = UserRegisterForm(request.POST) 10 | if form.is_valid(): 11 | form.save() 12 | username = form.cleaned_data.get('username') 13 | messages.success(request, f'Your account has been created! You are now able to log in') 14 | return redirect('login') 15 | else: 16 | form = UserRegisterForm() 17 | return render(request, 'users/register.html', {'form': form}) 18 | 19 | 20 | @login_required 21 | def profile(request): 22 | return render(request, 'users/profile.html') 23 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | 5 | 6 | class Post(models.Model): 7 | title = models.CharField(max_length=100) 8 | content = models.TextField() 9 | date_posted = models.DateTimeField(default=timezone.now) 10 | author = models.ForeignKey(User, on_delete=models.CASCADE) 11 | 12 | def __str__(self): 13 | return self.title 14 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 | 6 |
7 | 11 |

{{ post.title }}

12 |

{{ post.content }}

13 |
14 |
15 | {% endfor %} 16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name='blog-home'), 6 | path('about/', views.about, name='blog-about'), 7 | ] 8 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Post 3 | 4 | 5 | def home(request): 6 | context = { 7 | 'posts': Post.objects.all() 8 | } 9 | return render(request, 'blog/home.html', context) 10 | 11 | 12 | def about(request): 13 | return render(request, 'blog/about.html', {'title': 'About'}) 14 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/large.jpg -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/large_rbSbk8j.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/large_rbSbk8j.jpg -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | from .models import Profile 5 | 6 | 7 | class UserRegisterForm(UserCreationForm): 8 | email = forms.EmailField() 9 | 10 | class Meta: 11 | model = User 12 | fields = ['username', 'email', 'password1', 'password2'] 13 | 14 | 15 | class UserUpdateForm(forms.ModelForm): 16 | email = forms.EmailField() 17 | 18 | class Meta: 19 | model = User 20 | fields = ['username', 'email'] 21 | 22 | 23 | class ProfileUpdateForm(forms.ModelForm): 24 | class Meta: 25 | model = Profile 26 | fields = ['image'] 27 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/09-Update-User-Profile/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from PIL import Image 4 | 5 | 6 | class Profile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 9 | 10 | def __str__(self): 11 | return f'{self.user.username} Profile' 12 | 13 | def save(self): 14 | super().save() 15 | 16 | img = Image.open(self.image.path) 17 | 18 | if img.height > 300 or img.width > 300: 19 | output_size = (300, 300) 20 | img.thumbnail(output_size) 21 | img.save(self.image.path) 22 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/templates/users/login.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Log In 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Need An Account? Sign Up Now 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/09-Update-User-Profile/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | from django.urls import reverse 5 | 6 | 7 | class Post(models.Model): 8 | title = models.CharField(max_length=100) 9 | content = models.TextField() 10 | date_posted = models.DateTimeField(default=timezone.now) 11 | author = models.ForeignKey(User, on_delete=models.CASCADE) 12 | 13 | def __str__(self): 14 | return self.title 15 | 16 | def get_absolute_url(self): 17 | return reverse('post-detail', kwargs={'pk': self.pk}) 18 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/templates/blog/home.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 |
5 | 6 |
7 | 11 |

{{ post.title }}

12 |

{{ post.content }}

13 |
14 |
15 | {% endfor %} 16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/templates/blog/post_confirm_delete.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 |
5 | {% csrf_token %} 6 |
7 | Delete Post 8 |

Are you sure you want to delete the post "{{ object.title }}"

9 |
10 |
11 | 12 | Cancel 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/templates/blog/post_form.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Blog Post 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from .views import ( 3 | PostListView, 4 | PostDetailView, 5 | PostCreateView, 6 | PostUpdateView, 7 | PostDeleteView 8 | ) 9 | from . import views 10 | 11 | urlpatterns = [ 12 | path('', PostListView.as_view(), name='blog-home'), 13 | path('post//', PostDetailView.as_view(), name='post-detail'), 14 | path('post/new/', PostCreateView.as_view(), name='post-create'), 15 | path('post//update/', PostUpdateView.as_view(), name='post-update'), 16 | path('post//delete/', PostDeleteView.as_view(), name='post-delete'), 17 | path('about/', views.about, name='blog-about'), 18 | ] 19 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/large.jpg -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/large_rbSbk8j.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/large_rbSbk8j.jpg -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | from .models import Profile 5 | 6 | 7 | class UserRegisterForm(UserCreationForm): 8 | email = forms.EmailField() 9 | 10 | class Meta: 11 | model = User 12 | fields = ['username', 'email', 'password1', 'password2'] 13 | 14 | 15 | class UserUpdateForm(forms.ModelForm): 16 | email = forms.EmailField() 17 | 18 | class Meta: 19 | model = User 20 | fields = ['username', 'email'] 21 | 22 | 23 | class ProfileUpdateForm(forms.ModelForm): 24 | class Meta: 25 | model = Profile 26 | fields = ['image'] 27 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/10-Posts-Create-Update-Delete/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from PIL import Image 4 | 5 | 6 | class Profile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 9 | 10 | def __str__(self): 11 | return f'{self.user.username} Profile' 12 | 13 | def save(self): 14 | super().save() 15 | 16 | img = Image.open(self.image.path) 17 | 18 | if img.height > 300 or img.width > 300: 19 | output_size = (300, 300) 20 | img.thumbnail(output_size) 21 | img.save(self.image.path) 22 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/templates/users/login.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Log In 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Need An Account? Sign Up Now 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/10-Posts-Create-Update-Delete/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | from django.urls import reverse 5 | 6 | 7 | class Post(models.Model): 8 | title = models.CharField(max_length=100) 9 | content = models.TextField() 10 | date_posted = models.DateTimeField(default=timezone.now) 11 | author = models.ForeignKey(User, on_delete=models.CASCADE) 12 | 13 | def __str__(self): 14 | return self.title 15 | 16 | def get_absolute_url(self): 17 | return reverse('post-detail', kwargs={'pk': self.pk}) 18 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/templates/blog/post_confirm_delete.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 |
5 | {% csrf_token %} 6 |
7 | Delete Post 8 |

Are you sure you want to delete the post "{{ object.title }}"

9 |
10 |
11 | 12 | Cancel 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/templates/blog/post_form.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Blog Post 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from .views import ( 3 | PostListView, 4 | PostDetailView, 5 | PostCreateView, 6 | PostUpdateView, 7 | PostDeleteView, 8 | UserPostListView 9 | ) 10 | from . import views 11 | 12 | urlpatterns = [ 13 | path('', PostListView.as_view(), name='blog-home'), 14 | path('user/', UserPostListView.as_view(), name='user-posts'), 15 | path('post//', PostDetailView.as_view(), name='post-detail'), 16 | path('post/new/', PostCreateView.as_view(), name='post-create'), 17 | path('post//update/', PostUpdateView.as_view(), name='post-update'), 18 | path('post//delete/', PostDeleteView.as_view(), name='post-delete'), 19 | path('about/', views.about, name='blog-about'), 20 | ] 21 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/media/profile_pics/large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/media/profile_pics/large.jpg -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/media/profile_pics/large_rbSbk8j.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/media/profile_pics/large_rbSbk8j.jpg -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | from .models import Profile 5 | 6 | 7 | class UserRegisterForm(UserCreationForm): 8 | email = forms.EmailField() 9 | 10 | class Meta: 11 | model = User 12 | fields = ['username', 'email', 'password1', 'password2'] 13 | 14 | 15 | class UserUpdateForm(forms.ModelForm): 16 | email = forms.EmailField() 17 | 18 | class Meta: 19 | model = User 20 | fields = ['username', 'email'] 21 | 22 | 23 | class ProfileUpdateForm(forms.ModelForm): 24 | class Meta: 25 | model = Profile 26 | fields = ['image'] 27 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/11-Pagination/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from PIL import Image 4 | 5 | 6 | class Profile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 9 | 10 | def __str__(self): 11 | return f'{self.user.username} Profile' 12 | 13 | def save(self): 14 | super().save() 15 | 16 | img = Image.open(self.image.path) 17 | 18 | if img.height > 300 or img.width > 300: 19 | output_size = (300, 300) 20 | img.thumbnail(output_size) 21 | img.save(self.image.path) 22 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/templates/users/login.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Log In 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Need An Account? Sign Up Now 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/templates/users/register.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Join Today 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Already Have An Account? Sign In 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/11-Pagination/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/blog/__init__.py -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) 5 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/blog/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | from django.contrib.auth.models import User 4 | from django.urls import reverse 5 | 6 | 7 | class Post(models.Model): 8 | title = models.CharField(max_length=100) 9 | content = models.TextField() 10 | date_posted = models.DateTimeField(default=timezone.now) 11 | author = models.ForeignKey(User, on_delete=models.CASCADE) 12 | 13 | def __str__(self): 14 | return self.title 15 | 16 | def get_absolute_url(self): 17 | return reverse('post-detail', kwargs={'pk': self.pk}) 18 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/templates/blog/about.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/templates/blog/post_confirm_delete.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 |
5 | {% csrf_token %} 6 |
7 | Delete Post 8 |

Are you sure you want to delete the post "{{ object.title }}"

9 |
10 |
11 | 12 | Cancel 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/templates/blog/post_form.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Blog Post 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from .views import ( 3 | PostListView, 4 | PostDetailView, 5 | PostCreateView, 6 | PostUpdateView, 7 | PostDeleteView, 8 | UserPostListView 9 | ) 10 | from . import views 11 | 12 | urlpatterns = [ 13 | path('', PostListView.as_view(), name='blog-home'), 14 | path('user/', UserPostListView.as_view(), name='user-posts'), 15 | path('post//', PostDetailView.as_view(), name='post-detail'), 16 | path('post/new/', PostCreateView.as_view(), name='post-create'), 17 | path('post//update/', PostUpdateView.as_view(), name='post-update'), 18 | path('post//delete/', PostDeleteView.as_view(), name='post-delete'), 19 | path('about/', views.about, name='blog-about'), 20 | ] 21 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/db.sqlite3 -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/django_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/django_project/__init__.py -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/django_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/media/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/media/default.jpg -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/media/profile_pics/large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/media/profile_pics/large.jpg -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/media/profile_pics/large_rbSbk8j.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/media/profile_pics/large_rbSbk8j.jpg -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/media/profile_pics/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/media/profile_pics/pic.jpg -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/users/__init__.py -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Profile 3 | 4 | admin.site.register(Profile) 5 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'users' 6 | 7 | def ready(self): 8 | import users.signals 9 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | from .models import Profile 5 | 6 | 7 | class UserRegisterForm(UserCreationForm): 8 | email = forms.EmailField() 9 | 10 | class Meta: 11 | model = User 12 | fields = ['username', 'email', 'password1', 'password2'] 13 | 14 | 15 | class UserUpdateForm(forms.ModelForm): 16 | email = forms.EmailField() 17 | 18 | class Meta: 19 | model = User 20 | fields = ['username', 'email'] 21 | 22 | 23 | class ProfileUpdateForm(forms.ModelForm): 24 | class Meta: 25 | model = Profile 26 | fields = ['image'] 27 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Django_Blog/12-Password-Reset/django_project/users/migrations/__init__.py -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from PIL import Image 4 | 5 | 6 | class Profile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | image = models.ImageField(default='default.jpg', upload_to='profile_pics') 9 | 10 | def __str__(self): 11 | return f'{self.user.username} Profile' 12 | 13 | def save(self): 14 | super().save() 15 | 16 | img = Image.open(self.image.path) 17 | 18 | if img.height > 300 or img.width > 300: 19 | output_size = (300, 300) 20 | img.thumbnail(output_size) 21 | img.save(self.image.path) 22 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User 3 | from django.dispatch import receiver 4 | from .models import Profile 5 | 6 | 7 | @receiver(post_save, sender=User) 8 | def create_profile(sender, instance, created, **kwargs): 9 | if created: 10 | Profile.objects.create(user=instance) 11 | 12 | 13 | @receiver(post_save, sender=User) 14 | def save_profile(sender, instance, **kwargs): 15 | instance.profile.save() 16 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/logout.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |

You have been logged out

4 |
5 | 6 | Log In Again 7 | 8 |
9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/password_reset.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Reset Password 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/password_reset_complete.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 | Your password has been set. 5 |
6 | Sign In Here 7 | {% endblock content %} 8 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/password_reset_confirm.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Reset Password 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/password_reset_done.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% block content %} 3 |
4 | An email has been sent with instructions to reset your password 5 |
6 | {% endblock content %} 7 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/templates/users/register.html: -------------------------------------------------------------------------------- 1 | {% extends "blog/base.html" %} 2 | {% load crispy_forms_tags %} 3 | {% block content %} 4 |
5 |
6 | {% csrf_token %} 7 |
8 | Join Today 9 | {{ form|crispy }} 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | Already Have An Account? Sign In 18 | 19 |
20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /Django_Blog/12-Password-Reset/django_project/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Django_Blog/snippets/add_posts.txt: -------------------------------------------------------------------------------- 1 | 2 | # Run Django shell (python manage.py shell) and then run the following commands... 3 | 4 | >>> import json 5 | >>> from blog.models import Post 6 | >>> with open('posts.json') as f: 7 | ... post_json = json.load(f) 8 | ... 9 | >>> for post in post_json: 10 | ... post = Post(title=post['title'], content=post['content'], author_id=post['user_id']) 11 | ... post.save() 12 | ... 13 | >>> exit() 14 | 15 | -------------------------------------------------------------------------------- /Django_Blog/snippets/article.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Django_Blog/snippets/main.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | {% block content %}{% endblock %} 5 |
6 |
7 |
8 |

Our Sidebar

9 |

You can put any information here you'd like. 10 |

    11 |
  • Latest Posts
  • 12 |
  • Announcements
  • 13 |
  • Calendars
  • 14 |
  • etc
  • 15 |
16 |

17 |
18 |
19 |
20 |
21 | -------------------------------------------------------------------------------- /Django_Blog/snippets/profile.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |

username@email.com

7 |
8 |
9 | 10 |
11 | -------------------------------------------------------------------------------- /Ex-Machina/ex-machina.py: -------------------------------------------------------------------------------- 1 | #BlueBook code decryption 2 | import sys 3 | def sieve(n): 4 | x = [1] * n 5 | x[1] = 0 6 | for i in range(2,n/2): 7 | j = 2 * i 8 | while j < n: 9 | x[j]=0 10 | j = j+i 11 | return x 12 | 13 | def prime(n,x): 14 | i = 1 15 | j = 1 16 | while j <= n: 17 | if x[i] == 1: 18 | j = j + 1 19 | i = i + 1 20 | return i - 1 21 | x=sieve(10000) 22 | code = [1206,301,384,5] 23 | key =[1,1,2,2,] 24 | 25 | sys.stdout.write("".join(chr(i) for i in [73,83,66,78,32,61,32])) 26 | for i in range (0,4): 27 | sys.stdout.write(str(prime(code[i],x)-key[i])) 28 | 29 | print -------------------------------------------------------------------------------- /Exceptions/currupt_file.txt: -------------------------------------------------------------------------------- 1 | Currupt File! -------------------------------------------------------------------------------- /Exceptions/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | f = open('curruptfile.txt') 4 | # if f.name == 'currupt_file.txt': 5 | # raise Exception 6 | except IOError as e: 7 | print('First!') 8 | except Exception as e: 9 | print('Second') 10 | else: 11 | print(f.read()) 12 | f.close() 13 | finally: 14 | print("Executing Finally...") 15 | 16 | print('End of program') 17 | -------------------------------------------------------------------------------- /Exceptions/test_file.txt: -------------------------------------------------------------------------------- 1 | Test File Contents! -------------------------------------------------------------------------------- /FC_Functions/fc_functions.py: -------------------------------------------------------------------------------- 1 | 2 | def html_tag(tag): 3 | 4 | def wrap_text(msg): 5 | print('<{0}>{1}'.format(tag, msg)) 6 | 7 | return wrap_text 8 | 9 | print_h1 = html_tag('h1') 10 | print_h1('Test Headline!') 11 | print_h1('Another Headline!') 12 | 13 | print_p = html_tag('p') 14 | print_p('Test Paragraph!') 15 | -------------------------------------------------------------------------------- /For_Else/find.py: -------------------------------------------------------------------------------- 1 | 2 | def find_index(to_search, target): 3 | for i, value in enumerate(to_search): 4 | if value == target: 5 | break 6 | else: 7 | return -1 8 | return i 9 | 10 | 11 | my_list = ['Corey', 'Rick', 'John'] 12 | index_location = find_index(my_list, 'Steve') 13 | 14 | print 'Location of target is index: {}'.format(index_location) -------------------------------------------------------------------------------- /For_Else/test_while.py: -------------------------------------------------------------------------------- 1 | 2 | i = 1 3 | while i <= 5: 4 | print i 5 | i += 1 6 | if i == 3: 7 | break 8 | else: 9 | print 'Hit the While/Else Statement!' -------------------------------------------------------------------------------- /Generators/mem_profile.py: -------------------------------------------------------------------------------- 1 | from pympler import summary, muppy 2 | import psutil 3 | import resource 4 | import os 5 | import sys 6 | 7 | def memory_usage_psutil(): 8 | # return the memory usage in MB 9 | process = psutil.Process(os.getpid()) 10 | mem = process.get_memory_info()[0] / float(2 ** 20) 11 | return mem 12 | 13 | def memory_usage_resource(): 14 | rusage_denom = 1024. 15 | if sys.platform == 'darwin': 16 | # ... it seems that in OSX the output is different units ... 17 | rusage_denom = rusage_denom * rusage_denom 18 | mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom 19 | return mem 20 | -------------------------------------------------------------------------------- /Generators/mem_profile.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Generators/mem_profile.pyc -------------------------------------------------------------------------------- /Generators/square_nums.py: -------------------------------------------------------------------------------- 1 | 2 | # def square_numbers(nums): 3 | # for i in nums: 4 | # yield (i*i) 5 | 6 | # my_nums = square_numbers([1,2,3,4,5]) 7 | 8 | my_nums = (x*x for x in [1,2,3,4,5]) 9 | 10 | print list(my_nums) # [1, 4, 9, 16, 25] 11 | 12 | # for num in my_nums: 13 | # print num -------------------------------------------------------------------------------- /Idempotence/methods.txt: -------------------------------------------------------------------------------- 1 | HTTP METHODS 2 | 3 | GET /users/123 4 | PUT 5 | POST 6 | DELETE -------------------------------------------------------------------------------- /Idempotence/test.py: -------------------------------------------------------------------------------- 1 | # f(x) 2 | # add_ten(num) 3 | def add_ten(num): 4 | return num + 10 5 | 6 | # f(f(x)) = f(x) 7 | # f(f(10)) = 30 | f(10) = 20 8 | # print add_ten(add_ten(10)) 9 | 10 | print abs(abs(abs(-10))) 11 | # abs(-10) == 10 12 | # abs(10) == 10 13 | # abs(10) == 10 14 | 15 | a = 10 -------------------------------------------------------------------------------- /Logging-Basics/employee.py: -------------------------------------------------------------------------------- 1 | 2 | import logging 3 | 4 | logging.basicConfig(filename='employee.log', level=logging.INFO, 5 | format='%(levelname)s:%(message)s') 6 | 7 | 8 | class Employee: 9 | """A sample Employee class""" 10 | 11 | def __init__(self, first, last): 12 | self.first = first 13 | self.last = last 14 | 15 | logging.info('Created Employee: {} - {}'.format(self.fullname, self.email)) 16 | 17 | @property 18 | def email(self): 19 | return '{}.{}@email.com'.format(self.first, self.last) 20 | 21 | @property 22 | def fullname(self): 23 | return '{} {}'.format(self.first, self.last) 24 | 25 | 26 | emp_1 = Employee('John', 'Smith') 27 | emp_2 = Employee('Corey', 'Schafer') 28 | emp_3 = Employee('Jane', 'Doe') 29 | -------------------------------------------------------------------------------- /Logging-Basics/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | # DEBUG: Detailed information, typically of interest only when diagnosing problems. 3 | 4 | # INFO: Confirmation that things are working as expected. 5 | 6 | # WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected. 7 | 8 | # ERROR: Due to a more serious problem, the software has not been able to perform some function. 9 | 10 | # CRITICAL: A serious error, indicating that the program itself may be unable to continue running. 11 | -------------------------------------------------------------------------------- /Memoization/sample.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | ef_cache = {} 4 | 5 | def expensive_func(num): 6 | if num in ef_cache: 7 | return ef_cache[num] 8 | 9 | print "Computing {}...".format(num) 10 | time.sleep(1) 11 | result = num*num 12 | ef_cache[num] = result 13 | return result 14 | 15 | result = expensive_func(4) 16 | print result 17 | 18 | result = expensive_func(10) 19 | print result 20 | 21 | result = expensive_func(4) 22 | print result 23 | 24 | result = expensive_func(10) 25 | print result -------------------------------------------------------------------------------- /Mutable/code.py: -------------------------------------------------------------------------------- 1 | 2 | print 'Address of a is: {}'.format(id(a)) 3 | 4 | # a[0] = '' 5 | # print a 6 | # print 'Address of a is: {}'.format(id(a)) -------------------------------------------------------------------------------- /Mutable/concat.py: -------------------------------------------------------------------------------- 1 | 2 | employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam'] 3 | 4 | output = '
    \n' 5 | 6 | for employee in employees: 7 | output += '\t
  • {}
  • \n'.format(employee) 8 | print 'Address of output is {}'.format(id(output)) 9 | 10 | output += '
' 11 | 12 | print output 13 | 14 | print '\n' -------------------------------------------------------------------------------- /Mutable/mutable.py: -------------------------------------------------------------------------------- 1 | 2 | a = [1,2,3,4,5] 3 | print a 4 | print 'Address of a is: {}'.format(id(a)) 5 | 6 | a[0] = 6 7 | print a 8 | print 'Address of a is: {}'.format(id(a)) -------------------------------------------------------------------------------- /NamedTuples/code.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | # list / tuple 4 | color = (55,155,255) 5 | 6 | # dictionary 7 | color = {'red': 55, 'green': 155, 'blue': 255} 8 | 9 | # namedtuple 10 | Color = namedtuple('Color', ['red', 'green', 'blue']) 11 | color = Color(blue=55,green=155,red=255) 12 | 13 | -------------------------------------------------------------------------------- /NamedTuples/named_tuples.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | Color = namedtuple('Color', ['red', 'green', 'blue']) 4 | 5 | color = Color(55,155,255) 6 | white = Color(255,255,255) 7 | 8 | print color.blue -------------------------------------------------------------------------------- /Object-Oriented/1-FirstClasses/oop.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | 4 | def __init__(self, first, last, pay): 5 | self.first = first 6 | self.last = last 7 | self.email = first + '.' + last + '@email.com' 8 | self.pay = pay 9 | 10 | def fullname(self): 11 | return '{} {}'.format(self.first, self.last) 12 | 13 | emp_1 = Employee('Corey', 'Schafer', 50000) 14 | emp_2 = Employee('Test', 'Employee', 60000) 15 | -------------------------------------------------------------------------------- /Object-Oriented/2-Class-Instance-Variables/oop.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | 4 | def __init__(self, first, last, pay): 5 | self.first = first 6 | self.last = last 7 | self.email = first + '.' + last + '@email.com' 8 | self.pay = pay 9 | 10 | def fullname(self): 11 | return '{} {}'.format(self.first, self.last) 12 | 13 | emp_1 = Employee('Corey', 'Schafer', 50000) 14 | emp_2 = Employee('Test', 'Employee', 60000) 15 | -------------------------------------------------------------------------------- /Object-Oriented/4-Inheritance/oop.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | 4 | raise_amt = 1.04 5 | 6 | def __init__(self, first, last, pay): 7 | self.first = first 8 | self.last = last 9 | self.email = first + '.' + last + '@email.com' 10 | self.pay = pay 11 | 12 | def fullname(self): 13 | return '{} {}'.format(self.first, self.last) 14 | 15 | def apply_raise(self): 16 | self.pay = int(self.pay * self.raise_amt) 17 | 18 | 19 | dev_1 = Employee('Corey', 'Schafer', 50000) 20 | dev_2 = Employee('Test', 'Employee', 60000) 21 | 22 | print(dev_1.email) 23 | print(dev_2.email) 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | # print(dev_1.raise_amt) 34 | # dev_1.apply_raise() 35 | # print(dev_1.raise_amt) 36 | -------------------------------------------------------------------------------- /Object-Oriented/6-property-decorator/oop.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | 4 | def __init__(self, first, last): 5 | self.first = first 6 | self.last = last 7 | 8 | @property 9 | def email(self): 10 | return '{}.{}@email.com'.format(self.first, self.last) 11 | 12 | @property 13 | def fullname(self): 14 | return '{} {}'.format(self.first, self.last) 15 | 16 | 17 | emp_1 = Employee('John', 'Smith') 18 | 19 | print(emp_1.first) 20 | print(emp_1.email) 21 | print(emp_1.fullname) 22 | -------------------------------------------------------------------------------- /Python-CSV/new_names.csv: -------------------------------------------------------------------------------- 1 | first_name last_name 2 | John Doe 3 | Mary Smith-Robinson 4 | Dave Smith 5 | Jane Stuart 6 | Tom Wright 7 | Steve Robinson 8 | Nicole Jacobs 9 | Jane Wright 10 | Jane Doe 11 | Kurt Wright 12 | Kurt Robinson 13 | Jane Jenkins 14 | Neil Robinson 15 | Tom Patterson 16 | Sam Jenkins 17 | Steve Stuart 18 | Maggie Patterson 19 | Maggie Stuart 20 | Jane Doe 21 | Steve Patterson 22 | Dave Smith 23 | Sam Wilks 24 | Kurt Jefferson 25 | Sam Stuart 26 | Jane Stuart 27 | Dave Davis 28 | Sam Patterson 29 | Tom Jefferson 30 | Jane Stuart 31 | Maggie Jefferson 32 | Mary Wilks 33 | Neil Patterson 34 | Corey Davis 35 | Steve Jacobs 36 | Jane Jenkins 37 | John Jacobs 38 | Neil Smith 39 | Corey Wilks 40 | Corey Smith 41 | Mary Patterson 42 | Jane Stuart 43 | Travis Arnold 44 | John Robinson 45 | Travis Arnold 46 | -------------------------------------------------------------------------------- /Python-CSV/parse_csv.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | with open('names.csv', 'r') as csv_file: 4 | csv_reader = csv.DictReader(csv_file) 5 | 6 | with open('new_names.csv', 'w') as new_file: 7 | fieldnames = ['first_name', 'last_name'] 8 | 9 | csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames, delimiter='\t') 10 | 11 | csv_writer.writeheader() 12 | 13 | for line in csv_reader: 14 | del line['email'] 15 | csv_writer.writerow(line) 16 | -------------------------------------------------------------------------------- /Python-Conditionals/intro.py: -------------------------------------------------------------------------------- 1 | 2 | condition = 'Test' 3 | 4 | if condition: 5 | print('Evaluated to True') 6 | else: 7 | print('Evaluated to False') 8 | -------------------------------------------------------------------------------- /Python-Conditionals/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | # Comparisons: 3 | # Equal: == 4 | # Not Equal: != 5 | # Greater Than: > 6 | # Less Than: < 7 | # Greater or Equal: >= 8 | # Less or Equal: <= 9 | # Object Identity: is 10 | 11 | 12 | # False Values: 13 | # False 14 | # None 15 | # Zero of any numeric type 16 | # Any empty sequence. For example, '', (), []. 17 | # Any empty mapping. For example, {}. 18 | 19 | condition = False 20 | 21 | if condition: 22 | print('Evaluated to True') 23 | else: 24 | print('Evaluated to False') 25 | -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-One/mydoc.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-One/mydoc.txt -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-One/todo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-One/todo.txt -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-One/work.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-One/work.txt -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-Two/demo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-Two/demo.txt -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-Two/sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-Two/sample.txt -------------------------------------------------------------------------------- /Python-Context-Managers/Sample-Dir-Two/test.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-Context-Managers/Sample-Dir-Two/test.txt -------------------------------------------------------------------------------- /Python-Context-Managers/cm_demo.py: -------------------------------------------------------------------------------- 1 | import os 2 | from contextlib import contextmanager 3 | 4 | 5 | @contextmanager 6 | def change_dir(destination): 7 | try: 8 | cwd = os.getcwd() 9 | os.chdir(destination) 10 | yield 11 | finally: 12 | os.chdir(cwd) 13 | 14 | 15 | with change_dir('Sample-Dir-One'): 16 | print(os.listdir()) 17 | 18 | with change_dir('Sample-Dir-Two'): 19 | print(os.listdir()) 20 | -------------------------------------------------------------------------------- /Python-Context-Managers/sample.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. -------------------------------------------------------------------------------- /Python-Context-Managers/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | class Open_File(): 3 | 4 | def __init__(self, destination): 5 | pass 6 | 7 | def __enter__(self): 8 | pass 9 | 10 | def __exit__(self, exc_type, exc_val, traceback): 11 | pass 12 | 13 | 14 | #### Using contextlib #### 15 | 16 | @contextmanager 17 | def open_file(file, mode): 18 | f = open(file, mode) 19 | yield f 20 | f.close() 21 | 22 | 23 | with open_file('sample.txt', 'w') as f: 24 | f.write('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') 25 | 26 | print(f.closed) 27 | 28 | 29 | #### CD Example #### 30 | 31 | cwd = os.getcwd() 32 | os.chdir('Sample-Dir-One') 33 | print(os.listdir()) 34 | os.chdir(cwd) 35 | 36 | cwd = os.getcwd() 37 | os.chdir('Sample-Dir-Two') 38 | print(os.listdir()) 39 | os.chdir(cwd) 40 | 41 | 42 | -------------------------------------------------------------------------------- /Python-Decorator-Arguments/decorator-finish.py: -------------------------------------------------------------------------------- 1 | # Decorators 2 | 3 | 4 | def prefix_decorator(prefix): 5 | def decorator_function(original_function): 6 | def wrapper_function(*args, **kwargs): 7 | print(prefix, 'Executed Before', original_function.__name__) 8 | result = original_function(*args, **kwargs) 9 | print(prefix, 'Executed After', original_function.__name__, '\n') 10 | return result 11 | return wrapper_function 12 | return decorator_function 13 | 14 | 15 | @prefix_decorator('LOG:') 16 | def display_info(name, age): 17 | print('display_info ran with arguments ({}, {})'.format(name, age)) 18 | 19 | 20 | display_info('John', 25) 21 | display_info('Travis', 30) 22 | -------------------------------------------------------------------------------- /Python-Decorator-Arguments/decorator-start.py: -------------------------------------------------------------------------------- 1 | # Decorators 2 | 3 | 4 | def decorator_function(original_function): 5 | def wrapper_function(*args, **kwargs): 6 | print('Executed Before', original_function.__name__) 7 | result = original_function(*args, **kwargs) 8 | print('Executed After', original_function.__name__, '\n') 9 | return result 10 | return wrapper_function 11 | 12 | 13 | @decorator_function 14 | def display_info(name, age): 15 | print('display_info ran with arguments ({}, {})'.format(name, age)) 16 | 17 | 18 | display_info('John', 25) 19 | display_info('Travis', 30) 20 | -------------------------------------------------------------------------------- /Python-Decorator-Arguments/flask-hello.py: -------------------------------------------------------------------------------- 1 | 2 | from flask import Flask 3 | app = Flask(__name__) 4 | 5 | 6 | @app.route("/") 7 | def hello(): 8 | return "Hello World!" 9 | 10 | 11 | @app.route("/about") 12 | def about(): 13 | return "About Page" 14 | 15 | if __name__ == "__main__": 16 | app.run() 17 | -------------------------------------------------------------------------------- /Python-Dicts/intro.py: -------------------------------------------------------------------------------- 1 | 2 | student = {'name': 'John', 'age': 25, 'courses': ['Math', 'CompSci']} 3 | 4 | for key, value in student.items(): 5 | print(key, value) 6 | -------------------------------------------------------------------------------- /Python-Files/README.txt: -------------------------------------------------------------------------------- 1 | The Files.py contains all the code snippets shown in 2 | the tutorial. To explicitly use them all through out the video tutorial, make sure to uncomment 3 | them to use it. 4 | 5 | In the image section, make sure to use your own image. 6 | 7 | 8 | Video Link: https://www.youtube.com/watch?v=Uh2ebFW8OYM&t=1295s 9 | -------------------------------------------------------------------------------- /Python-Files/test.txt: -------------------------------------------------------------------------------- 1 | 1) This is a test file 2 | 2) With multiple lines of data... 3 | 3) Third line 4 | 4) Fourth line 5 | 5) Fifth line 6 | 6) Sixth line 7 | 7) Seventh line 8 | 8) Eighth line 9 | 9) Ninth line 10 | 10) Tenth line -------------------------------------------------------------------------------- /Python-Functions/intro.py: -------------------------------------------------------------------------------- 1 | 2 | # Number of days per month. First value placeholder for indexing purposes. 3 | month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 4 | 5 | 6 | def is_leap(year): 7 | """Return True for leap years, False for non-leap years.""" 8 | 9 | return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) 10 | 11 | 12 | def days_in_month(year, month): 13 | """Return number of days in that month in that year.""" 14 | 15 | # year 2017 16 | # month 2 17 | if not 1 <= month <= 12: 18 | return 'Invalid Month' 19 | 20 | if month == 2 and is_leap(year): 21 | return 29 22 | 23 | return month_days[month] 24 | 25 | print(days_in_month(2017, 2)) 26 | -------------------------------------------------------------------------------- /Python-Functions/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | # Number of days per month. First value placeholder for indexing purposes. 3 | month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 4 | 5 | 6 | def is_leap(year): 7 | """Return True for leap years, False for non-leap years.""" 8 | 9 | return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) 10 | 11 | 12 | def days_in_month(year, month): 13 | """Return number of days in that month in that year.""" 14 | 15 | if not 1 <= month <= 12: 16 | return 'Invalid Month' 17 | 18 | if month == 2 and is_leap(year): 19 | return 29 20 | 21 | return month_days[month] 22 | -------------------------------------------------------------------------------- /Python-Future-Date/credit.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import calendar 3 | 4 | balance = 10000 5 | interest_rate = 13 * .01 6 | monthly_payment = 1000 7 | 8 | today = datetime.date.today() 9 | days_in_current_month = calendar.monthrange(today.year, today.month)[1] 10 | days_till_end_month = days_in_current_month - today.day 11 | 12 | start_date = today + datetime.timedelta(days=days_till_end_month + 1) 13 | end_date = start_date 14 | 15 | while balance > 0: 16 | interest_charge = (interest_rate / 12) * balance 17 | balance += interest_charge 18 | balance -= monthly_payment 19 | 20 | balance = round(balance, 2) 21 | if balance < 0: 22 | balance = 0 23 | 24 | print(end_date, balance) 25 | 26 | days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1] 27 | end_date = end_date + datetime.timedelta(days=days_in_current_month) 28 | -------------------------------------------------------------------------------- /Python-Future-Date/subs.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import math 3 | 4 | goal_subs = 150000 5 | current_subs = 85000 6 | subs_to_go = goal_subs - current_subs 7 | 8 | avg_subs_day = 200 9 | days_to_go = math.ceil(subs_to_go / avg_subs_day) 10 | 11 | today = datetime.date.today() 12 | 13 | print(today + datetime.timedelta(days=days_to_go)) 14 | -------------------------------------------------------------------------------- /Python-Future-Date/weight.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | current_weight = 220 4 | goal_weight = 180 5 | avg_lbs_week = 2 6 | 7 | start_date = datetime.date.today() 8 | end_date = start_date 9 | 10 | while current_weight > goal_weight: 11 | end_date += datetime.timedelta(days=7) 12 | current_weight -= avg_lbs_week 13 | 14 | print(end_date) 15 | print(f'Reached goal in {(end_date - start_date).days // 7} weeks') 16 | -------------------------------------------------------------------------------- /Python-Imports/intro.py: -------------------------------------------------------------------------------- 1 | 2 | courses = ['History', 'Math', 'Physics', 'CompSci'] 3 | -------------------------------------------------------------------------------- /Python-Imports/my_module.py: -------------------------------------------------------------------------------- 1 | 2 | print('Imported my_module...') 3 | 4 | test = 'Test String' 5 | 6 | 7 | def find_index(to_search, target): 8 | '''Find the index of a value in a sequence''' 9 | for i, value in enumerate(to_search): 10 | if value == target: 11 | return i 12 | 13 | return -1 14 | -------------------------------------------------------------------------------- /Python-Ints/intro.py: -------------------------------------------------------------------------------- 1 | 2 | num_1 = '100' 3 | num_2 = '200' 4 | 5 | num_1 = int(num_1) 6 | num_2 = int(num_2) 7 | 8 | print(num_1 + num_2) 9 | -------------------------------------------------------------------------------- /Python-Ints/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | # Arithmetic Operators: 3 | # Addition: 3 + 2 4 | # Subtraction: 3 - 2 5 | # Multiplication: 3 * 2 6 | # Division: 3 / 2 7 | # Floor Division: 3 // 2 8 | # Exponent: 3 ** 2 9 | # Modulus: 3 % 2 10 | 11 | 12 | # Comparisons: 13 | # Equal: 3 == 2 14 | # Not Equal: 3 != 2 15 | # Greater Than: 3 > 2 16 | # Less Than: 3 < 2 17 | # Greater or Equal: 3 >= 2 18 | # Less or Equal: 3 <= 2 19 | -------------------------------------------------------------------------------- /Python-JSON/api.py: -------------------------------------------------------------------------------- 1 | import json 2 | from urllib.request import urlopen 3 | 4 | with urlopen("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json") as response: 5 | source = response.read() 6 | 7 | data = json.loads(source) 8 | 9 | # print(json.dumps(data, indent=2)) 10 | 11 | usd_rates = dict() 12 | 13 | for item in data['list']['resources']: 14 | name = item['resource']['fields']['name'] 15 | price = item['resource']['fields']['price'] 16 | usd_rates[name] = price 17 | 18 | print(50 * float(usd_rates['USD/INR'])) 19 | -------------------------------------------------------------------------------- /Python-JSON/json_demo.py: -------------------------------------------------------------------------------- 1 | ''' JavaScript Object Notation ''' 2 | import json 3 | 4 | with open('states.json') as f: 5 | data = json.load(f) 6 | 7 | for state in data['states']: 8 | del state['area_codes'] 9 | 10 | with open('new_states.json', 'w') as f: 11 | json.dump(data, f, indent=2) 12 | -------------------------------------------------------------------------------- /Python-Lists/intro.py: -------------------------------------------------------------------------------- 1 | 2 | # Empty Lists 3 | empty_list = [] 4 | empty_list = list() 5 | 6 | # Empty Tuples 7 | empty_tuple = () 8 | empty_tuple = tuple() 9 | 10 | # Empty Sets 11 | empty_set = {} # This isn't right! It's a dict 12 | empty_set = set() 13 | -------------------------------------------------------------------------------- /Python-Lists/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Mutable 4 | list_1 = ['History', 'Math', 'Physics', 'CompSci'] 5 | list_2 = list_1 6 | 7 | print(list_1) 8 | print(list_2) 9 | 10 | # list_1[0] = 'Art' 11 | 12 | # print(list_1) 13 | # print(list_2) 14 | 15 | 16 | # Immutable 17 | # tuple_1 = ('History', 'Math', 'Physics', 'CompSci') 18 | # tuple_2 = tuple_1 19 | 20 | # print(tuple_1) 21 | # print(tuple_2) 22 | 23 | # tuple_1[0] = 'Art' 24 | 25 | # print(tuple_1) 26 | # print(tuple_2) 27 | 28 | # Sets 29 | cs_courses = {'History', 'Math', 'Physics', 'CompSci'} 30 | 31 | print(cs_courses) 32 | 33 | 34 | # Empty Lists 35 | empty_list = [] 36 | empty_list = list() 37 | 38 | # Empty Tuples 39 | empty_tuple = () 40 | empty_tuple = tuple() 41 | 42 | # Empty Sets 43 | empty_set = {} # This isn't right! It's a dict 44 | empty_set = set() 45 | -------------------------------------------------------------------------------- /Python-Loops/intro.py: -------------------------------------------------------------------------------- 1 | 2 | x = 0 3 | 4 | while True: 5 | # if x == 5: 6 | # break 7 | print(x) 8 | x += 1 9 | -------------------------------------------------------------------------------- /Python-Patreon-CSV/parse_csv.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | html_output = '' 4 | names = [] 5 | 6 | with open('patrons.csv', 'r') as data_file: 7 | csv_data = csv.DictReader(data_file) 8 | 9 | # We don't want first line of bad data 10 | next(csv_data) 11 | 12 | for line in csv_data: 13 | if line['FirstName'] == 'No Reward': 14 | break 15 | names.append(f"{line['FirstName']} {line['LastName']}") 16 | 17 | html_output += f'

There are currently {len(names)} public contributors. Thank You!

' 18 | 19 | html_output += '\n
    ' 20 | 21 | for name in names: 22 | html_output += f'\n\t
  • {name}
  • ' 23 | 24 | html_output += '\n
' 25 | 26 | print(html_output) 27 | -------------------------------------------------------------------------------- /Python-Random/random_demo.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | deck = list(range(1, 53)) 4 | 5 | hand = random.sample(deck, k=5) 6 | print(hand) 7 | -------------------------------------------------------------------------------- /Python-Regular-Expressions/emails.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | emails = ''' 4 | CoreyMSchafer@gmail.com 5 | corey.schafer@university.edu 6 | corey-321-schafer@my-work.net 7 | ''' 8 | 9 | pattern = re.compile(r'[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+') 10 | 11 | matches = pattern.finditer(emails) 12 | 13 | for match in matches: 14 | print(match) 15 | -------------------------------------------------------------------------------- /Python-Regular-Expressions/simple.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text_to_search = ''' 4 | abcdefghijklmnopqurtuvwxyz 5 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 6 | 1234567890 7 | 8 | Ha HaHa 9 | 10 | MetaCharacters (Need to be escaped): 11 | . ^ $ * + ? { } [ ] \ | ( ) 12 | 13 | coreyms.com 14 | 15 | 321-555-4321 16 | 123.555.1234 17 | 123*555*1234 18 | 800-555-1234 19 | 900-555-1234 20 | 21 | Mr. Schafer 22 | Mr Smith 23 | Ms Davis 24 | Mrs. Robinson 25 | Mr. T 26 | ''' 27 | 28 | sentence = 'Start a sentence and then bring it to an end' 29 | 30 | pattern = re.compile(r'start', re.I) 31 | 32 | matches = pattern.search(sentence) 33 | 34 | print(matches) 35 | -------------------------------------------------------------------------------- /Python-Regular-Expressions/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | . - Any Character Except New Line 3 | \d - Digit (0-9) 4 | \D - Not a Digit (0-9) 5 | \w - Word Character (a-z, A-Z, 0-9, _) 6 | \W - Not a Word Character 7 | \s - Whitespace (space, tab, newline) 8 | \S - Not Whitespace (space, tab, newline) 9 | 10 | \b - Word Boundary 11 | \B - Not a Word Boundary 12 | ^ - Beginning of a String 13 | $ - End of a String 14 | 15 | [] - Matches Characters in brackets 16 | [^ ] - Matches Characters NOT in brackets 17 | | - Either Or 18 | ( ) - Group 19 | 20 | Quantifiers: 21 | * - 0 or More 22 | + - 1 or More 23 | ? - 0 or One 24 | {3} - Exact Number 25 | {3,4} - Range of Numbers (Minimum, Maximum) 26 | 27 | 28 | #### Sample Regexs #### 29 | 30 | [a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+ 31 | -------------------------------------------------------------------------------- /Python-Regular-Expressions/urls.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | urls = ''' 4 | https://www.google.com 5 | http://coreyms.com 6 | https://youtube.com 7 | https://www.nasa.gov 8 | ''' 9 | 10 | pattern = re.compile(r'https?://(www\.)?(\w+)(\.\w+)') 11 | 12 | subbed_urls = pattern.sub(r'\2\3', urls) 13 | 14 | print(subbed_urls) 15 | 16 | # matches = pattern.finditer(urls) 17 | 18 | # for match in matches: 19 | # print(match.group(3)) 20 | -------------------------------------------------------------------------------- /Python-SQLite/employee.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python-SQLite/employee.db -------------------------------------------------------------------------------- /Python-SQLite/employee.py: -------------------------------------------------------------------------------- 1 | 2 | class Employee: 3 | """A sample Employee class""" 4 | 5 | def __init__(self, first, last, pay): 6 | self.first = first 7 | self.last = last 8 | self.pay = pay 9 | 10 | @property 11 | def email(self): 12 | return '{}.{}@email.com'.format(self.first, self.last) 13 | 14 | @property 15 | def fullname(self): 16 | return '{} {}'.format(self.first, self.last) 17 | 18 | def __repr__(self): 19 | return "Employee('{}', '{}', {})".format(self.first, self.last, self.pay) 20 | -------------------------------------------------------------------------------- /Python-SQLite/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | def insert_emp(emp): 3 | pass 4 | 5 | 6 | def get_emps_by_name(lastname): 7 | pass 8 | 9 | 10 | def update_pay(emp, pay): 11 | pass 12 | 13 | 14 | def remove_emp(emp): 15 | pass 16 | 17 | 18 | 19 | 20 | def update_pay(emp, pay): 21 | with conn: 22 | c.execute("""UPDATE employees SET pay = :pay 23 | WHERE first = :first AND last = :last""", 24 | {'first': emp.first, 'last': emp.last, 'pay': pay}) 25 | 26 | 27 | def remove_emp(emp): 28 | with conn: 29 | c.execute("DELETE from employees WHERE first = :first AND last = :last", 30 | {'first': emp.first, 'last': emp.last}) 31 | -------------------------------------------------------------------------------- /Python-Strings/intro.py: -------------------------------------------------------------------------------- 1 | 2 | greeting = 'Hello' 3 | name = 'Michael' 4 | 5 | print(help(str.lower)) 6 | -------------------------------------------------------------------------------- /Python-Unit-Testing/calc.py: -------------------------------------------------------------------------------- 1 | 2 | def add(x, y): 3 | """Add Function""" 4 | return x + y 5 | 6 | 7 | def subtract(x, y): 8 | """Subtract Function""" 9 | return x - y 10 | 11 | 12 | def multiply(x, y): 13 | """Multiply Function""" 14 | return x * y 15 | 16 | 17 | def divide(x, y): 18 | """Divide Function""" 19 | if y == 0: 20 | raise ValueError('Can not divide by zero!') 21 | return x / y 22 | -------------------------------------------------------------------------------- /Python-Unit-Testing/employee.py: -------------------------------------------------------------------------------- 1 | 2 | import requests 3 | 4 | 5 | class Employee: 6 | """A sample Employee class""" 7 | 8 | raise_amt = 1.05 9 | 10 | def __init__(self, first, last, pay): 11 | self.first = first 12 | self.last = last 13 | self.pay = pay 14 | 15 | @property 16 | def email(self): 17 | return '{}.{}@email.com'.format(self.first, self.last) 18 | 19 | @property 20 | def fullname(self): 21 | return '{} {}'.format(self.first, self.last) 22 | 23 | def apply_raise(self): 24 | self.pay = int(self.pay * self.raise_amt) 25 | 26 | def monthly_schedule(self, month): 27 | response = requests.get(f'http://company.com/{self.last}/{month}') 28 | if response.ok: 29 | return response.text 30 | else: 31 | return 'Bad Response!' 32 | -------------------------------------------------------------------------------- /Python/Flask_Blog/01-Getting-Started/flaskblog.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route("/") 6 | @app.route("/home") 7 | def home(): 8 | return "

Home Page

" 9 | 10 | 11 | @app.route("/about") 12 | def about(): 13 | return "

About Page

" 14 | 15 | 16 | if __name__ == '__main__': 17 | app.run(debug=True) 18 | -------------------------------------------------------------------------------- /Python/Flask_Blog/02-Templates/flaskblog.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, url_for 2 | app = Flask(__name__) 3 | 4 | posts = [ 5 | { 6 | 'author': 'Corey Schafer', 7 | 'title': 'Blog Post 1', 8 | 'content': 'First post content', 9 | 'date_posted': 'April 20, 2018' 10 | }, 11 | { 12 | 'author': 'Jane Doe', 13 | 'title': 'Blog Post 2', 14 | 'content': 'Second post content', 15 | 'date_posted': 'April 21, 2018' 16 | } 17 | ] 18 | 19 | 20 | @app.route("/") 21 | @app.route("/home") 22 | def home(): 23 | return render_template('home.html', posts=posts) 24 | 25 | 26 | @app.route("/about") 27 | def about(): 28 | return render_template('about.html', title='About') 29 | 30 | 31 | if __name__ == '__main__': 32 | app.run(debug=True) 33 | -------------------------------------------------------------------------------- /Python/Flask_Blog/02-Templates/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/02-Templates/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/03-Forms-and-Validation/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/03-Forms-and-Validation/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/03-Forms-and-Validation/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/03-Forms-and-Validation/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/04-Database/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/04-Database/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/04-Database/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/04-Database/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/05-Package-Structure/flaskblog/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | 4 | app = Flask(__name__) 5 | app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' 6 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' 7 | db = SQLAlchemy(app) 8 | 9 | from flaskblog import routes 10 | -------------------------------------------------------------------------------- /Python/Flask_Blog/05-Package-Structure/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/05-Package-Structure/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/05-Package-Structure/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/05-Package-Structure/flaskblog/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/05-Package-Structure/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/flaskblog/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | from flask_bcrypt import Bcrypt 4 | from flask_login import LoginManager 5 | 6 | app = Flask(__name__) 7 | app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' 8 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' 9 | db = SQLAlchemy(app) 10 | bcrypt = Bcrypt(app) 11 | login_manager = LoginManager(app) 12 | login_manager.login_view = 'login' 13 | login_manager.login_message_category = 'info' 14 | 15 | from flaskblog import routes 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/06-Login-Auth/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/flaskblog/templates/account.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

{{ current_user.username }}

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/flaskblog/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/06-Login-Auth/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | from flask_bcrypt import Bcrypt 4 | from flask_login import LoginManager 5 | 6 | app = Flask(__name__) 7 | app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' 8 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' 9 | db = SQLAlchemy(app) 10 | bcrypt = Bcrypt(app) 11 | login_manager = LoginManager(app) 12 | login_manager.login_view = 'login' 13 | login_manager.login_message_category = 'info' 14 | 15 | from flaskblog import routes 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/flaskblog/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 14 | {% endfor %} 15 | {% endblock content %} 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/07-User-Account-Profile-Pic/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | from flask_bcrypt import Bcrypt 4 | from flask_login import LoginManager 5 | 6 | app = Flask(__name__) 7 | app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' 8 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' 9 | db = SQLAlchemy(app) 10 | bcrypt = Bcrypt(app) 11 | login_manager = LoginManager(app) 12 | login_manager.login_view = 'login' 13 | login_manager.login_message_category = 'info' 14 | 15 | from flaskblog import routes 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/08-Posts/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/flaskblog/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 | {% for post in posts %} 4 | 15 | {% endfor %} 16 | {% endblock content %} 17 | -------------------------------------------------------------------------------- /Python/Flask_Blog/08-Posts/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | from flask_bcrypt import Bcrypt 4 | from flask_login import LoginManager 5 | 6 | app = Flask(__name__) 7 | app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' 8 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' 9 | db = SQLAlchemy(app) 10 | bcrypt = Bcrypt(app) 11 | login_manager = LoginManager(app) 12 | login_manager.login_view = 'login' 13 | login_manager.login_message_category = 'info' 14 | 15 | from flaskblog import routes 16 | -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/09-Pagination/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/09-Pagination/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/10-Password-Reset-Email/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import app 2 | 3 | if __name__ == '__main__': 4 | app.run(debug=True) 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class Config: 5 | SECRET_KEY = os.environ.get('SECRET_KEY') 6 | SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI') 7 | MAIL_SERVER = 'smtp.googlemail.com' 8 | MAIL_PORT = 587 9 | MAIL_USE_TLS = True 10 | MAIL_USERNAME = os.environ.get('EMAIL_USER') 11 | MAIL_PASSWORD = os.environ.get('EMAIL_PASS') 12 | -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/main/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/main/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/main/routes.py: -------------------------------------------------------------------------------- 1 | from flask import render_template, request, Blueprint 2 | from flaskblog.models import Post 3 | 4 | main = Blueprint('main', __name__) 5 | 6 | 7 | @main.route("/") 8 | @main.route("/home") 9 | def home(): 10 | page = request.args.get('page', 1, type=int) 11 | posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5) 12 | return render_template('home.html', posts=posts) 13 | 14 | 15 | @main.route("/about") 16 | def about(): 17 | return render_template('about.html', title='About') 18 | -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/posts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/posts/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/posts/forms.py: -------------------------------------------------------------------------------- 1 | from flask_wtf import FlaskForm 2 | from wtforms import StringField, SubmitField, TextAreaField 3 | from wtforms.validators import DataRequired 4 | 5 | 6 | class PostForm(FlaskForm): 7 | title = StringField('Title', validators=[DataRequired()]) 8 | content = TextAreaField('Content', validators=[DataRequired()]) 9 | submit = SubmitField('Post') 10 | -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/7ef894751d31a45b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/7ef894751d31a45b.png -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/ddd3ffe2e3271c40.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/ddd3ffe2e3271c40.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/flaskblog/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/11-Blueprints/flaskblog/users/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/11-Blueprints/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import create_app 2 | 3 | app = create_app() 4 | 5 | if __name__ == '__main__': 6 | app.run(debug=True) 7 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class Config: 5 | SECRET_KEY = os.environ.get('SECRET_KEY') 6 | SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI') 7 | MAIL_SERVER = 'smtp.googlemail.com' 8 | MAIL_PORT = 587 9 | MAIL_USE_TLS = True 10 | MAIL_USERNAME = os.environ.get('EMAIL_USER') 11 | MAIL_PASSWORD = os.environ.get('EMAIL_PASS') 12 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/errors/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/errors/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/errors/handlers.py: -------------------------------------------------------------------------------- 1 | from flask import Blueprint, render_template 2 | 3 | errors = Blueprint('errors', __name__) 4 | 5 | 6 | @errors.app_errorhandler(404) 7 | def error_404(error): 8 | return render_template('errors/404.html'), 404 9 | 10 | 11 | @errors.app_errorhandler(403) 12 | def error_403(error): 13 | return render_template('errors/403.html'), 403 14 | 15 | 16 | @errors.app_errorhandler(500) 17 | def error_500(error): 18 | return render_template('errors/500.html'), 500 19 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/main/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/main/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/main/routes.py: -------------------------------------------------------------------------------- 1 | from flask import render_template, request, Blueprint 2 | from flaskblog.models import Post 3 | 4 | main = Blueprint('main', __name__) 5 | 6 | 7 | @main.route("/") 8 | @main.route("/home") 9 | def home(): 10 | page = request.args.get('page', 1, type=int) 11 | posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5) 12 | return render_template('home.html', posts=posts) 13 | 14 | 15 | @main.route("/about") 16 | def about(): 17 | return render_template('about.html', title='About') 18 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/posts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/posts/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/posts/forms.py: -------------------------------------------------------------------------------- 1 | from flask_wtf import FlaskForm 2 | from wtforms import StringField, SubmitField, TextAreaField 3 | from wtforms.validators import DataRequired 4 | 5 | 6 | class PostForm(FlaskForm): 7 | title = StringField('Title', validators=[DataRequired()]) 8 | content = TextAreaField('Content', validators=[DataRequired()]) 9 | submit = SubmitField('Post') 10 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/site.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/site.db -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/2e32b4c96a8d8f10.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/7798432669b8b3ac.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/7798432669b8b3ac.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/7ef894751d31a45b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/7ef894751d31a45b.png -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/85ed1b444539873d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/85ed1b444539873d.png -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/b6e1c53325f88b74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/b6e1c53325f88b74.png -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/ddd3ffe2e3271c40.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/ddd3ffe2e3271c40.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/static/profile_pics/default.jpg -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |

About Page

4 | {% endblock content %} 5 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/templates/errors/403.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |
4 |

You don't have permission to do that (403)

5 |

Please check your account and try again

6 |
7 | {% endblock content %} 8 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/templates/errors/404.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |
4 |

Oops. Page Not Found (404)

5 |

That page does not exist. Please try a different location

6 |
7 | {% endblock content %} 8 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/templates/errors/500.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block content %} 3 |
4 |

Something went wrong (500)

5 |

We're experiencing some trouble on our end. Please try again in the near future

6 |
7 | {% endblock content %} 8 | -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/flaskblog/users/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dece1ver/CoreyMSchafer_code_snippets/7d3d49bd44f909587487529ab05d2cfd6161c800/Python/Flask_Blog/12-Error-Pages/flaskblog/users/__init__.py -------------------------------------------------------------------------------- /Python/Flask_Blog/12-Error-Pages/run.py: -------------------------------------------------------------------------------- 1 | from flaskblog import create_app 2 | 3 | app = create_app() 4 | 5 | if __name__ == '__main__': 6 | app.run(debug=True) 7 | -------------------------------------------------------------------------------- /Python/Flask_Blog/quickstart-windows.bat: -------------------------------------------------------------------------------- 1 | set FLASK_APP=flaskblog.py 2 | set FLASK_ENV=development 3 | flask run 4 | -------------------------------------------------------------------------------- /Python/Flask_Blog/snippets/account.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |

username@email.com

7 |
8 |
9 | 10 |
11 | -------------------------------------------------------------------------------- /Python/Flask_Blog/snippets/article.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Python/Flask_Blog/snippets/main.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | {% block content %}{% endblock %} 5 |
6 |
7 |
8 |

Our Sidebar

9 |

You can put any information here you'd like. 10 |

    11 |
  • Latest Posts
  • 12 |
  • Announcements
  • 13 |
  • Calendars
  • 14 |
  • etc
  • 15 |
16 |

17 |
18 |
19 |
20 |
21 | -------------------------------------------------------------------------------- /Python/Python-Environment-Variables/env_vars.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | db_user = os.environ.get('DB_USER') 4 | db_password = os.environ.get('DB_PASS') 5 | 6 | print(db_user) 7 | print(db_password) 8 | -------------------------------------------------------------------------------- /Python/Python-Sets/sets.py: -------------------------------------------------------------------------------- 1 | 2 | employees = ['Corey', 'Jim', 'Steven', 'April', 'Judy', 'Jenn', 'John', 'Jane'] 3 | 4 | gym_members = ['April', 'John', 'Corey'] 5 | 6 | developers = ['Judy', 'Corey', 'Steven', 'Jane', 'April'] 7 | 8 | if 'Corey' in developers: 9 | print('Found!') 10 | 11 | # O(n) for list 12 | # O(1) for a set 13 | -------------------------------------------------------------------------------- /Python/Python-Sets/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | s1 = {1, 2, 3} 3 | s2 = {2, 3, 4} 4 | s3 = {3, 4, 5} 5 | 6 | # print(s4) 7 | 8 | 9 | employees = ['Corey', 'Jim', 'Steven', 'April', 'Judy', 'Jenn', 'John', 'Jane'] 10 | 11 | gym_members = ['April', 'John', 'Corey'] 12 | 13 | developers = ['Judy', 'Corey', 'Steven', 'Jane', 'April'] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # code_snippets -------------------------------------------------------------------------------- /Regular-Expressions/emails.txt: -------------------------------------------------------------------------------- 1 | 2 | CoreyMSchafer@gmail.com 3 | corey.schafer@university.edu 4 | corey-321-schafer@my-work.net 5 | -------------------------------------------------------------------------------- /Regular-Expressions/simple.txt: -------------------------------------------------------------------------------- 1 | abcdefghijklmnopqurtuvwxyz 2 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 | 1234567890 4 | 5 | Ha HaHa 6 | 7 | MetaCharacters (Need to be escaped): 8 | .[{()\^$|?*+ 9 | 10 | coreyms.com 11 | 12 | 321-555-4321 13 | 123.555.1234 14 | 15 | Mr. Schafer 16 | Mr Smith 17 | Ms Davis 18 | Mrs. Robinson 19 | Mr. T 20 | -------------------------------------------------------------------------------- /Regular-Expressions/snippets.txt: -------------------------------------------------------------------------------- 1 | 2 | . - Any Character Except New Line 3 | \d - Digit (0-9) 4 | \D - Not a Digit (0-9) 5 | \w - Word Character (a-z, A-Z, 0-9, _) 6 | \W - Not a Word Character 7 | \s - Whitespace (space, tab, newline) 8 | \S - Not Whitespace (space, tab, newline) 9 | 10 | \b - Word Boundary 11 | \B - Not a Word Boundary 12 | ^ - Beginning of a String 13 | $ - End of a String 14 | 15 | [] - Matches Characters in brackets 16 | [^ ] - Matches Characters NOT in brackets 17 | | - Either Or 18 | ( ) - Group 19 | 20 | Quantifiers: 21 | * - 0 or More 22 | + - 1 or More 23 | ? - 0 or One 24 | {3} - Exact Number 25 | {3,4} - Range of Numbers (Minimum, Maximum) 26 | 27 | 28 | #### Sample Regexs #### 29 | 30 | [a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+ 31 | -------------------------------------------------------------------------------- /Regular-Expressions/urls.txt: -------------------------------------------------------------------------------- 1 | https://www.google.com 2 | http://coreyms.com 3 | https://youtube.com 4 | https://www.nasa.gov 5 | -------------------------------------------------------------------------------- /Scope/scope.py: -------------------------------------------------------------------------------- 1 | ''' 2 | LEGB 3 | Local, Enclosing, Global, Built-in 4 | ''' 5 | 6 | for a in range(2): 7 | x = 'global {}'.format(a) 8 | 9 | 10 | def outer(): 11 | # x = 'outer x' 12 | for b in range(3): 13 | x = 'outer {}'.format(b) 14 | 15 | def inner(): 16 | # x = 'inner x' 17 | for c in range(4): 18 | x = 'inner {}'.format(c) 19 | print(x) 20 | print(a, b, c) 21 | 22 | inner() 23 | print(x) 24 | print(a, b) 25 | 26 | outer() 27 | print(x) 28 | print(a) 29 | -------------------------------------------------------------------------------- /Slicing/slicing.py: -------------------------------------------------------------------------------- 1 | 2 | my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 3 | # 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 4 | # -10,-9,-8,-7,-6,-5,-4,-3,-2,-1 5 | 6 | # list[start:end:step] 7 | 8 | # print my_list[::-1] 9 | 10 | 11 | sample_url = 'http://coreyms.com' 12 | print sample_url 13 | 14 | # Reverse the url 15 | # print sample_url[::-1] 16 | 17 | # # Get the top level domain 18 | # print sample_url[-4:] 19 | 20 | # # Print the url without the http:// 21 | # print sample_url[7:] 22 | 23 | # # Print the url without the http:// or the top level domain 24 | print sample_url[7:-4] 25 | -------------------------------------------------------------------------------- /Starting_Code/calc.py: -------------------------------------------------------------------------------- 1 | 2 | def add(x, y): 3 | """Add Function""" 4 | return x + y 5 | 6 | 7 | def subtract(x, y): 8 | """Subtract Function""" 9 | return x - y 10 | 11 | 12 | def multiply(x, y): 13 | """Multiply Function""" 14 | return x * y 15 | 16 | 17 | def divide(x, y): 18 | """Divide Function""" 19 | return x / y 20 | -------------------------------------------------------------------------------- /Str_Repr/test.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import pytz 3 | 4 | a = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC) 5 | 6 | b = str(a) 7 | 8 | print 'str(a): {}'.format(str(a)) 9 | print 'str(b): {}'.format(str(b)) 10 | 11 | print 12 | 13 | print 'repr(a): {}'.format(repr(a)) 14 | print 'repr(b): {}'.format(repr(b)) 15 | 16 | print -------------------------------------------------------------------------------- /Str_Repr/test2.py: -------------------------------------------------------------------------------- 1 | a = [1,2,3,4] 2 | b = 'sample string' 3 | 4 | print str(a) 5 | print repr(a) 6 | 7 | print str(b) 8 | print repr(b) -------------------------------------------------------------------------------- /String Interpolation/test.py: -------------------------------------------------------------------------------- 1 | name = 'Corey' 2 | age = 28 3 | 4 | # greeting = 'My name is ' + name + ' and I am ' + str(age) + ' years old' 5 | 6 | greeting = 'I am {age} years old and my name is {name}'.format(name=name, age=age) 7 | 8 | print greeting 9 | 10 | -------------------------------------------------------------------------------- /Terminal/Grep/Personel/emails.txt: -------------------------------------------------------------------------------- 1 | 2 | Corey Schafer 3 | CoreyMSchafer@gmail.com 4 | 5 | John Williams 6 | JohnWilliams@company.com 7 | 8 | Jane Doe 9 | JaneDoe@dummyemail.com 10 | -------------------------------------------------------------------------------- /Terminal/Grep/Personel/phone_numbers.txt: -------------------------------------------------------------------------------- 1 | 2 | Corey Schafer 3 | 304-555-0223 4 | 5 | John Williams 6 | 321-555-1234 7 | 8 | Jane Doe 9 | 123-555-4321 10 | -------------------------------------------------------------------------------- /Terminal/Grep/grep-commands.txt: -------------------------------------------------------------------------------- 1 | grep "Jane Williams" names.txt 2 | grep "John Williams" names.txt 3 | 4 | grep -w "John Williams" names.txt 5 | grep -wi "John Williams" names.txt 6 | grep -win "John Williams" names.txt 7 | 8 | grep -win -B 4 "John Williams" names.txt 9 | grep -win -A 4 "John Williams" names.txt 10 | grep -win -C 2 "John Williams" names.txt 11 | 12 | grep -win "John Williams" ./* 13 | grep -win "John Williams" ./*.txt 14 | grep -winr "John Williams" . 15 | grep -wirl "John Williams" . 16 | grep -wirc "John Williams" . 17 | 18 | history 19 | history | grep "git commit" 20 | history | grep "git commit" | grep "dotfile" 21 | 22 | grep "...-...-...." names.txt 23 | grep -P "\d{3}-\d{3}-\d{4}" names.txt 24 | grep -V 25 | -------------------------------------------------------------------------------- /Terminal/Grep/memo.txt: -------------------------------------------------------------------------------- 1 | 2 | Dear Mr. Doe, 3 | 4 | In our meeting today, John Williams had mentioned that the work could be completed by the end of the month. 5 | 6 | We really appreciate the hard work! 7 | 8 | Thanks, 9 | Corey Schafer 10 | -------------------------------------------------------------------------------- /conda_auto_env.sh: -------------------------------------------------------------------------------- 1 | # Modified from: 2 | # https://github.com/chdoig/conda-auto-env 3 | 4 | # Auto activate conda environments 5 | function conda_auto_env() { 6 | if [ -e "environment.yaml" ]; then 7 | ENV_NAME=$(head -n 1 environment.yaml | cut -f2 -d ' ') 8 | # Check if you are already in the environment 9 | if [[ $CONDA_PREFIX != *$ENV_NAME* ]]; then 10 | # Try to activate environment 11 | source activate $ENV_NAME &>/dev/null 12 | fi 13 | fi 14 | } 15 | 16 | export PROMPT_COMMAND="conda_auto_env;$PROMPT_COMMAND" 17 | -------------------------------------------------------------------------------- /mem_profile.py: -------------------------------------------------------------------------------- 1 | import psutil 2 | import os 3 | import sys 4 | import time 5 | 6 | 7 | def memory_usage_psutil(): 8 | process = psutil.Process(os.getpid()) 9 | mem = process.memory_info().rss / float(2 ** 20) 10 | return '{:.2f} MB'.format(mem) 11 | -------------------------------------------------------------------------------- /mem_profile_old.py: -------------------------------------------------------------------------------- 1 | from pympler import summary, muppy 2 | import psutil 3 | import resource 4 | import os 5 | import sys 6 | 7 | def memory_usage_psutil(): 8 | # return the memory usage in MB 9 | process = psutil.Process(os.getpid()) 10 | mem = process.get_memory_info()[0] / float(2 ** 20) 11 | return mem 12 | 13 | def memory_usage_resource(): 14 | rusage_denom = 1024. 15 | if sys.platform == 'darwin': 16 | # ... it seems that in OSX the output is different units ... 17 | rusage_denom = rusage_denom * rusage_denom 18 | mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom 19 | return mem 20 | --------------------------------------------------------------------------------