Skip to content

Instantly share code, notes, and snippets.

@AO8
AO8 / send_picamera_photo.py
Created December 12, 2024 01:23
Updated: Email a timestamped PiCamera photo with Gmail
import os
import picamera
import smtplib
import ssl
import time
from datetime import datetime as dt
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
@AO8
AO8 / unicode_encryption.py
Created December 12, 2024 01:06
Simple Unicode Encryption
# Simple unicode encryption
def encrypt_message(message):
encrypted = ' '.join(str(ord(char)) for char in message)
return encrypted
def decrypt_message(encrypted_message):
@AO8
AO8 / binary_encryption.py
Created December 12, 2024 01:02
Simple Binary Encryption
# Simple binary encryption
def encrypt_message(message):
encrypted = ' '.join(format(ord(char), '08b') for char in message)
return encrypted
def decrypt_message(encrypted_message):
@AO8
AO8 / send_ebook_codes.py
Created September 19, 2020 16:13
For Susan.
# be sure to enable less secure apps in gmail
import smtplib
import ssl
from email.mime.text import MIMEText
def send_gmail(sender, password, receiver, subject, body):
"""Prepare and send a nicely formatted Gmail"""
msg = MIMEText(body)
msg["Subject"] = subject
@AO8
AO8 / covid19.py
Last active August 11, 2020 04:57
Daily Coronavirus data update (global and WA state) with Python 3, requests, and beautifulsoup.
# Check out https://ncov2019.live/data by Avi Schiffmann
# as featured in the Seattle Times at:
# https://www.seattletimes.com/seattle-news/education/qa-avi-schiffmann-the-washington-state-teen-behind-a-coronavirus-website-with-millions-of-views/
from email.mime.text import MIMEText
import smtplib
import ssl
import sys
import stdiomask
from bs4 import BeautifulSoup
@AO8
AO8 / dynamic_dice_roller.py
Last active February 7, 2020 19:18
Dynamic dice roll visualizer with Python 3 and Matplotlib.
import datetime
import random
import sys
from matplotlib import animation
import matplotlib.pyplot as plt
import seaborn as sns
def update(frame_number, rolls, faces, frequencies):
random.seed(datetime.datetime.now())
@AO8
AO8 / language_analyzer.py
Last active November 17, 2023 18:07
Python text analyzer using TextBlob and Textatistic.
import nltk
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
from textatistic import Textatistic
# This corpus is required for the Naive Bayes Analyzer
nltk.download("movie_reviews")
def main():
user_text = get_user_text()
@AO8
AO8 / check_weather.py
Last active December 18, 2019 22:58
Check the weather with Python 3 and the Open Weather dot Org API.
# explore the Open Weather dot Org API at: https://openweathermap.org/api
from datetime import datetime
import requests
def main():
# app_id will be specific to personal Open Weather acccount, 60 API calls per hour max
APP_ID = "#YourAppId"
# get zip code from user
zip_code = input("Enter a 5-digit, US zip code: ").strip()
@AO8
AO8 / profiler.py
Created November 8, 2019 23:47
A simple profiling example with the timeit module.
import random
import timeit
TAX_RATE = .08
txns = [random.randrange(100) for _ in range(10000000)]
def get_price(txn):
return txn * (1 + TAX_RATE)
def get_prices_with_map():
@AO8
AO8 / countdown.py
Created November 1, 2019 18:02
A simple Python countdown clock.
import sys
from time import sleep
def countdown(seconds):
while seconds > -1:
mins, secs = divmod(seconds, 60)
formatted_time = f"{mins:02d}:{secs:02d}"
if seconds > 3:
print(formatted_time, end="\r")
else: