Skip to content

Instantly share code, notes, and snippets.

View zztalker's full-sized avatar
🏠
Working from home

Pavel Zaikin zztalker

🏠
Working from home
View GitHub Profile
<testsuites><testsuite name="pytest" errors="0" failures="1" skipped="28" tests="153" time="3212.329" timestamp="2022-04-27T17:14:08.246020" hostname="vm-id-3946681"><testcase classname="Ubuntu20_plesk_500_users_1.test_app_specific_ruleset" name="test_conflict_raised_when_server_not_supported" file="test_app_specific_ruleset.py" line="206" time="1.389"><skipped type="pytest.skip" message="Server supported">/vagrant/test_app_specific_ruleset.py:207: Server supported</skipped></testcase><testcase classname="Ubuntu20_plesk_500_users_1.test_app_specific_ruleset" name="test_not_setup_wordpress_fails" file="test_app_specific_ruleset.py" line="237" time="32.570" /><testcase classname="Ubuntu20_plesk_500_users_1.test_app_specific_ruleset" name="test_wordpress_up_and_running" file="test_app_specific_ruleset.py" line="251" time="17.228" /><testcase classname="Ubuntu20_plesk_500_users_1.test_blocked_ports" name="TestBlockedPorts.test_input_outgoing[udp]" file="test_blocked_ports.py" line="327" time="19.973" /><testcase
@zztalker
zztalker / multi-lock.py
Created March 24, 2021 05:15
asyncio locks with timeout
""" $ python3 multi-lock.py
I'm 1 and want to lock, wait no more than 1 sec
I'm 2 and want to lock, wait no more than 1 sec
I'm 3 and want to lock, wait no more than 1 sec
I'm 4 and want to lock, wait no more than 1 sec
I'm 5 and want to lock, wait no more than 1 sec
I'm 6 and want to lock, wait no more than 1 sec
I'm 7 and want to lock, wait no more than 1 sec
I'm 8 and want to lock, wait no more than 1 sec
I'm 9 and want to lock, wait no more than 1 sec
import time
import win32gui as w
import win32con as wc
import win32process as wp
TRACK_MODE, RESTRICT_MODE = "TRACK", "RESTRICT"
while True:
handle = w.GetForegroundWindow()
  • Python 3.6.9
pz@asus:~/snippets/urllib-timeout $ python3 urllib_check.py
Test server send bytes at one moment, with timeout 1.
b'1234567890'
Duration: 0.0029508500010706484
Test server send 1 byte per 0.5 sec, with timeout 1.
b'1234567890'
Duration: 13.017826942999818
Test server send 1 bytes per 2 sec for total 10 bytes (56 sec long), with timeout 10.
@zztalker
zztalker / 3d_plot.py
Created June 18, 2018 12:01
3d_plot.py
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(1, 9, 1)
print(X)
@zztalker
zztalker / data_diff.py
Last active May 31, 2018 05:53
Get a date up to N days from the date you entered
import datetime
s = input("Date in format yyyy\mm\dd: ").split("\\")
d = datetime.date(int(s[0]),int(s[1]),int(s[2]))
N = input("Diff days: ")
print(d+datetime.timedelta(days=int(N)))
@zztalker
zztalker / flask_decorator_to_view.py
Last active January 8, 2017 09:14
How to make own decorator to view in Flask
from functools import wraps
def islogged(func):
# нужен декоратор на декорируемую функцию, т.к. app.route - составляет таблицу view - и ему нужны уникальные ссылки на функции.
# Если не добавить подобный декоратор, то ссылки будут одинаковые - на функцию decorated_view
# wraps - использует создание экземпляра объекта partial - (каждый экземпляр обладает уникальной ссылкой и ведёт себя как функция)
# https://docs.python.org/3/library/functools.html#functools.partial
@wraps(func)
def decorated_view(*args, **kwargs):
if not session.get('logged_in'):
<form>
<input type="button" value="В корзину"
onclick="myajax('{{=URL('ajax_addbasket')}}','target')"/>
<input type="hidden" id="senddata" name="senddata" value=""/>
</form>
<script>
function myajax(u,t) {
var trList = jQuery(".clickedRow")
//var table = document.getElementById('idWalkTable');
def ajax_addbasket():
# получаем данные из пост заспроса, для Flask request.forms
s = request.vars.senddata.split(",")
qRec = 0
for doc in s:
if len(doc)!=0:
db.basket.insert(doc_id = doc, userid = session.auth.user.id)
qRec += 1
#print u"Успешно добавлено "+str(qRec)+" записей"
qRecStr = str(qRec)
@zztalker
zztalker / load.py
Created January 7, 2017 16:33
example
s = file.readline()
for e in file.readlines():
l = e.split('\t')
row = db.docs(doc_id=l[0])
if not row:
db.docs.insert(doc_id=l[0],type_doc1=l[1],type_doc2=l[2],type_doc3=l[3],
surname1 = l[4], name1 = l[5], patronymic1 = l[6],
surname2 = l[7], name2 = l[8], patronymic2 = l[9])
rec = db.doc_status.insert(doc_id=l[0],status=l[10],status_ex=l[11],date_change=l[12])
else: