This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ven bash | |
# Finding the total duration of all the videos | |
# in the local Videos directory by default | |
# or in the directory passed as the first parameter | |
folder="${1:-$HOME/Videos}" | |
[ -d "$folder" ] || { echo "Folder not found: $folder" >&2; exit 1; } | |
echo "Calculating total video duration in $folder" >&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
def get_max_height(skyline:numpy.ndarray) -> int: | |
'''Returns the maximum height of a continuous sequence | |
of true values in a 2D array, starting from the bottom''' | |
mask = True | |
return sum(any(mask := row & mask) | |
for row in reversed(skyline.astype(bool))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python >= 3.8 | |
assert (sys.version_info.major == 3 and | |
sys.version_info.minor >= 8) | |
from math import log | |
def convert(num:int, base=3) -> list: | |
'''Return a list of "digits" representing num in the given base, | |
ordered from lower to higher positions''' | |
width, num = int(1 + log(num, base)), (num,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
from pprint import pprint | |
import numpy as np | |
# Idea borrowed from the video https://youtu.be/G_UYXzGuqvM | |
# and implemented in a kind of numpyish way | |
# | |
# TODO: 1) how can I use numpy.lib.stride_tricks.sliding_window_view | |
# or something like that to solve the task? | |
# 2) get rid of the array SOLUTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Check whether we can obtain names for the control characters | |
# with the unicodedata.name method in python | |
curl --silent 'https://www.unicode.org/Public/13.0.0/ucd/NameAliases.txt' |\ | |
sed '/^\ *$/d; /^#.*/d' |\ | |
python -c ' | |
import unicodedata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# pydoc_grep <keyword> | |
# Grep for the keyword through the pydoc's topics | |
keyword="${1:?Give me a keyword to look for as a first parameter}" | |
python -m pydoc 'topics' | awk '/^[A-Z ]+$/ {for (i=1; i<=NF; i++) print $i}' | { | |
unset found | |
while read topic; do | |
python -m pydoc "$topic" | grep --ignore-case "$keyword" > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from signal import SIGINT, signal | |
from time import sleep | |
import pickle | |
def load(store): | |
try: | |
with open(store, 'br') as f: | |
start = pickle.load(f) | |
except Exception: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In the programm my_app.py we only import | |
# the module "test.py" from the folder "modules" | |
import modules.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logo = """ | |
____ _ _ _ _ | |
/ ___|_ _ ___ ___ ___ __ _ | \ | |_ _ _ __ ___ | |__ ___ _ __| | | |
| | _| | | |/ _ \/ __/ __| / _` | | \| | | | | '_ ` _ \| '_ \ / _ \ '__| | | |
| |_| | |_| | __/\__ \__ \ | (_| | | |\ | |_| | | | | | | |_) | __/ | |_| | |
\____|\__,_|\___||___/___/ \__,_| |_| \_|\__,_|_| |_| |_|_.__/ \___|_| (_) | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://replit.com/@winetoxin/Winetoxins-Simple-Calculator | |
from operator import add, sub, mul, truediv | |
operations = {"+": add, "-": sub, "*": mul, "/": truediv} | |
intro = "Welcome to the Winetoxin's Python Project!!!" | |
decoration = '-+-' | |
border = decoration * (len(intro)//len(decoration)) + decoration[:len(intro)%len(decoration)] |
NewerOlder