Skip to content

Instantly share code, notes, and snippets.

View scriptify's full-sized avatar
🏆
Working towards my goals, every day!

Maximilian Torggler scriptify

🏆
Working towards my goals, every day!
View GitHub Profile
@scriptify
scriptify / schroedinger.js
Last active December 18, 2018 10:06
If you don't debug the function using console.log, it throws an unexpected error. But as soon as you want to debug it, it works like a charm (I recently had an occurence like this, and instead of fixing the bug, I needed to create this gist as a joke). "Works" for every global function you create in the browser. Just copy and paste this code int…
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();
}
@scriptify
scriptify / julius.js
Created May 28, 2019 19:52
Simple Caesar Decryption in JavaScript
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) {
@scriptify
scriptify / not-that-noble.js
Created October 26, 2019 16:42
If you find out what it's doing, it can be pretty useful...
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);
@scriptify
scriptify / volume-calculation.js
Created October 16, 2019 17:33
Potree Volume Calculation
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 (
@scriptify
scriptify / Statikk Yo
Created January 18, 2020 18:54
You know what it is
/** 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));
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";
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";
@scriptify
scriptify / AreaCalculation.js
Created September 20, 2019 10:57
Calculates the area of a polygon in 3D space
//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]
);
@scriptify
scriptify / translate.js
Last active September 7, 2021 09:07
Go to https://www.deepl.com, paste this code into your browser console, and execute "translateAll" with a key-value object as the first param.
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);
@scriptify
scriptify / profiler.ts
Created March 10, 2023 09:01
Simple TypeScript profiler - Measure and print average function execution times the easy way
interface ExecutionTime {
fnName: string;
totalTime: number;
hitCount: number;
}
const executionTimes: ExecutionTime[] = [];
async function measureExecutionTime<T>(
fn: (...args: any[]) => Promise<T>,