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 redis import Redis | |
import string | |
import random | |
from time import sleep | |
def random_message_generate(length=100): | |
message = ''.join([random.choice( | |
string.ascii_letters + string.digits) for n in range(length)]) | |
return message |
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
def timer(func): | |
def tmp(*args, **kwargs): | |
t = time.time() | |
res = func(*args, **kwargs) | |
print("f time - {} {}".format(str(time.time()-t), f.__name__, )) | |
return res | |
return tmp |
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
def kangaroo(input_str): | |
""" для решения задачи необходимо решить уравнение: | |
x1 + y * v1 = x2 + y * v2, так же проверим условия, | |
и проверим крайние уникальные условия, при которых | |
возникает деление на 0: v2 == v1""" | |
input_list = input_str.split() | |
x1, v1, x2, v2 = map(int, input_list) | |
if x1 < 0 or x1 > x2 or x2 > 10000 or\ | |
v1 < 1 or v1 > 10000 or\ | |
v2 < 1 or v2 > 10000: |
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 itertools | |
def get_data(file_name): | |
"""generator to yield file row by row | |
for not upload it to memory""" | |
with open(file_name, encoding='Windows-1251') as f: | |
rows = f.readlines() | |
for row in rows: | |
yield (row) |
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
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
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
# !/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from email.parser import Parser | |
import syslog | |
import email | |
import base64 | |
import ldap | |
import sys | |
import argparse | |
import os |
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
def decorator(arg1, arg2): | |
def real_decorator(function): | |
def wrapper(*args, **kwargs): | |
print("Congratulations. You decorated a " | |
"function that does something with %s and %s" % (arg1, arg2)) | |
for obj in args: # это список | |
print('hello: {}'.format(obj)) | |
for key, value in kwargs.items(): # это словарь | |
print('key={}, value={}'.format(key, value)) | |
function(*args, **kwargs) |
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
static private int NumberSum(int number) | |
{ | |
int sum = 0; | |
while(number != 0) | |
{ | |
sum += number % 10; | |
number /= 10; | |
} | |
return sum; | |
} |
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
# -*- coding: utf-8 -*- | |
from collections import defaultdict, OrderedDict | |
PINGDROP = OrderedDict([ | |
('- первичный пинг локальных сокетов', ['ping', '-i', '0.2', '-w', '1', '127.0.0.1']), | |
( | |
'установка правила для блокировки icmp пакетов идущих на локальные сокеты', | |
['iptables', '-I', 'INPUT', '-s', '127.0.0.1', '-p', 'icmp', '-j', 'DROP'] | |
), |
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 socket | |
import sys | |
import os | |
import json | |
import time | |
server_address = './uds_socket.s' | |
# Make sure the socket does not already exist |
OlderNewer