Skip to content

Instantly share code, notes, and snippets.

View Juraj-Masiar's full-sized avatar

Juraj Mäsiar Juraj-Masiar

View GitHub Profile
@Juraj-Masiar
Juraj-Masiar / firefox_for_android.polyfill.ts
Last active February 8, 2024 16:02
Polyfill for the missing browser.window API in the Firefox for Android
if (!browser.windows) browser.windows = {};
if (!browser.windows.getCurrent) {
browser.windows.getCurrent = async (getInfo?: browser.windows.GetInfo): Promise<browser.windows.Window> => {
const tabs = await browser.tabs.query({});
const activeTab = tabs.find(tab => tab.active);
return {
id: activeTab?.windowId ?? 1,
title: activeTab?.title ?? '',
focused: true,
alwaysOnTop: false,
@Juraj-Masiar
Juraj-Masiar / math_random_collision.js
Last active October 5, 2023 20:35
How many times do you need to call `Math.random()` to get a collision? (Firefox will tell you, Chrome may not!)
// This is a simple experiment to see how likely it is to get a collision when using Math.random()
(() => {
const numbersSet = new Set();
while (true) {
const random = Math.random();
// const random = crypto.randomUUID();
if (numbersSet.has(random)) {
console.log(`Set size: ${numbersSet.size.toLocaleString()}, collision: ${random}`);
break;
}