Skip to content

Instantly share code, notes, and snippets.

View mikeckennedy's full-sized avatar

Michael Kennedy mikeckennedy

View GitHub Profile
@mikeckennedy
mikeckennedy / markdown-subtemplate-example.md
Created February 19, 2020 01:35
This is the subtemplate in markdown with imports for https://talkpython.fm/beginners - notice the md imports of other templates.

What's this course about and how is it different?

Most courses teach you the facts of programming and Python. Here is how a loop is constructed. Here is how you test a condition and make your program choose one path or another. Often they assume that you are familiar with programming concepts such as data types, loops, functions, and so on and that you just need to learn the details of how to do this in Python.

This course is not most courses. If you want ground up coverage of

@mikeckennedy
mikeckennedy / speedy.py
Created January 20, 2020 22:46
Compare the speed of a complex multiple if test and set containment replement.
import datetime
def main():
count = 1000
run_sets(count)
run_ifs(count)
def run_sets(times):
@mikeckennedy
mikeckennedy / rss.xml.pt
Created December 18, 2019 20:37
RSS Feed template for Talk Python
<?xml version="1.0" encoding="UTF-8"?>
<rss
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Talk Python To Me - Python conversations for passionate developers</title>
<description>Talk Python to Me is a weekly podcast hosted by Michael Kennedy.
The show covers a wide array of Python topics as well as many related
@mikeckennedy
mikeckennedy / urlify.py
Last active December 25, 2019 22:44
Short script to take a string in the clipboard and replace it with something appropriate for a folder, file, or URL name.
# Make sure to pip install pyperclip and colorama.
# Because output is better with color!
import pyperclip
from colorama import Fore
def main():
print(Fore.WHITE + "-----------------------------")
print(Fore.WHITE + " URLIFY ")
print(Fore.WHITE + "-----------------------------")
@mikeckennedy
mikeckennedy / run_unsync.py
Created August 31, 2018 17:38
An example of asyncio, standard io, and process-based parallelism using unsync
# Requirements:
# aiohttp
# aiodns
# cchardet
# requests
# unsync
import asyncio
from unsync import unsync
@mikeckennedy
mikeckennedy / switch_in_python_example.py
Last active August 21, 2019 04:55
Could we easily add switch to the Python language? I think the answer is maybe yes!
# Here is an example of some syntax I'm proposing:
# See the github repo at https://github.com/mikeckennedy/python-switch
def test_switch():
num = 7
val = input("Enter a key. a, b, c or any other: ")
with Switch(val) as s:
s.case('a', process_a)
s.case('b', process_b)
symbol open high low close volume
AAL 49 49.1 48.47 48.63 11901883
AAPL 145.13 147.16 145.11 146.28 33917635
ADBE 143.75 145.59 143.06 145.41 3383524
AMZN 1002.54 1004.62 998.02 1003.74 2832807
GOOGL 975.5 986.62 974.46 986.09 1524905
MAT 20.22 20.75 20.11 20.68 10603967
MSFT 70.09 71.25 69.92 71.21 26803888
NTES 320 333.78 319 333.56 1356386
@mikeckennedy
mikeckennedy / stocks_v1.py
Last active June 27, 2017 17:46
Sorting example
import collections
Stock = collections.namedtuple('Stock', 'symbol, open, high, low, close, volume')
stocks = [
Stock('AAL', 49, 49.1, 48.47, 48.63, 11901883),
Stock('AAPL', 145.13, 147.16, 145.11, 146.28, 33917635),
Stock('ADBE', 143.75, 145.59, 143.06, 145.41, 3383524),
Stock('AMZN', 1002.54, 1004.62, 998.02, 1003.74, 2832807),
Stock('GOOGL', 975.5, 986.62, 974.46, 986.09, 1524905),
@mikeckennedy
mikeckennedy / loopy_pythonic.py
Last active February 18, 2017 15:15
Feedback for a student :)
# Original version
def main():
name = print_intro()
the_list = bash_list.commands
flag='1'
while flag=='1':
random.shuffle(the_list)
correct, incorrect, answer_list = question_loop(the_list)
percentage = calculate_stats(correct, incorrect)
print_results(correct, incorrect, percentage, name)
@mikeckennedy
mikeckennedy / extractdocx.py
Created January 27, 2017 17:54 — forked from etienned/extractdocx.py
Simple function to extract text from MS XML Word document (.docx) without any dependencies.
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile
"""
Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)