Skip to content

Instantly share code, notes, and snippets.

View TracyGJG's full-sized avatar

TGJ Gilmore TracyGJG

  • Somerset, UK
View GitHub Profile
@TracyGJG
TracyGJG / codingStyles.js
Last active April 29, 2026 08:51
Coding styles in JS
/*
Case study
Write a function that, when given an object returns the value of a specific property of that object.
Exercise
Create an object with two numeric properties (x=42 and y=666) and log just the x property to the console.
*/
// Procedural style
{
@TracyGJG
TracyGJG / moduloNegative.js
Last active May 3, 2026 21:29
Modulo that handles negative values properly
const mod = (v, m) => (v + m) % m;
function modulo(m, v) {
return v == null ? (_v) => mod(_v, m) : mod(v, m);
}
console.log('\nJS mod: -1 % 1000 \t=', -1 % 1000);
console.log('\nmod(-1, 1000) \t\t=', mod(-1, 1000));
@TracyGJG
TracyGJG / duplicate-ids.html
Last active August 3, 2025 16:32
Function to detect and report elements with duplicate Ids
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Duplicate Ids</title>
</head>
<body>
<div id="$m1">
<p id="p1"></p>
@TracyGJG
TracyGJG / DomElementRefById.html
Last active April 29, 2026 08:51
DOM element reference by
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DOM element ref by ($)id</title>
</head>
<body>
<main>Place holder text</main>
@TracyGJG
TracyGJG / presentDateTime.js
Created February 28, 2023 17:25
Date-Time presentation formatter
function presentDateTime(dateObjectOrString) {
const pDateTime = (dateObjectOrString instanceof Date) ? dateObjectOrString : new Date(dateObjectOrString);
const pYear = nonZeroSuppression(pDateTime.getFullYear(), 4);
const pMonth = nonZeroSuppression(pDateTime.getMonth() + 1);
const pDay = nonZeroSuppression(pDateTime.getDate());
const pHours = nonZeroSuppression(pDateTime.getHours());
const pMinutes = nonZeroSuppression(pDateTime.getMinutes());
return `${pYear}-${pMonth}-${pDay}, ${pHours}:${pMinutes}`;
function nonZeroSuppression(num, width = 2) {
@TracyGJG
TracyGJG / pokerStats.js
Last active February 16, 2023 08:28
Poker stats calculator
const tests = [
[],
[0],
[0, 0],
[0, 1, 2, 3, 5, 1, 2, 5, 8, 5, 1],
[5, 5, 5, 5],
[5, 5, 5, 8],
[5, 5, 8, 8],
[5, 5, 8, 13],
[5, 8, 8, 8],
@TracyGJG
TracyGJG / WorstHelloWorld.html
Last active November 15, 2024 20:23
Worst Hello World ever
<script>
[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!