Skip to content

Instantly share code, notes, and snippets.

@Philistino
Philistino / tfidf_match.py
Last active August 4, 2022 10:04
Scikit-lean TFIDF Extraction and KNN (cosine)
def _tf_idf_match(
original: Sequence[str],
lookup: Sequence[str],
k_matches: int = 3,
ngram_range: tuple[int, int] = (3, 3),
) -> tuple[Sequence[str], Sequence[str], list[list[float]], list[list[int]]]:
"""Takes two tuples, returns top `k` matches from `lookup` dataset.
This function does this by:
- Transform the lookup strings into TF-IDF sparse matrix.
- Fit a NearestNeighbours Model to the lookup matrix.
@Philistino
Philistino / philistino_custom_aliases.zsh
Last active May 19, 2023 09:59
custom zsh/bash aliases
# See last successful ssh logins
alias ssh_success = "sudo tail -100000 /var/log/auth.log | grep 'sshd.*Accepted'"
# To add to profile, run command: source ~/.zshrc
#------------------------------------------------------------------------------------------------
# Operating System
#------------------------------------------------------------------------------------------------
# update and upgrade
alias update="sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y"
@Philistino
Philistino / user_input.py
Last active January 17, 2022 10:17
Multiple choice: generic class to convert iterable into multiple choice options and asks for user input via CLI
import re
class UserInputMultiChoice:
"""
gets multiple choice response from user via CLI
Attributes:
message: string to diplay to the user asking for input. Defaults to "User input required. Choose from the following:."
sort_options: bool determining if the options should be sorted alphabetically. Defaults to False.
options_always_included: list of options to alwasy display regardless of other options. Defaults to "Skip" and "Exit."
@Philistino
Philistino / configparser_to_dataclasses.py
Last active August 15, 2021 09:48 — forked from tux-00/configparser_to_dataclasses.py
Converts python config parser to dataclasses (easier access)
import configparser
from dataclasses import dataclass
@dataclass
class Sections:
raw_sections: dict
def __post_init__(self):
for section_key, section_value in self.raw_sections.items():