Skip to content

Instantly share code, notes, and snippets.

View benhatsor's full-sized avatar

Ben Hatsor benhatsor

View GitHub Profile
@benhatsor
benhatsor / disableMagnifier.js
Last active September 12, 2024 14:32
Remove Safari text selection magnifier (iPhone)
// https://discourse.threejs.org/t/iphone-how-to-remove-text-selection-magnifier/47812/11
function createHandler(func, timeout) {
let timer = null;
let pressed = false;
return function() {
if (timer) {
@benhatsor
benhatsor / brickanimator.py
Created March 1, 2021 15:35
Animate Lego sets in Blender
import bpy
from mathutils import Vector
# Edit these:
offset = 1 # Offset is the interval between each brick appearance
startFrame = 0 # Start Frame is the frame that the brick animation starts on
# Variables
frameNum = startFrame
selectedBricks = bpy.context.selected_objects
@benhatsor
benhatsor / arrayEqual.js
Last active February 10, 2024 15:49
Compare two arrays (minified)
Array.prototype.equals=function(a){for(var b=0;b<this.length;b++)if(this[b]!=a[b])return!1;return!0};
[0,1].equals([0,1]) // true
@benhatsor
benhatsor / IDFromTime.js
Last active February 10, 2024 15:47
Generate a unique ID based on the current time. Note: If you need a truly unique ID, use something like the JS Crypto API instead.
// Both numbers and letters
function mixedID() {
var now = new Date();
timestamp = now.getFullYear().toString();
timestamp += (now.getMonth < 9 ? '0' : '') + now.getMonth().toString();
timestamp += ((now.getDate < 10) ? '0' : '') + now.getDate().toString();
timestamp += now.getHours().toString();
timestamp += now.getMinutes().toString();
timestamp += now.getSeconds().toString();
@benhatsor
benhatsor / scrollToEl.js
Last active February 10, 2024 15:48
Smooth scroll to element
function scrollToEl(el) {
var rect = el.getBoundingClientRect(),
scrollTop = window.pageYOffset || document.documentElement.scrollTop,
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
elTop = rect.top + scrollTop,
elLeft = rect.left + scrollLeft;
window.scrollTo({
top: elTop,
left: elLeft,