Skip to content

Instantly share code, notes, and snippets.

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

ReSampled pointofpresence

🏠
Working from home
View GitHub Profile
@pointofpresence
pointofpresence / pyppeteer screenshot.py
Last active March 31, 2024 18:55
Скриншот страницы с помощью pyppeteer
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()
@pointofpresence
pointofpresence / three line clamp.css
Last active March 31, 2024 18:23
Ограничение многоточием до трех строк текста
Простые свойства CSS могут помочь. Ниже приведено трехстрочное многоточие.
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
@pointofpresence
pointofpresence / send_file_via_post.py
Last active March 31, 2024 11:41
Загрузка файла на сервер методом POST и передача дополнительных полей
files = {'upload_file': open('file.txt','rb')}
values = {'DB': 'photcat', 'OUT': 'csv', 'SHORT': 'short'}
r = requests.post(url, files=files, data=values)
@pointofpresence
pointofpresence / filter list.txt
Last active March 31, 2024 20:39
Python: Удалить словарь из списка по значению ключа
# Удалить словарь из списка:
thelist[:] = [d for d in thelist if d.get('id') != 2]
# Используя синтаксис thelist[:], мы можем сохранить ссылку на исходный список и избежать создания нового списка.
# Это может быть полезно, если переменная thelist уже используется в других частях кода, и вы хотите обновить ее содержимое.
@pointofpresence
pointofpresence / lines2list.py
Created May 30, 2022 09:31
Read file line by line to list
with open('list.txt') as file:
self.lines = [line.rstrip() for line in file.readlines()]
@pointofpresence
pointofpresence / check_is_string_empty.py
Last active June 13, 2022 15:41
Check if string empty
# 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:
@pointofpresence
pointofpresence / argumentsToProperties.ts
Last active June 14, 2022 13:15
TypeScript: Constructor arguments to class properties
// Старый подход...
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;
@pointofpresence
pointofpresence / saveFromConsole2file.js
Last active June 13, 2022 15:53
console.save(data, filename) - save object to file from console
(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)
}
@pointofpresence
pointofpresence / cairo_text_centered.py
Last active March 31, 2024 14:00
Python: Текст по центру холста (Cairo)
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" по центру холста, выравнивая его горизонтально и вертикально
@pointofpresence
pointofpresence / enum_with_strings.py
Last active June 14, 2022 13:41
Python: Enum with strings
# 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