This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Принцип открытости\закрытости | |
Цель - сделать систему легкорасширяемой и обезопасить ее от влияния изменений | |
Эта цель достигается делением системы на компонентыи упорядочением их зависимостей в иерархию - защищающуу компоненты уровнем выше от изменений в компонентах уровнем ниже | |
Принцип единственной ответственности | |
Принцип при котором причины изменения конкретного модуля должны зависеть от конкретной группы (конкретных акторов) | |
Руководствуясь этим принципом у вас не может быть 1го класса который отвечает за оплату во всем приложении, | |
в котором есть несколько групп (акторов) пользователей |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeout(ms, fn) { | |
let timer = setTimeout(() => { | |
if (timer) console.log('Function timedout'); | |
timer = null; | |
}, ms); | |
return (...args) => { | |
if (timer) { | |
timer = null; | |
fn(...args); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function chain(prev = null) { | |
const cur = () => { | |
if (cur.prev) { | |
cur.prev.next = cur; | |
cur.prev(); | |
} else { | |
cur.forward(); | |
} | |
} | |
cur.prev = prev; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const memoizationClosuresTimes10 = n => { | |
let cache = {}; | |
return n => { | |
if (n in cache) { | |
return cache[n] | |
} else { | |
let res = n * 10; | |
cache[n] = res; | |
return res; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder