Skip to content

Instantly share code, notes, and snippets.

View PavlikPolivka's full-sized avatar

Pavel Polívka PavlikPolivka

View GitHub Profile
const paginationHandler = (page) => {
const currentPath = props.router.pathname;
const currentQuery = props.router.query;
currentQuery.page = page.selected + 1;
props.router.push({
pathname: currentPath,
query: currentQuery,
})
const wordsPerMinute = 225
export function readingTime(text) {
return Math.ceil(wordCounter(text) / wordsPerMinute)
}
function wordCounter(input) {
const text = input.split(/\s+/)
let wordCount = 0
for (let i = 0; i < text.length; i++) {
if (text[i] !== ' ' && isWord(text[i])) {
wordCount++
}
}
return wordCount
}
function getData(key){
return new Promise(function(resolve, reject) {
console.log('starting get ' + key)
setTimeout(() => {
console.log('ending get ' + key)
resolve(key);
}, 1000);
})
}
const _cacheValues = new Map();
const _cacheResolvedTime = new Map();
const _cachePromises = new Map();
const getDataCached = function (key) {
}
if (_cacheValues.has(key)) {
return Promise.resolve(_cacheValues.get(key));
} else if (_cachePromises.has(key)) {
return _cachePromises.get(key);
} else {
const promise = new Promise(function (resolve, reject) {
return getData(key).then(data => {
_cacheValues.set(key, data);
_cachePromises.delete(key);
const now = new Date().getTime();
const now = new Date().getTime();
if (_cacheResolvedTime.has(key)) {
if ((now - _cacheResolvedTime.get(key)) > 60000) {
_cacheResolvedTime.delete(param);
_cacheValues.delete(key);
_cachePromises.delete(key);
}
}
getDataCached('a').then(result => { console.log('first call outer: ' + result);
getDataCached('a').then(result => { console.log('first call inner: ' + result); });
});
getDataCached('b').then(result => { console.log('first call outer: ' + result);
getDataCached('b').then(result => { console.log('first call inner: ' + result); });
});
getDataCached('a').then(result => { console.log('second call outer: ' + result);
getDataCached('a').then(result => { console.log('second call inner: ' + result); });
const { TwitterClient } = require('twitter-api-client')
const axios = require('axios')
const sharp = require('sharp')
const Feed = require('rss-to-json')
const Jimp = require('jimp')
const fs = require('fs')
const numberOfFollowers = 3
const widthHeightFollowerImage = 90
{
"scripts": {
"generate": "run-func netlify/functions/header.js handler"
},
"dependencies": {
"axios": "^0.24.0",
"jimp": "^0.16.1",
"rss-to-json": "^2.0.2",
"run-func": "^1.0.5",
"sharp": "^0.29.3",