Skip to content

Instantly share code, notes, and snippets.

View gapspt's full-sized avatar

Jorge Galvao gapspt

  • Homa Games
  • Lisbon
View GitHub Profile
@gapspt
gapspt / PolyPartition.cs
Created January 12, 2024 10:11
Port of https://github.com/ivanfratric/polypartition to C# (Partial but almost complete port - lacking monotone partitioning)
// Origin: https://github.com/ivanfratric/polypartition
// Commit: 5dcc93c9c023a2296610ec98539e2377f4285d30
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using tppl_float = System.Double;
using TPPLPolyList = System.Collections.Generic.LinkedList<TPPLPoly>;
@gapspt
gapspt / addOverlayImage.js
Last active August 14, 2022 20:49
Dinamically add an image as an overlay when pressing a specific sequence of keys on the keyboard. The image will scale with the browser window (responsive) while keeping its original ratio.
function addOverlayImage(url, scale) {
let e = document.createElement('img');
e.style.visibility = 'hidden';
e.src = url;
let w, h, r = 0;
function setSize() {
if (r) {
let winR = window.innerWidth / window.innerHeight;
let s = scale * (r > winR ? window.innerWidth / w : window.innerHeight / h);
e.width = w * s;
@gapspt
gapspt / promise_debug.js
Last active March 29, 2022 17:20
JavaScript pending promises debug
// Adapted from https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-promise
function promiseState(promise, callback) {
const uniqueValue = /unique/;
Promise.race([promise, Promise.resolve(uniqueValue)])
.then(
(value) => callback(value === uniqueValue ? 'pending' : 'fulfilled'),
(reason) => callback(`rejected (${reason})`));
}
function debugPromiseState(promise) {
promiseState(promise, (state) => {