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 / menu_launcher.py
Created May 22, 2016 19:15 — forked from abishur/menu_launcher.py
A simple menu system using python for the Terminal (Framebufer)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.com/2010/03/python-curses-custom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code :-)
# Basic code refactoring by Andrew Scheller
from time import sleep
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho() # Disables automatic echoing of key presses (prevents program from input each key twice)
#!python3
import requests
from urllib.parse import quote
from prettytable import PrettyTable
def measure(user, MAX_XP, MAX_LVL, MAX_ELITE_XP):
SKILL_NAMES = ["Total level", "Attack", "Defence", "Strength", "Constitution",
"Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching",
"Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
"Herblore", "Agility", "Thieving", "Slayer", "Farming",
@echo off
rem Define a (local) name for the temporary file
setlocal
set temp="tmp.txt"
rem Copy the list of outdated modules to a text file
call pip list --outdated > %temp%
rem Process the text file to only contain module names
@Diapolo10
Diapolo10 / main.py
Last active August 30, 2019 07:55
Python range-function example definition
#!/usr/bin/env python3
from typing import Generator, Optional
from numbers import Real
def my_range(start: Real, stop: Optional[Real]=None, step: Real=1) -> Generator[Real, None, None]:
""" An example definition of Python 3's range-class as a function """
# If only one argument was provided, use that
# argument as the goal and set start to 0
@Diapolo10
Diapolo10 / four_fours.py
Last active January 19, 2020 13:51
A general solution for the four fours problem
# log(log(sqrt(4), 4), (sqrt(4)/4)) == 1
import math
def repeat(func, n):
x = 4
for _ in range(n):
x = func(x)
return x
@Diapolo10
Diapolo10 / main.py
Last active September 7, 2020 16:56
Python print-function mock-up
import sys
from typing import TextIO
def my_print(*args: list, file: TextIO=sys.stdout, sep: str=' ', end: str='\n', flush: bool=False) -> None:
"""
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
@Diapolo10
Diapolo10 / caesar_cipher.py
Last active February 3, 2021 12:38
Caesar cipher
#!/usr/bin/env python3
# Written by Lari Liuhamo
import string
from typing import Generator
def caesar_cipher(message: str, shift: int, alphabet=string.ascii_uppercase) -> str:
"""
Performs the Caesar cipher on a given message (string) by shifting all characters using the given shift.
@Diapolo10
Diapolo10 / rsa.py
Last active February 15, 2021 17:54
RSA implementation
#!/usr/bin/env python3
from typing import List
class RSAConfig:
def __init__(self, p, q, e, d):
self.p = p
self.q = q
self.n = p * q
self.phi = (p-1) * (q-1)
self.e = e
@Diapolo10
Diapolo10 / rsa_pq_bruteforce.py
Created February 15, 2021 20:08
RSA prime pair bruteforce searcher
#!/usr/bin/env python3
from typing import Optional, List, Generator
def prime_gen(limit: Optional[int]=None) -> Generator[int, None, None]:
"""Generates prime numbers with an optional upper limit"""
primes = [2]
n = 3
while limit is None or limit >= n:
for prime in primes:
@Diapolo10
Diapolo10 / map.py
Last active February 20, 2021 17:39
Python map-function example implementation
#!/usr/bin/env python3
from typing import Any, Callable, Generator, Iterable, List
def my_map(func: Callable[[Any, ...], Any], *iterables: List[Iterable[Any]]) -> Generator[Any, None, None]:
"""
Mimics the built-in map function, accepting any number of iterables
and yielding values returned by the given function.
"""