Skip to content

Instantly share code, notes, and snippets.

View ZechCodes's full-sized avatar
🏄‍♂️
Surfing on a space-time bubble

Zech Zimmerman ZechCodes

🏄‍♂️
Surfing on a space-time bubble
View GitHub Profile
@ZechCodes
ZechCodes / RockPaperScissors.py
Created July 2, 2019 20:49
Really basic rock, paper, scissors CLI game.
from __future__ import annotations
from typing import AnyStr, Callable, Container, Tuple, Union
class Choice:
def __init__(self, name: AnyStr, beats: Choice = None):
self._name = name
self._beats = beats
@property
@ZechCodes
ZechCodes / pil_line_writer.py
Last active December 27, 2022 11:05
Simple class for writing multiline textcentered on a PIL image with even linespacing.
"""
PIL Line Writer
Simple class for writing multiline text centered on an image with even line
spacing.
To use create a line writer object by passing a PIL image object and a padding
value. Then to write text call the LineWriter's text method with the text you
would like centered on the image over multiple lines. It also takes an optional
line height argument which will scale the line heights. Additionally you can
@ZechCodes
ZechCodes / nlp-extract-topics.py
Last active September 25, 2020 01:25
Messing around with NLP and extracting topics.
"""
Messing around with NLP and extracting topics.
It works acceptably. Results are mediocre, many legal texts get categorized as religious. Generally identifies
sports but they often get categorized as hockey. Likely too small of a training set.
Referenced and based heavily on this article
https://towardsdatascience.com/nlp-extracting-the-main-topics-from-your-dataset-using-lda-in-minutes-21486f5aa925
"""
@ZechCodes
ZechCodes / nlp-extract-topics.py
Created July 7, 2019 22:33
Further messing around with NLP and extracting topics, using PoS analysis
"""
Further messing around with NLP and extracting topics.
Built a class for analyzing text to determine topics. It allows for part of speech analysis and has a pipeline for
cleaning the data set. It then uses the Gensim LDA model to determine which words are the topics.
Using the Gensim part of speech analysis to filter out everything but nouns, in conjunction with my previous
lemmatization and stemming I was able to get results that seem much better even with still using only the SKLearn news
group data set.
"""
import csv
import pandas as pd
from functools import reduce
#input below
ranked_fighters = {'Leon Edwards': {'Rank': 7}, 'Rafael Dos Anjos': {'Rank': 16}, 'Walt Harris': {'Rank': 2}, 'Aleksei Oleinik': {'Rank': 9}, 'Juan Adams': {'Rank': 1}, 'Greg Hardy': {'Rank': 4}, 'Dan Hooker': {'Rank': 3}, 'James Vick': {'Rank': 15}, 'Alexander Hernandez': {'Rank': 6}, 'Francisco Trinaldo': {'Rank': 20}, 'Ben Rothwell': {'Rank': 10}, 'Andrei Arlovski': {'Rank': 14}, 'Alex Caceres': {'Rank': 19}, 'Steven Peterson': {'Rank': 11}, 'Irene Aldana': {'Rank': 8}, 'Raquel Pennington': {'Rank': 24}, 'Klidson Abreu': {'Rank': 5}, 'Sam Alvey': {'Rank': 21}, 'Jennifer Maia': {'Rank': 13}, 'Roxanne Modafferi': {'Rank': 22}, 'Ray Borg': {'Rank': 17}, 'Gabriel Silva': {'Rank': 23}, 'Dom Pilarte': {'Rank': 12}, 'Felipe Colares': {'Rank': 26}, 'Jinsoo Son': {'Rank': 18}, 'Mario Bautista': {'Rank': 25}}
all_combinations = [row for row in csv.reader(open("C:/Users/micha/Desktop/Python/Diversification_data.csv", "r"))]
@ZechCodes
ZechCodes / jwt_demo.py
Created April 19, 2020 15:35
Playing with RSA JWTs
import jwt
def create_token(payload, private_key):
return jwt.encode(payload, private_key, algorithm="RS256")
def decode_token(token, public_key, default=None):
try:
return jwt.decode(token, public_key, algorithms="RS256")
@ZechCodes
ZechCodes / challenge-24.md
Created June 10, 2020 23:51
Challenge #24 - Remove Extras

Challenge #24 - Remove Extras

Create a function that takes two arguments: a list and a number. In the list (the first argument), if an element occurs more than N times (the second argument), remove the extra occurrences and return the result.

Examples

delete_occurrences([1, 1, 1, 1], 2) ➞ [1, 1]

delete_occurrences([13, True, 13, None], 1) ➞ [13, True, None]
@ZechCodes
ZechCodes / challeng-25.md
Last active June 12, 2020 08:18
Challenge #25 - Directionally Challenged

Challenge #25 - Directionally Challenged

Suppose you are directionally challenged, and get lost easily. As a result, sometimes you walk in circles or make U-turns. You might take a sub-optimal route. Create a function that returns the difference in length between your path and the optimal path. Both paths reach the same destination.

You start at (0,0) and reach your destination by the end of the input list.

A demonstration

Your route: ["N", "S", "E", "W", "E", "E", "E", "N"]  // 8
Optimal route: ["E", "E", "E", "N"] (or ["N", "E", "E", "E"], etc.) // 4

Challenge # 26 - Do All Bigrams Exist?

You are given an input array of bigrams, and an list of words.

Write a function that returns True if every single bigram from this list can be found at least once in a list of words.

Examples

can_find(["at", "be", "th", "au"], ["beautiful", "the", "hat"]) ➞ True

Challenge #27 - Shift & Multiple Validators

For this task, you will write two validators.

  • Shift Validator: Determines if each element is translated (added or subtracted) by a constant.
  • Multiple Validator: Determines if each element is multiplied by a positive or negative constant.

A few examples to illustrate these respective functions:

Examples