Skip to content

Instantly share code, notes, and snippets.

View jisaacks's full-sized avatar
🦎
‌‌

JD Isaacks jisaacks

🦎
‌‌
View GitHub Profile
// Demo: converting a thenable to a Promise
const fulfilledThenable = {
then(reaction) {
reaction('hello');
}
};
const promise = Promise.resolve(fulfilledThenable);
console.log(promise instanceof Promise); // true
promise.then(x => console.log(x)); // hello
@iammerrick
iammerrick / PinchZoomPan.js
Last active January 26, 2026 06:44
React Pinch + Zoom + Pan
import React from 'react';
const MIN_SCALE = 1;
const MAX_SCALE = 4;
const SETTLE_RANGE = 0.001;
const ADDITIONAL_LIMIT = 0.2;
const DOUBLE_TAP_THRESHOLD = 300;
const ANIMATION_SPEED = 0.04;
const RESET_ANIMATION_SPEED = 0.08;
const INITIAL_X = 0;
@javilobo8
javilobo8 / download-file.js
Last active May 13, 2025 05:55
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@mjaakko
mjaakko / bbox2geohashes.js
Last active January 31, 2026 11:15
Converts a bounding box to geohashes
//Converts a bounding box bounded by minLat and maxLat and minLng and maxLng to a list of geohashes (e.g. ["60;24/19/84", "60;24/19/85"]) used for MQTT topic filters
function bbox2geohashes(minLat, minLng, maxLat, maxLng) {
var deltaLat = maxLat - minLat;
var deltaLng = maxLng - minLng;
var geohashLevel = Math.max(Math.ceil(Math.abs(Math.log10(deltaLat))), Math.ceil(Math.abs(Math.log10(deltaLng))));
var delta = Math.pow(10, -geohashLevel);
var geohashes = [];