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 / overloads.ts
Last active March 31, 2024 18:22
TS: Перегрузка функций
// Overloads
function conv(a: string): number;
function conv(a: number): string;
function conv(a: string | number): string | number {
// ...
}
@pointofpresence
pointofpresence / nullish_coalescing_operator.js
Last active March 31, 2024 13:33
JS: Оператор объединения с null (??=)
let a;
let b = 0;
// assign a value only if current value is null or undefined
a ??= 'default'; // a is now 'default'
b ??= 5; // b is still 0
@pointofpresence
pointofpresence / operator_&&=.js
Last active March 31, 2024 12:32
Оператор &&= используется для присваивания значения переменной только в том случае, если текущее значение переменной является «истинным» (не false, 0, NaN, null, undefined или пустой строкой).
let a;
let b = 1;
// assign a value only if current value is truthy
a &&= 'default'; // a is still undefined
b &&= 5; // b is now 5
@pointofpresence
pointofpresence / TS tuples.js
Last active March 31, 2024 20:44
TS: Кортежи
Basic tuples
let myTuple: [ string, number, boolean? ];
myTuple = [ 'test', 42 ];
@pointofpresence
pointofpresence / index types.ts
Last active March 31, 2024 14:44
Индексные типы позволяют определить тип данных для ключей объекта, которые могут быть строками, числами, символами или определенным шаблоном строк.
// Object with arbitrary string properties (like a hashmap or dictionary)
{ [key: string]: Type; }
{ [key: number]: Type; }
{ [key: symbol]: Type; }
{ [key: `data-${string}`]: Type; }
/*
Индексные типы позволяют определить тип данных для ключей объекта, которые могут быть строками, числами, символами
или определенным шаблоном строк.
@pointofpresence
pointofpresence / select multiple.jsx
Last active March 31, 2024 18:42
HTML: Тег select с мультивыбором
// В атрибут value можно передать массив, что позволит выбрать несколько опций в теге select:
<select multiple={true} value={['Б', 'В']}
// Boolean attribute 'multiple' indicates that multiple options can be selected in the list.
// If it is not specified, then only one option can be selected at a time. When `multiple` is
// specified, most browsers will show a scrolling list box instead of a single line dropdown.
@pointofpresence
pointofpresence / 1660549971.js
Created August 15, 2022 07:52
Created with Copy to Gist
192
If you are using Apache as your web server, you can insert this into your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@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
@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 / 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';