Skip to content

Instantly share code, notes, and snippets.

Avatar

Pavel Polívka PavlikPolivka

View GitHub Profile
View contact.js
import TextField from '@mui/material/TextField';
import Button from '@mui/material/Button';
import {useState} from 'react';
export default function Contact() {
const [send, setSend] = useState(false);
async function handleSubmit(event) {
event.preventDefault()
View email.js
const sendInBlueKey = process.env.NEXT_PUBLIC_SEND_IN_BLUE_KEY
export default async function handler(req, res) {
const body = req.body
const resp = await fetch('https://api.sendinblue.com/v3/smtp/email', {
method: 'POST',
headers: {
'Accept': 'application/json',
View render.js
import ReactMarkdown from 'react-markdown';
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { materialDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
<ReactMarkdown
components={{
p: ({ node, children }) => {
if (node.children[0].tagName === "img") {
const image = node.children[0];
View netlify.toml
[functions]
included_files = ["netlify/functions/**"]
View packakge.json
{
"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",
View header.js
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
View test.js
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); });
View ttl.js
const now = new Date().getTime();
if (_cacheResolvedTime.has(key)) {
if ((now - _cacheResolvedTime.get(key)) > 60000) {
_cacheResolvedTime.delete(param);
_cacheValues.delete(key);
_cachePromises.delete(key);
}
}
View cache.js
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();
View variables.js
const _cacheValues = new Map();
const _cacheResolvedTime = new Map();
const _cachePromises = new Map();
const getDataCached = function (key) {
}