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 notFunny() { | |
function s(fn = () => {}) { | |
return () => { | |
const fnStr = fn.toString(); | |
console.log(fnStr); | |
const keywords = ['console', 'debugger']; | |
if (!keywords.find(key => fnStr.includes(key))) | |
throw new Error(`Uncaught ReferenceError: ${fn.toString().slice(0, 10)} is not defined`); | |
fn(); | |
} |
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 caesar(str, increment) { | |
const letters = 'abcdefghijklmnopqrstuvwxyz'; | |
return str | |
.toLowerCase() | |
.split('') | |
.map(c => { | |
const index = letters.indexOf(c); | |
if (index === -1) return c; | |
let newIndex = index + increment; | |
if (newIndex < 0) { |
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
//determinant of matrix a | |
function det(a) { | |
return ( | |
a[0][0] * a[1][1] * a[2][2] + | |
a[0][1] * a[1][2] * a[2][0] + | |
a[0][2] * a[1][0] * a[2][1] - | |
a[0][2] * a[1][1] * a[2][0] - | |
a[0][1] * a[1][0] * a[2][2] - | |
a[0][0] * a[1][2] * a[2][1] | |
); |
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 waitUntilValueChanges(domElem) { | |
return new Promise(resolve => { | |
let prevVal = domElem.value; | |
const inter = setInterval(() => { | |
if (domElem.value !== prevVal) { | |
clearInterval(inter); | |
return resolve(); | |
} | |
prevVal = domElem.value + ''; | |
}, 100); |
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
const defaultArea = [ | |
{ x: 1.51, y: 0, z: -1.98 }, | |
{ x: -0.17, y: 0, z: -1.96 }, | |
{ x: -0.06, y: 0, z: 0.06 }, | |
{ x: 1.36, y: 0, z: 0.73 } | |
]; | |
//determinant of matrix a | |
function det(a) { | |
return ( |
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
const audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext); | |
function beep(duration, frequency, volume, type, callback) { | |
const oscillator = audioCtx.createOscillator(); | |
const gainNode = audioCtx.createGain(); | |
oscillator.connect(gainNode); | |
gainNode.connect(audioCtx.destination); |
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
/** Play around and try to convert a website into re-usable React components */ | |
// Code from https://github.com/scriptify/statikk-converter/ | |
(() => { | |
const $ = document.querySelectorAll.bind(document); | |
function extractElements() { | |
const allElements = $('body *'); | |
const allStatikkElements = []; | |
for (const elem of allElements) { | |
allStatikkElements.push(domToStatikk(elem)); |
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
import React from "react"; | |
import { CmsEditorFieldTypePlugin } from "@webiny/app-headless-cms/types"; | |
import { Grid, Cell } from "@webiny/ui/Grid"; | |
import { Typography } from "@webiny/ui/Typography"; | |
import { Select } from "@webiny/ui/Select"; | |
import { Input } from "@webiny/ui/Input"; | |
import { i18n } from "@webiny/app/i18n"; | |
const t = i18n.ns("app-headless-cms/admin/fields"); | |
import { ReactComponent as TextIcon } from "./round-text_fields-24px.svg"; |
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
import React from "react"; | |
import { CmsEditorFieldTypePlugin } from "@webiny/app-headless-cms/types"; | |
import { Grid, Cell } from "@webiny/ui/Grid"; | |
import { Typography } from "@webiny/ui/Typography"; | |
import { Select } from "@webiny/ui/Select"; | |
import { Input } from "@webiny/ui/Input"; | |
import { i18n } from "@webiny/app/i18n"; | |
const t = i18n.ns("app-headless-cms/admin/fields"); | |
import { ReactComponent as TextIcon } from "./round-text_fields-24px.svg"; |
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
interface ExecutionTime { | |
fnName: string; | |
totalTime: number; | |
hitCount: number; | |
} | |
const executionTimes: ExecutionTime[] = []; | |
async function measureExecutionTime<T>( | |
fn: (...args: any[]) => Promise<T>, |
OlderNewer