This file contains hidden or 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
/** | |
* fibonacciGenerator.js | |
* tags: { JavaScript, Generator, Iterator } | |
*/ | |
function* fibonacciGenerator() { | |
var [prev, curr] = [0, 1] | |
while(true) { | |
[prev, curr] = [curr, prev + curr] | |
yield curr |
This file contains hidden or 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
/** | |
* Workaround to set up a handshake, lazy-loading by resolving a promise | |
*/ | |
let settleReadyState = {} | |
let subprocess = {} | |
// following code outputs: Promise {<pending>} on console and sets | |
// settleReadyState = { resolve: ƒ, reject: ƒ} | |
// subprocess = {ready: Promise<pending>} |
This file contains hidden or 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 fizzBuzz(n: number) { | |
return ( | |
{ true: '', false: 'Fizz' }[`${n % 3 === 0}`] + | |
{ true: '', false: 'Buzz' }[`${n % 5 === 0}`] || | |
n.toString() | |
) | |
} | |
function fizzBuzzFunctional(n: number) { | |
let test = |
This file contains hidden or 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
/** | |
* Creates a hash for a value using the SHA-256 algorithm. Returns a promise. | |
* | |
* Use crypto.createHash() to create a Hash object with the appropriate | |
* algorithm. | |
* | |
* Use hash.update() to add the data from val to the Hash, hash.digest() to | |
* calculate the digest of the data. | |
* | |
* Use setTimeout() to prevent blocking on a long operation. Return a Promise to |
This file contains hidden or 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
/** | |
* The vanilla javascript way of implementing such a functionality would be to use | |
* he window's matchMedia function. The function takes a string query and | |
* returns a MediaQueryList that can be used to get the current result of the | |
* query and listen to changes of the media query. | |
*/ | |
const mediaQueryList = window.matchMedia(`(min-width: 767px)`); | |
console.log(mediaQueryList.matches); // true or false |
This file contains hidden or 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
/** | |
* Generate html string suitable for rendering in PDF | |
*/ | |
export const generateReportPdfHTML = async (options: GenerateReportPdfOptions): Promise<string> => { | |
const pages = CustomReportTemplate({ ...options, ssr: true }); | |
const pagesContent = _.map(pages, ({ name, content }) => ( | |
<Flex key={`box-${name}`} flexDir="column" h="100vh" style={{ pageBreakBefore: 'always' }}> | |
{content} | |
</Flex> |
This file contains hidden or 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
/*------------------------------------------ | |
Responsive Grid Media Queries - 1280, 1024, 768, 480 | |
1280-1024 - desktop (default grid) | |
1024-768 - tablet landscape | |
768-480 - tablet | |
480-less - phone landscape & smaller | |
--------------------------------------------*/ | |
@media all and (min-width: 1024px) and (max-width: 1280px) { } | |
@media all and (min-width: 768px) and (max-width: 1024px) { } |
This file contains hidden or 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
/** | |
* Reject promise after timeout | |
* | |
* @todo this is slow, we should find a way to do this in a faster way | |
* @param {Promise<any>} callback | |
* @param {number} ms | |
* @return {Promise<never>} | |
*/ | |
function withTimeout(callback, ms) { | |
let timeout; |
This file contains hidden or 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
'use strict'; | |
const { generateHeadersKey } = require('./generateHeadersKey'); | |
const { generateQueryParamsKey } = require('./generateQueryParamsKey'); | |
function generateCacheKey( | |
ctx, | |
keys = { | |
useQueryParams: false, // @todo: array or boolean => can be optimized | |
useHeaders: [], |