Skip to content

Instantly share code, notes, and snippets.

@OrionReed
OrionReed / dom3d.js
Last active July 28, 2024 16:59
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@Akryum
Akryum / IframeKeepAlive.vue
Last active May 23, 2024 09:17
An iframe that will not reload when mounted on the page again (based on `src`).
<script lang="ts">
const iframes = new Map<string, { iframe: HTMLIFrameElement, src: string }>()
</script>
<script lang="ts" setup>
import { useAttrs, ref, shallowRef, watchEffect, onMounted, onBeforeUnmount } from 'vue'
import { useElementBounding } from '@vueuse/core'
defineOptions({
inheritAttrs: false,
@guest271314
guest271314 / javascript_engines_and_runtimes.md
Last active July 25, 2024 02:34
A list of JavaScript engines, runtimes, interpreters

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

SpiderMonkey is Mozilla’s JavaScript and WebAssembly Engine, used in Firefox, Servo and various other projects. It is written in C++, Rust and JavaScript. You can embed it into C++ and Rust projects, and it can be run as a stand-alone shell. It can also be [compiled](https://bytecodealliance.org/articles/making-javascript-run-fast-on

@1Marc
1Marc / reactive.js
Last active July 7, 2024 15:42
Vanilla Reactive System
// Credit Ryan Carniato https://frontendmasters.com/courses/reactivity-solidjs/
let context = [];
export function untrack(fn) {
const prevContext = context;
context = [];
const res = fn();
context = prevContext;
return res;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Screen recorder</title>
</head>
<body>
<button id="recording-toggle">Start recording</button>
<script defer>
// Core assets
let coreAssets = [];
// On install, cache core assets
self.addEventListener('install', function (event) {
// Cache core assets
event.waitUntil(caches.open('app').then(function (cache) {
for (let asset of coreAssets) {
cache.add(new Request(asset));
const hash = require("crypto-js/sha256");
class Block {
constructor(previousHash, data) {
this.data = data;
this.hash = this.calculateHash();
this.previousHash = previousHash;
this.timeStamp = new Date();
this.proofOfWork = 0;
}
@rakia
rakia / circular-reference.ts
Created September 20, 2021 13:11
Circular Reference in JavaScript
var circularReference = {otherData: 123};
circularReference.myself = circularReference;
JSON.stringify(circularReference); // returns --> TypeError: cyclic object value
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
@broofa
broofa / checkForUndefinedCSSClasses.js
Last active January 21, 2024 17:22
ES module for detecting undefined CSS classes (uses mutation observer to monitor DOM changes). `console.warn()`s undefined classes.
/**
* Sets up a DOM MutationObserver that watches for elements using undefined CSS
* class names. Performance should be pretty good, but it's probably best to
* avoid using this in production.
*
* Usage:
*
* import cssCheck from './checkForUndefinedCSSClasses.js'
*
* // Call before DOM renders (e.g. in <HEAD> or prior to React.render())
@aryasurya21
aryasurya21 / serviceWorker.js
Created March 17, 2021 05:03
Updated STATIC_FILES
var STATIC_CACHE_CONTAINER = "static_v1"
var STATIC_FILES = [
"/",
"/index.js",
"/index.css",
"https://fonts.googleapis.com/css2?family=Ranchers&display=swap",
"https://fonts.gstatic.com/s/ranchers/v8/zrfm0H3Lx-P2Xvs2ArDfBi8.woff2",
"https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
]