Skip to content

Instantly share code, notes, and snippets.

View andgineer's full-sized avatar
💭
Andrey Sorokin, engineer

Andrey Sorokin andgineer

💭
Andrey Sorokin, engineer
View GitHub Profile
@andgineer
andgineer / wpstest.ino
Created September 14, 2017 12:00 — forked from copa2/wpstest.ino
Example for WPS connection with https://github.com/esp8266/Arduino
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
delay(1000);
Serial.printf("\nTry connecting to WiFi with SSID '%s'\n", WiFi.SSID().c_str());
WiFi.mode(WIFI_STA);
WiFi.begin(WiFi.SSID().c_str(),WiFi.psk().c_str()); // reading data from EPROM, last saved credentials
while (WiFi.status() == WL_DISCONNECTED) {
@andgineer
andgineer / conftest.py
Created March 20, 2019 17:37
Python allure pytest automatic Selenium webdriver screenshot
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
if rep.when == 'call' and rep.failed:
mode = 'a' if os.path.exists('failures') else 'w'
try:
with open('failures', mode) as f:
if 'browser' in item.fixturenames:
web_driver = item.funcargs['browser']
@andgineer
andgineer / bash_wait_with_timeout_for_string.sh
Last active October 21, 2019 10:03
wait for specific string from application with timeout
timeout -k 1s --preserve-status 0.5s \
perl -e '$|++; print "bla-bla\n"; sleep(2); print "The end."' \ # placeholder for you process
| perl -pe 'END { exit $status } $status=1; if (/end/) {$status=0; exit;}'
# see explanation in andrey.engineer/posts/en/bash_wait_with_timeout_for_string.html
@andgineer
andgineer / activate
Created February 25, 2020 08:09
Python virtual environment create and activate
#!/usr/bin/env bash
#
# "Set-ups or/and activates development environment"
#
VENV_FOLDER="venv"
PYTHON="python3.7"
RED='\033[1;31m'
GREEN='\033[1;32m'
@andgineer
andgineer / flatit
Last active April 23, 2020 03:21
Flat it! Copies files from subfolders
find ./ -iname "*.mp3" -type f -exec sh -c 'cp $0 "$(basename -- $(dirname -- $0))_$(basename -- $0)"' {} \;
@andgineer
andgineer / .bashrc
Created March 26, 2020 10:15
Adding credentials to GIT remote
function gitcred () {
rep_uri=$(git config --get remote.origin.url)
rep_proto=${rep_uri:0:8}
rep_url=${rep_uri:8}
user_name=$1
user_name=${user_name:-andgineer}
user_psw=$2
user_psw=${user_psw:-???}
uri=$rep_proto$user_name:$user_psw@${rep_url#*@}
@andgineer
andgineer / universal_decorator.py
Last active April 9, 2020 11:15
Python decorator class that works for standalone functions and for object methods
class UniversalDecorator:
""" Good for standalone functions as well as for object methods """
def __init__(self, orig_func):
self.orig_func = orig_func
def __call__(self, *args):
""" For standalone function decoration """
return self.orig_func(*args)
def __get__(self, wrapped_instance, owner):
@andgineer
andgineer / conftest.py
Last active May 23, 2020 05:52
pytest fixture for test data file
from distutils import dir_util
import pytest
import os.path
from pathlib import Path
@pytest.fixture
def data_path(tmpdir, request) -> Path:
"""
If in the same folder as the test module exists a sub folder with the name
class EnumType(BaseType):
"""
Converts Python Enum into the string.
"""
primitive_type = str
native_type = enum.Enum
MESSAGES = {
'convert': ("Couldn't interpret '{0}' value as Enum."),
'find': 'Couldnt find {value} in {choices}'
@andgineer
andgineer / __init__.py
Created June 9, 2020 10:57
Python: imports all symbols from all modules in the package
"""
Imports all symbols from all modules in the package
"""
from pathlib import Path
from importlib import import_module
for module_path in Path(__file__).parent.glob('*.py'):
if module_path.is_file() and not module_path.stem.startswith('_'):
module = import_module(f'.{module_path.stem}', package=__package__)