Skip to content

Instantly share code, notes, and snippets.

View ungarson's full-sized avatar
🎯
Focusing

Yo ungarson

🎯
Focusing
View GitHub Profile
@ungarson
ungarson / example.c
Created December 25, 2019 19:04
Struct with dynamic memory allocation in c
#include <stdio.h>
#include <stdlib.h>
struct course {
int mark;
char subject[30];
} mark;
struct course *ptr; // we don't allocate memory at that point because we don't know amount yet
int numberOfRecords;
@ungarson
ungarson / optimize_site_speed_ways.txt
Last active October 20, 2020 11:49
Способы оптимизировать скорость загрузки сайта
Необходимые максимальные показатели (wi-fi, 200 mb/s, октябрь 2020):
Desktop:
1. FCP - 0.6s
2. Time To Interactive - 1.9s
3. Speed Index - 1.2s
4. LCP - 0.8s
5. CLS - 0.001s
6. Total Blocking Time - 0.1s
7. DomContentLoaded - 1.5s
@ungarson
ungarson / Storage.js
Created October 10, 2021 13:55
Storage class for local storage management
export default class Storage {
static get(key) {
const value = localStorage.getItem(key);
if (!value) return undefined;
try {
return JSON.parse(value);
} catch {
localStorage.removeItem(key);
return undefined;
}
@ungarson
ungarson / tryAsyncUntilOk.js
Last active October 13, 2021 08:56
Try asynchronous function several times until it returns result
async function tryAsyncUntilOk(func, times = 4, timeout = 1250) {
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
for (let i = 0; i < times; i++) {
try {
const res = await func();
if (typeof res !== "undefined") {
return res;