Skip to content

Instantly share code, notes, and snippets.

View Farrukhraz's full-sized avatar
🎯
Focusing

Farrukh Razikov Farrukhraz

🎯
Focusing
View GitHub Profile
@Farrukhraz
Farrukhraz / Python 3 or 2?
Created June 2, 2020 17:27
do this if python3, elif python2 do this
if sys.version_info.major == 2:
BaseStrType_ = basestring
else:
BaseStrType_ = str
import platform
import logging
from logging.handlers import RotatingFileHandler
class ConsoleLogger:
handlers = [
(logging.StreamHandler,
dict(),
logging.DEBUG),
generateDS.py -o scenario.py -f --super=scenario C:\path\to\file\Scenario.xsd
# Если нужен сабмодуль (не нужная вещь)
generateDS.py -o scenario.py -s scenariosubs.py -f --super=scenario C:\path\to\file\Scenario.xsd
@Farrukhraz
Farrukhraz / pickle
Last active May 21, 2020 09:55
Object to binary file and reverse
import pickle
with open('data.pickle', 'wb') as f:
pickle.dump(old_data, f, pickle.HIGHEST_PROTOCOL)
with open(r'C:\path\to\file.pkl', 'rb') as f:
new_data = pickle.load(f)
@Farrukhraz
Farrukhraz / @debug
Last active May 10, 2020 16:51
All given functions (decorators) should be in the separate module: decorators.py; Thnks for this article "https://proglib.io/p/vse-chto-nuzhno-znat-o-dekoratorah-python-2020-05-09#dark-theme-toggler"
import functools
def debug(func):
@functools.wraps(func)
def wrapper_debug(*args, **kwargs):
args_repr = [repr(a) for a in args]
kwargs_repr = [f"{k}={v!r}" for k, v in kwargs.items()]
signature = ", ".join(args_repr + kwargs_repr)
print(f"Вызываем {func.__name__}({signature})")
value = func(*args, **kwargs)
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
@Farrukhraz
Farrukhraz / time
Last active May 4, 2020 08:01
Current time
from datetime import datetime
datetime.now().strftime('%Y-%m-%d %H:%M:%S')
import importlib
import sys
robot_folder_path = r'full\path\to\folder\with\packages'
module_name = 'PackageName'
file_path = f'{robot_folder_path}\\{module_name}\\__init__.py'
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
@Farrukhraz
Farrukhraz / 2nd homework
Last active April 19, 2021 17:49
bash commands
1.
ls -la /etc
ls -la /proc
ls -la /home
___________________________________________
2.
cat - в основном служит для чтения файла и объяденения содержимого нескольких файлов в один.
cat /etc/adduser.conf > file1
@Farrukhraz
Farrukhraz / git_commands.txt
Last active May 22, 2020 21:49
Git commands
git config --global user.name [name] # set up user name
git config --global user.email [email] # set up user email
git config --global color.ui auto # if git command returns error msg. Msg will be highlighted red
git init # initialize repo
git remote add origin https://github.com/Farrukhraz/folder.git # synchronize local and remote repo's
git remote -v # check if synchronization is done
git status # current status
git add . # to include in what will be commited