Skip to content

Instantly share code, notes, and snippets.

View Rustam-Z's full-sized avatar
🚀
Hello from Mars!

Rustam Zokirov Rustam-Z

🚀
Hello from Mars!
View GitHub Profile
int call(int rnum){
// rnum is parameter
printf("the num is %d", rnum);
}
int num = 20;
call(num);
// num is argument
@Rustam-Z
Rustam-Z / infinite_sequence.py
Created August 9, 2021 04:53
Makes the infinite sequence using generator.
def infinite_sequence():
"""Makes the infinite sequence with Python generator.
"""
num = 0
while True:
yield num
num += 1
def print_return_type(func):
# Define wrapper(), the decorated function
def wrapper(*args, **kwargs):
# Call the function being decorated
result = func(*args, **kwargs)
print('{}() returned type {}'.format(
func.__name__, type(result)
))
return result
# Return the decorated function
@Rustam-Z
Rustam-Z / counter.py
Created August 9, 2021 10:37
Counting how many times function was called
def counter(func):
def wrapper(*args, **kwargs):
wrapper.count += 1
# Call the function being decorated and return the result
return func(*args, **kwargs)
wrapper.count = 0
# Return the new decorated function
return wrapper
# Decorate foo() with the counter() decorator
@Rustam-Z
Rustam-Z / doc_string.py
Last active August 9, 2021 10:44
How to write docstrning of Python function.
# Docstring - Google style
def function(arg_1, arg_2=42, some_function):
"""Descriptioin of what this function does.
Args:
arg_1 (str): Description of arg_1.
(The string to search).
arg_2 (int, optional): Write optional when
argument has default value.
some_function (callable): The function we want a tooltip for.
@Rustam-Z
Rustam-Z / timer.py
Last active August 9, 2021 10:57
A decorator that prints how long a function took to run.
import time
from functools import wraps
def timer(func):
"""A decorator that prints how long a function took to run."""
@wraps(func)
def wrapper(*args, **kwargs):
# When wrapper() is called, get the current time.
t_start = time.time()
@Rustam-Z
Rustam-Z / memorize.py
Last active August 9, 2021 10:59
Store the results of the decorated function for fast lookup
from functools import wraps
def memorize(func):
"""Store the results of the decorated function for fast lookup """
# Store results in a dict that maps arguments to results
cache = {}
@wraps(func)
def wrapper(*args, **kwargs):
@Rustam-Z
Rustam-Z / html_generator.py
Last active August 9, 2021 12:01
Project: HTML generator with Python decorator
"""Project: HTML Generator
With the new html() decorator you can focus on
writing simple functions that return the
information you want to display on the webpage
and let the decorator take care of wrapping them
in the appropriate HTML tag.
"""
def html(open_tag, close_tag):
def decorator(func):
@wraps(func)
@Rustam-Z
Rustam-Z / minikube.md
Created November 30, 2021 06:23 — forked from rahulkumar-aws/minikube.md
Install/Uninstall Minikube from Mac
minikube stop; minikube delete
docker stop $(docker ps -aq)
rm -r ~/.kube ~/.minikube
sudo rm /usr/local/bin/localkube /usr/local/bin/minikube
systemctl stop '*kubelet*.mount'
sudo rm -rf /etc/kubernetes/
docker system prune -af --volumes
import os
import sys
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))