Skip to content

Instantly share code, notes, and snippets.

View spamshaker's full-sized avatar

Michał Grzegorzewski spamshaker

View GitHub Profile
@spamshaker
spamshaker / performance-stress.js
Created October 23, 2023 14:24
performance stress test
View performance-stress.js
'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;
@spamshaker
spamshaker / base64.mjs
Last active October 14, 2023 09:56
Javascript base64 encode/decode using native Browser/Node methods
View base64.mjs
// 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)));
@spamshaker
spamshaker / match-jsdoc-comment.js
Created August 11, 2023 04:11
match-jsdoc-comment.js
View match-jsdoc-comment.js
`/**
* This is a comment
*/
class MyClass {
/**
* This is a comment
*/
function doSmth(){
const thing = '';
return thing + 'done';
@spamshaker
spamshaker / iframe-jest-jsdom-environment.js
Last active January 22, 2023 19:56
IFrame jest simulation with jest by custom IFrameJSDOMEnvironment
View iframe-jest-jsdom-environment.js
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) {