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 asyncio | |
from pyppeteer import launch | |
async def main(): | |
browser = await launch() | |
page = await browser.newPage() | |
await page.goto('http://example.com') | |
await page.screenshot({'path': 'example.png', 'fullPage': 'true'}) | |
await browser.close() |
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
Простые свойства CSS могут помочь. Ниже приведено трехстрочное многоточие. | |
display: -webkit-box; | |
-webkit-line-clamp: 3; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
text-overflow: ellipsis; |
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
files = {'upload_file': open('file.txt','rb')} | |
values = {'DB': 'photcat', 'OUT': 'csv', 'SHORT': 'short'} | |
r = requests.post(url, files=files, data=values) |
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
# Удалить словарь из списка: | |
thelist[:] = [d for d in thelist if d.get('id') != 2] | |
# Используя синтаксис thelist[:], мы можем сохранить ссылку на исходный список и избежать создания нового списка. | |
# Это может быть полезно, если переменная thelist уже используется в других частях кода, и вы хотите обновить ее содержимое. |
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
with open('list.txt') as file: | |
self.lines = [line.rstrip() for line in file.readlines()] |
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
# Empty strings are "falsy" (python 2 or python 3 reference), | |
# which means they are considered false in a Boolean context, so you can just do this: | |
if not myString: |
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
// Старый подход... | |
class Person { | |
private first_name: string; | |
private last_name: string; | |
private age: number; | |
private is_married: boolean; | |
constructor(fname:string, lname:string, age:number, married:boolean) { | |
this.first_name = fname; | |
this.last_name = lname; |
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
(function(console) { | |
console.save = function(data, filename){ | |
if(!data) { | |
console.error('Console.save: No data') | |
return; | |
} | |
if(!filename) filename = 'console.html' | |
if(typeof data === "object"){ | |
data = JSON.stringify(data, undefined, 4) | |
} |
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
context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) | |
context.set_font_size(52.0) | |
(x, y, width, height, dx, dy) = context.text_extents("Hello") | |
context.move_to(WIDTH/2. - width/2., HEIGHT/2. + height/2.) | |
context.show_text("Hello") | |
""" | |
Указанный код рисует текст "Hello" по центру холста, выравнивая его горизонтально и вертикально |
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
# A better practice is to inherit Signal from str: | |
class Signal(str, Enum): | |
red = 'red' | |
green = 'green' | |
orange = 'orange' | |
brain_detected_colour = 'red' | |
brain_detected_colour == Signal.red # direct comparison |