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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / text width.js
Last active March 31, 2024 18:48
Получение ширины строки текста
function getTextWidth() {  
text = document.createElement("span");
document.body.appendChild(text);
text.style.font = "times new roman";
text.style.fontSize = 16 + "px";
text.style.height = 'auto';
text.style.width = 'auto';
text.style.position = 'absolute';
text.style.whiteSpace = 'no-wrap';
@pointofpresence
pointofpresence / colored_svg_icon.jsx
Last active March 31, 2024 13:50
Чтобы установить цвет иконки, указанный в пропсе color, в SVG-файле lock.svg, к тегу <svg> добавляется атрибут fill="currentColor". Значение currentColor означает, что цвет будет взят из текущего контекста, в данном случае он будет взят из переданного цвета color для компонента LockIcon. Таким образом, в итоге, иконка будет отображена с цветом, …
import LockIcon from "../assets/lock.svg"
// and then render it as:
<LockIcon color={theme.colors.text.primary} />
// and then in lock.svg I just add fill="currentColor" in the svg tag.
/*
Чтобы установить цвет иконки, указанный в пропсе color, в SVG-файле lock.svg, к тегу <svg> добавляется атрибут
fill="currentColor". Значение currentColor означает, что цвет будет взят из текущего контекста, в данном случае
он будет взят из переданного цвета color для компонента LockIcon. Таким образом, в итоге, иконка будет отображена
@pointofpresence
pointofpresence / color functions.py
Last active March 31, 2024 19:05
python color functions
import math
# Function to Parse Hexadecimal Value
def parse_hex_color(string):
if string.startswith("#"):
string = string[1:]
r = int(string[0:2], 16) # red color value
g = int(string[2:4], 16) # green color value
b = int(string[4:6], 16) # blue color value