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 {default: JSDOMEnvironment} = require('jest-environment-jsdom'); | |
const {JSDOM} = require('jsdom'); | |
const createWindow = (url) => new JSDOM('', { | |
runScripts: 'dangerously', | |
url | |
}).window; | |
class IFrameJSDOMEnvironment extends JSDOMEnvironment { | |
constructor(config, context) { |
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
`/** | |
* This is a comment | |
*/ | |
class MyClass { | |
/** | |
* This is a comment | |
*/ | |
function doSmth(){ | |
const thing = ''; | |
return thing + 'done'; |
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
// Encodes any text to base64; | |
export const encodeBase64 = text => btoa(String.fromCodePoint(...Array.from(new TextEncoder().encode(text)))); | |
// Decodes base64 to text; | |
export const decodeBase64 = text => new TextDecoder().decode(Uint8Array.from(atob(text), (m) => m.codePointAt(0))); |
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
'use strict'; | |
const cluster = require('cluster'); | |
const os = require('os'); | |
const now = () => performance.now(); | |
let time = 10000; | |
let start = now(); | |
let end = start + time; | |
if (cluster.isMaster) { | |
let total = 0; | |
const numCPUs = os.cpus().length; |
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
/** | |
* Hoisting does not work; The userLicenseFactory method is not hoisted to the top. | |
* @throws {ReferenceError} ReferenceError: Cannot access 'User' before initialization | |
*/ | |
// console.log(User); | |
/** | |
* Hoisting works; The {UserFunc} method is hoisted to the top. | |
*/ | |
console.log(UserFunc); |
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
import { createContext, runInContext} from 'node:vm'; | |
import { performance } from 'node:perf_hooks'; | |
const fibonacci = n => n <= 2 ? n - 1 : fibonacci(n - 1) + fibonacci(n - 2); | |
const context = createContext({ fibonacci }); | |
let time; | |
let result; |
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
#include <iostream> | |
#include <chrono> | |
#include <cmath> | |
bool isPrime(int n) { | |
if (n <= 1) return false; | |
if (n <= 3) return true; | |
if (n % 2 == 0 || n % 3 == 0) return false; | |
for (int i = 5; i * i <= n; i += 6) { | |
if (n % i == 0 || n % (i + 2) == 0) return false; |