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
# Дан отсортированный массив чисел. Нужно вернуть отсортированный массив квадратов этих чисел. | |
# Ограничение по сложности O(n) | |
# Диапазон чисел не ограничен | |
from pytest import mark | |
def index_of_min_abs(numbers): | |
''' Return index of minimal abs element | |
''' |
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 csv | |
def write_csv(filename, lines): | |
with open(filename, 'wt', newline='') as f: | |
csvout = csv.DictWriter(f, ('author', 'book')) | |
csvout.writeheader() | |
csvout.writerows(lines) | |
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 insert_sort(array): | |
''' |
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 save_report_to_csv(content, filename='report.csv'): | |
with open(filename, 'w', newline='') as f: | |
fieldnames = ('filename', 'time') | |
writer = csv.DictWriter(f, fieldnames=fieldnames) | |
writer.writeheader() | |
for item in content: | |
writer.writerow({'filename': item[0], 'time': item[1]}) |
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
const MAX_PASSWORD_BLOCK_SIZE = 3* 1024; | |
const MAX_PASSWORD_LENGTH = 128; | |
const CHARSET_OPTIONS = 'upper,lower,numbers,special'; | |
function randomInt(max, min = 0) { | |
return Math.floor(min + Math.random() * (max - min)); | |
} | |
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 sqlite3 | |
DB_SCHEME = '''CREATE TABLE IF NOT EXISTS stories | |
(author TEXT, | |
categories TEXT, | |
endpoint TEXT, | |
title TEXT) | |
''' |
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
const fs = require('fs'); | |
const Papa = require('papaparse'); // https://www.papaparse.com/ | |
async function readCSVFile(filepath) { | |
return new Promise((resolve, reject) => { | |
Papa.parse(fs.ReadStream(filepath), { | |
complete: (results) => resolve(results.data), | |
error: (err) => reject(err) | |
}); |
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
const fs = require('fs'); | |
const Papa = require('papaparse'); // https://www.papaparse.com/ | |
function readCSVFile(filepath, cb) { | |
Papa.parse(fs.ReadStream(filepath), { | |
complete: (results, file) => cb(null, results.data, file), | |
error: (err, file) => cb(err, null, file) | |
}); | |
} |
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
const urlresolve = require('url').resolve; | |
const needle = require('needle'); | |
class Site { | |
constructor(mainPageUrl, cookies) { | |
const PHPSESSID = 'PHPSESSID'; | |
if (!(PHPSESSID in cookies)) { | |
throw new Error('PHP Session ID not found'); | |
} | |
this.phpsessid = cookies[PHPSESSID]; |