Skip to content

Instantly share code, notes, and snippets.

View benhatsor's full-sized avatar

Ben Hatsor benhatsor

View GitHub Profile
@benhatsor
benhatsor / css-standard-native.css
Last active March 11, 2026 21:56
CSS Standard Styles - Native App
body {
margin: 0;
}
html {
/*
* Disable pinch-to-zoom, double-tap to zoom and panning the body (scrolling gestures).
* To enable scrolling: `touch-action: pan-x pan-y`.
*/
@benhatsor
benhatsor / css-reset-minimal.css
Last active March 11, 2026 21:55
CSS Reset - Minimal
html, body {
/* Disable double-tap to zoom to prevent click event delay
See: https://webkit.org/blog/5610/more-responsive-tapping-on-ios/ */
touch-action: manipulation;
/* Disable the highlight that appears when you tap on an element */
-webkit-tap-highlight-color: transparent;
/* Disable automatic browser bold/italic font variant generation */
//
// LinearAnimation.ts
// Created by Ben on 2/15/26.
//
export class LinearAnimation {
fromRange: LinearAnimationRange;
toRange: LinearAnimationRange;
@benhatsor
benhatsor / EscapedContinuation.swift
Last active August 31, 2025 18:37
Escaped Continuation
///
/// # EscapedContinuation
///
/// ## Usage
///
/// 1. Call:
///
/// ```swift
/// let continuation = await EscapedContinuation<ReturnsType>()
/// ```
@benhatsor
benhatsor / objDestructuringWithDefinedVars.js
Created June 30, 2025 18:19
Object destructuring with defined variables.
let a, b;
const obj = { a: 1, b: 2 };
({ a, b } = obj);
console.log(a, b); // 1 2
@benhatsor
benhatsor / awaitPromiseArr.js
Last active June 30, 2025 18:21
Await all promises in array
/*
// without response:
for await (async of promises) {}
OR
await Promise.all(promises);
// with response:
for await (const resp of promises) {
console.log(resp); // same as: const resp = await promise;
@benhatsor
benhatsor / optionalArgsWithObjectDestructuring.js
Created November 13, 2024 19:59
Optional function arguments with object destructuring.
function a(b, { c = 1 } = {}) {
console.log(b, c);
}
// a(2) -> '2 1'
// a(2, { c: 3 }) -> '2 3'
// a(2, {}) -> '2 1'
@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