Skip to content

Instantly share code, notes, and snippets.

View Diapolo10's full-sized avatar
🏠
Working from home

Lari Liuhamo Diapolo10

🏠
Working from home
View GitHub Profile
@Diapolo10
Diapolo10 / hangman.py
Last active September 15, 2024 17:35 — forked from sheebydeeby/hangman.py
from getpass import getpass
def print_line(line_count: int = 1) -> None:
"""Print a number of newlines."""
print('\n' * line_count, end='')
def ask_guess(used: list[str], answer: list[str]) -> str:
while True:
@Diapolo10
Diapolo10 / linked_list.py
Last active December 5, 2023 19:26
[Python] Linked List
from __future__ import annotations
from collections.abc import Callable
from typing import Any
class Node:
def __init__(self, value: object):
self.value = value
self.next_node: Node | None = None
@Diapolo10
Diapolo10 / main.py
Last active September 14, 2023 01:07
[Python] Flexible Tic Tac Toe
"""Tic-Tac-Toe implementation"""
from typing import Literal, get_args
# Custom type annotations
PlayerSymbol = Literal['X', 'O']
BoardSymbol = Literal[' ', PlayerSymbol]
Board = list[list[BoardSymbol]]
BOARD_WIDTH = 3
@Diapolo10
Diapolo10 / main.py
Created January 10, 2023 17:07
Powerball Lottery Simulator
"""Powerball Lottery Simulator"""
import json
import random
POSSIBLE_WHITE_VALUES = range(1, 70)
POSSIBLE_RED_VALUES = range(1, 27)
WHITE_DRAWS = 5
RED_DRAWS = 1
@Diapolo10
Diapolo10 / powers_of_2.py
Created September 22, 2022 14:03
[Python] Powers of 2
"""
Experimenting with the Powers of 2 problem
https://www.youtube.com/watch?v=IPoh5C9CcI8
"""
import itertools
from math import log2
def is_power_of_2(num: int) -> bool:
@Diapolo10
Diapolo10 / config.py
Last active December 8, 2022 00:02
Hangman example
LOGO = """
_
| |
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
| | | | (_| | | | | (_| | | | | | | (_| | | | |
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
__/ |
|___/
"""
@Diapolo10
Diapolo10 / line_stickers.py
Last active May 20, 2022 14:24
LINE Sticker Downloader
#!/usr/bin/env python3
"""Downloads sticker images from the LINE store"""
from pathlib import Path
import requests
DESTINATION = Path.home() / 'line_stickers'
IMAGE_ID_RANGE = range(345806894, 345806934) # Default: Kemomimi set 1
@Diapolo10
Diapolo10 / my_enumerate.py
Last active March 2, 2022 10:50
Python enumerate-function example implementation
from typing import Generator, Iterable, T, Tuple
def my_enumerate(iterable: Iterable[T], start: int=0) -> Generator[Tuple[int, T], None, None]:
"""
Mimics the built-in enumerate-function, accepting any iterable,
and yielding incremented indices and values from it.
"""
idx = start
for value in iterable:
@Diapolo10
Diapolo10 / example.py
Last active February 11, 2022 19:00
Python style guide example
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# The above two lines specify two things. The order must always be the same if both are used.
# The first line is a shebang, used by Unix-like systems to determine how to run a file.
# The second is a way to specify the encoding used by the file.
# Neither are necessary, especially the second one, since Python 3 is UTF-8 by default.
"""
@Diapolo10
Diapolo10 / my_zip.py
Created December 15, 2021 15:25
Python zip-function example implementation
from typing import Any, Callable, Generator, Iterable, List
def my_zip(*iterables: List[Iterable[Any]]) -> Generator[List[Any], None, None]:
"""
Mimics the built-in zip function, accepting any number of iterables
and yielding values from all of them until one or more are exhausted.
"""
iterators = [iter(iterable) for iterable in iterables]