Skip to content

Instantly share code, notes, and snippets.

View MattyQ's full-sized avatar

Matty Williams MattyQ

View GitHub Profile
@MattyQ
MattyQ / anaylzeViewport.js
Created May 29, 2024 14:35
Simple function to determine whether a viewport is vertical, horizontal or square, and whether the dimensions are nearest to 16:9, 4:3, or 1:1 (or the vertical equivalent)
function analyzeViewport() {
const width = window.innerWidth;
const height = window.innerHeight;
// Determine layout
let layout;
if (width > height) {
layout = "horizontal";
} else if (width < height) {
layout = "vertical";
@MattyQ
MattyQ / matrixrain.js
Created April 25, 2023 01:55
Creates a canvas in the body to draw a Matrix-style rain effect. Generated by ChatGPT. Free to reuse with no attribution required.
function matrixRain() {
const canvas = document.createElement("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = "fixed";
canvas.style.top = 0;
canvas.style.left = 0;
canvas.style.zIndex = -1;
document.body.appendChild(canvas);
@MattyQ
MattyQ / quantum-fractal-dreaming.ascii
Created March 16, 2023 03:25
ChatGPT-generated ASCII art
\033[0;31m . .
\033[0;33m . . * . .
\033[0;32m . * . .
\033[0;34m \ . * . * . .
\033[0;35m o
\033[0;36m . o .
\033[0;37m .---.\ ___ ____ *
\033[0;31m ~-_ /:. _\ \ \/ / . *
\033[0;33m ~-/::. \-~~~~~~~\ /~~~\_ *
\033[0;32m ~---/:::::\ /:::./ \ .
@MattyQ
MattyQ / private_class_with_constructor.js
Created February 11, 2023 01:53
Implements a simple example class that includes a static private class. The static private class is used to construct objects when the global public class is instantiated.
"use strict";
/** Public class that uses a static private class as the constructor for the public class. */
class GlobalPublicClass {
/** Static private class that is only accessible within the scope of GlobalPublicClass. */
static #InternalPrivateClass = class {
/**
* Constructs the #InternalPrivateClass object.
*/
constructor() {
@MattyQ
MattyQ / get_z_index.js
Last active April 26, 2019 17:17
Get highest z-index in a given target (Javascript)
/**
* @fileoverview Queries the computed styles for a given element to determine the highest z-index.
* For example, GET_Z_INDEX(document) returns the highest z-index in the DOM.
*/
/**
* @function GET_Z_INDEX
* @param {object} parent_node The target parent node. The function returns the highest z-index of parent_node's children.
* @returns {number}
*/