Skip to content

Instantly share code, notes, and snippets.

View annibal's full-sized avatar

Arthur Annibal annibal

View GitHub Profile
@annibal
annibal / README.md
Last active December 3, 2025 13:09
A way to check how random is your random function. Invokes it billions of times and counts each result for you.

Usage:

function myRandomFunction() {
  return Math.random() * 100 | 0;
}

const testRF = testRandomFunction({
  randFn: () => { myRandomFunction(); },
 runsPerCycle: 1e5,
@annibal
annibal / README.md
Last active November 22, 2025 21:12
i think PRIMARY KEY INTEGER AUTOINCREMENT ids are ugly.

Custom UID generator

const { uid: customUID } = CreateNibolsUID();
const thingID = customUID(4);
const otherID = customUID(8);

// decode uid
log(thingID === otherID); // true
log( customUID(thingID, true), customUID(otherID, true) ); // 4, 8
@annibal
annibal / aboutURL.json
Last active November 14, 2025 03:48
Examples of URL - both Valid and Invalid, plus some more info about URL validation. Someday i'll build the perfect URL validation, then from it, the amazing "makeValidThisURL()"
{
"rules": {
"domain": [
".com .net .org and .info domain names cannot exceed 67 characters",
".info and .biz must have at least 3 characters not including .info and .biz",
"Other domain names cannot exceed 22 characters not including the extension",
"2 letter domains are not allowed."
],
"edge-cases": [
"'http://url.com/path///////otherpath' is technically valid per RFC 3986 and 9110. Most servers normalize or collapse them ('/path///////otherpath' and '/path/otherpath' yield the same resource), others don't (several empty segments (\"\") between 'path' and 'otherpath').",
@annibal
annibal / getValidatedVersionParam.js
Last active November 14, 2025 03:47
Validates "v1" or "v0.1" or "v0.0.1" but not "v01" nor "v1.01" nor "v0.0.01" nor "vRegExp"
const regExVersion = new RegExp([
// starts with "v" ➔ v1, v2, v56, v100 works. vv1, 12345, 1.2.3 fails.
"^(?:v)",
// major version: either "0" or a number that not starts with 0. ➔ v01 fails
"(?<major>(?:[1-9][0-9]*)|(?:0))",
// minor version (optional) - same as major ➔ v1.1, v0.1, v2.15, v9, v9.0, v9.9 works. v9.09 fails
"(?:\.(?<minor>(?:[1-9][0-9]*)|(?:0)))?",
// revision (optional too) - same as major ➔ v1.2.3, v0.0.1, v9.0.9 works, v0.0.0, v6.5.04 fails.
"(?:\.(?<revision>(?:[1-9][0-9]*)|(?:0)))?",
@annibal
annibal / BEM.css
Last active November 14, 2025 03:47
B.E.M. :: Block Element Modifier - naming standard - Cascading Style Sheets
.BEM {
--B: block, #1;
--E: element, #2;
--M: modifier, #3;
--USAGE: block__element--modifier;
--USAGE: nibol-slider__item--active;
}
*:nth-child(1) {
@annibal
annibal / ColorFormatConverterHelpers.js
Last active August 13, 2025 19:24
Converts many of the most common color formats, from and to. Also generates a monochromatic palette.
const makeColorFormatConverterHelpers = (() => {
function rgbToHsl([r, g, b]) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h, s, l = (max + min) / 2, d = max - min;
if (!d) h = s = 0;
else {
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
@annibal
annibal / HTMLandQueryUtil.js
Last active November 9, 2025 07:43
Generate HTML and Query elements with the H() and Q() functions
const example = (() => {
const content = H("<div class=content>"+
"<p>quia dolor sit, amet, consectetur, adipisci velit</p>"+
"<p>sed quia non numquam eius modi tempora incidunt,</p>"+
"<p>ut labore et dolore magnam aliquam quaerat voluptatem.</p>"+
"</div>");
const card = H("<section>"+
"<header><h1>Dolorem Ipsum</h1></header>"+
content.outerHTML,
"</section>");
@annibal
annibal / bidi-tests.js
Last active November 14, 2025 03:47
Unicode Combination and Width Tests
// Example usage:
console.log(testWidthReductionTechniques("Hello World"));
console.log(runWidthTests());
function testWidthReductionTechniques(inputText) {
// Store original for comparison
const original = inputText;
// Key directional control characters
const RLM = "\u200F"; // Right-to-Left Mark
@annibal
annibal / list_recently_active_repos.js
Last active April 22, 2025 18:11
Azure : list Project's recently active Repos
async function listMostRecentlyActiveRepos(org, project, maxCommits=15) {
const base = `https://dev.azure.com/${org}/${project}/_apis/git/repositories?api-version=7.1-preview.1`;
const repos = await fetch(base).then(r => r.json());
const activeRepos = [];
const data = []
for (const repo of repos.value) {
const commitsUrl = `https://dev.azure.com/${org}/${project}/_apis/git/repositories/${repo.id}/commits?$top=${maxCommits}&api-version=7.1-preview.1`;
@annibal
annibal / jequiti-blinker.js
Last active October 25, 2024 20:55
Every 5 ~ 30 seconds, randomly, shows an JEQUITI image fullscreen covering the web page, for a few seconds, then hides and deletes it
const commonStyles = "display: block; position: fixed; z-index: 9999999; transition: opacity 100ms ease; left 100ms ease; top: 100ms ease; right: 100ms ease; bottom: 100ms ease; width: 100ms ease; height: 100ms ease;"
const jequitiSettings = {
min: 5000,
max: 30000,
duration: 500,
waitLoad: 1000,
waitRemove: 200,
tid: null,
src: "https://fraguru.com/mdimg/dizajneri/o.1954.jpg",
id: "jequiti-overlay",