Skip to content

Instantly share code, notes, and snippets.

@AO8
AO8 / cc_encrypt.py
Created March 3, 2018 23:55
Simple Caesar Cipher Python encryption function.
import string
from time import sleep
alphabet = string.ascii_lowercase # "abcdefghijklmnopqrstuvwxyz"
def encrypt():
print("Welcome to Caesar Cipher Encryption.\n")
message = input("Type a message you would like to encrypt: ").lower()
print()
@AO8
AO8 / encrypt_decrypt.py
Last active April 8, 2024 03:51
A Python encryption class for encrypting and decrypting messages.
import string
import random
class Encryption():
def __init__(self,seed):
# Sets a random seed and a self.seed attribute
random.seed(seed)
self.seed = seed
@AO8
AO8 / enrollment_counter.py
Last active March 23, 2018 18:30
Using Python to analyze data in CSV files from IE. Quantifies non-IT, IT, and STEPP enrollments generated by BAS-SD.
import csv
import os
import re
import send2trash
def build_csv():
"""iterate through CSV files in directory to create master enrollment_data.csv"""
rows = []
for filename in os.listdir("C:\\Users\\aorr\\Desktop\\GenEdData"):
if filename.endswith(".csv"):
@AO8
AO8 / ceasar_cipher.py
Last active October 24, 2024 00:43
A Python Ceasar Cipher to encrypt, decrypt, and brute-force decrypt messages.
import string
def encrypt(text, shift):
encrypted_text = list(range(len(text)))
alphabet = string.ascii_lowercase # 'abcdefghijklmnopqrstuvwxyz'
first_half = alphabet[:shift]
second_half = alphabet[shift:]
shifted_alphabet = second_half + first_half
@AO8
AO8 / gen_ed_counter.py
Last active February 23, 2018 20:22
Python program to analyze data from IE. Quantifies non-IT enrollments generated by BAS-SD for other departments on campus.
# AO8
# February 16, 2018
import csv
import os
import re
def build_csv():
"""iterates through CSV files in directory to create master gen_ed_data.csv"""
rows = []
@AO8
AO8 / word_counter.py
Last active June 26, 2018 16:51
Another (more concise, more Pythonic) frequency word counter using collections.Counter.
# collections.Counter docs at:
# https://docs.python.org/3/library/collections.html#collections.Counter
from collections import Counter
import re
with open("txt_file.txt", "r") as f:
words = re.findall(r"\w+", f.read().lower())
totals = Counter(words).most_common(50) # returns a list of tuples for the 50 most common words and their counts
@AO8
AO8 / seating.py
Last active February 14, 2018 20:45
Model a theater exercise: ways to generate a list of (row, seat) tuples using Python list comprehensions.
# --------
# Option 1
# --------
def create_theater_seats(num_rows, num_seats):
rows = [r for r in range(1, num_rows + 1)]
seats = [s for s in range(1, num_seats + 1)]
theater_seats = [(r,s) for r in rows for s in seats]
return theater_seats
create_theater_seats(2,3)
@AO8
AO8 / index.html
Last active January 29, 2018 15:41
Sample HTML template that includes Google Analytics and jQuery.
<!DOCTYPE html>
<html lang="en">
<head>
<!--Defines the web page's title-->
<title></title>
<!--Defines the character set used-->
<meta charset="utf-8">
<!--Provides a description of your web page-->
<meta name="description" content="">
<!--Defines keywords for search engines-->
@AO8
AO8 / data_structures.py
Last active January 22, 2018 21:19
Quick recipes for implementing Stacks, Queues, and Linked Lists in Python.
# with inspiration from Kojin @ Harvard
class Stack:
"""for creating a LIFO data structure"""
def __init__(self):
self.items = []
def size(self):
return len(self.items)
@AO8
AO8 / dow_jones_csv_tracker.py
Last active January 16, 2018 23:00
Another simple Dow Jones tracker that scrapes a website and writes data to a CSV file using Python 3 and Beautiful Soup.
import urllib.request
import csv
import re
from bs4 import BeautifulSoup
from datetime import datetime as dt
dow_jones_page = "https://www.bloomberg.com/quote/INDU:IND"
html = urllib.request.urlopen(dow_jones_page)
soup = BeautifulSoup(html, "html.parser")