Skip to content

Instantly share code, notes, and snippets.

View KamMif's full-sized avatar
Focusing

Kam KamMif

Focusing
View GitHub Profile
@KamMif
KamMif / download-file.js
Created September 8, 2021 12:42 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@KamMif
KamMif / Чистая архитектура
Last active September 6, 2019 06:07
Дядюшка Боб
Принцип открытости\закрытости
Цель - сделать систему легкорасширяемой и обезопасить ее от влияния изменений
Эта цель достигается делением системы на компонентыи упорядочением их зависимостей в иерархию - защищающуу компоненты уровнем выше от изменений в компонентах уровнем ниже
Принцип единственной ответственности
Принцип при котором причины изменения конкретного модуля должны зависеть от конкретной группы (конкретных акторов)
Руководствуясь этим принципом у вас не может быть 1го класса который отвечает за оплату во всем приложении,
в котором есть несколько групп (акторов) пользователей
@KamMif
KamMif / timeout.js
Created July 7, 2019 18:05
add timeout
function timeout(ms, fn) {
let timer = setTimeout(() => {
if (timer) console.log('Function timedout');
timer = null;
}, ms);
return (...args) => {
if (timer) {
timer = null;
fn(...args);
}
@KamMif
KamMif / async_function_chain.js
Created July 7, 2019 18:01
async function chain
function chain(prev = null) {
const cur = () => {
if (cur.prev) {
cur.prev.next = cur;
cur.prev();
} else {
cur.forward();
}
}
cur.prev = prev;
function* RequestData() {
try {
yield put(requestData());
while (true) {
yield call(delay, 60000);
const data = yield call(fetchDataStatus);
if (data.res) {
yield put(requestDataSuccess(data.resp));
}
const memoizationClosuresTimes10 = n => {
let cache = {};
return n => {
if (n in cache) {
return cache[n]
} else {
let res = n * 10;
cache[n] = res;
return res;
}
const times10 = n => n * 10;
const cache = {};
const memoTimes10 = n => {
if (n in cache) {
return cache[n];
}
else {
let res = times10(n);
cache[n] = res;
// Function for rinding min index of elemtnt in array
function smallest(arr) {
let smallest[0];
let smallestIndex = 0;
for (let i = 0; i < arr.length; i ++) {
if (arr[i] < smallest) {
smallest = arr[i]
smallestIndex = i
@KamMif
KamMif / filtred obj
Last active November 10, 2017 12:54
find includes in array and output filtred object
const values = ['sadasdasd', 'sdfsdfsdf', 'sdfsdf'];
const obj = [{ id: 1, transaction: 'sadasdasd' }];
const sorted = obj.filter(item => item.transaction.indexOf(values.transaction) !== -1);
console.log(sorted);
@KamMif
KamMif / array.includes(Obj)
Created November 7, 2017 08:20
find includes item in to array from obkect
const values = ['sadasdasd', 'sdfsdfsdf', 'sdfsdf'];
const obj = [{ id: 1, transaction: 'sdfsdf' }];
const sorted = values.filter(value => obj.map(item => item.transaction).includes(value));
console.log(sorted);