Skip to content

Instantly share code, notes, and snippets.

View SalvatorePreviti's full-sized avatar

Salvatore Previti SalvatorePreviti

View GitHub Profile
git log --since="2022-01-01" | ack "Author:" | awk -F '<' '{print $1}' | ack Author | sort | uniq -c | sort -r
describe('newPRNG', () => {
test('should generate seeded random values', () => {
expect(newPRNG(123)(new Array(5))).toEqual([-220828386, -1556571610, 1450074142, -2011800852, 1359997245]);
expect(Buffer.from(newPRNG(123)(new Int8Array(20))).toString('hex')).toBe(
'1ef2d66d26a3389a1e566e60ec88165a3d510fe9',
);
expect(Buffer.from(newPRNG(123)(new Int8Array(20))).toString('hex')).toBe(
'1ef2d66d26a3389a1e566e60ec88165a3d510fe9',
);
expect(Buffer.from(newPRNG(123)(new Uint8ClampedArray(10))).toString('hex')).toBe('1ef2d66d26a3389a1e56');
@SalvatorePreviti
SalvatorePreviti / atom-hooks.tsx
Last active July 19, 2023 21:28
React global state!
import { useSyncExternalStore } from "react";
import type { ConsumerProps, FC, ReactNode } from "react";
export interface ReactAtom<T> {
readonly get: () => T;
readonly sub: (listener: () => void) => () => void;
}
/**
* Hook: Use an atom value in a react component.
@SalvatorePreviti
SalvatorePreviti / gist:0ec6a73cb14cd33f12350ae27468f2e7
Last active May 20, 2024 02:00
GetFrustumLineIntersection - find the intersection of an infinite line with a view frustum in Unity (improved, with tolerance, stable on corner cases)
/// <summary>
/// Computes the intersection points between a frustum and an infinite line.
/// Finds the visible part of a segment in respect of a camera frustum.
/// Returns false if the line is not visible at all.
/// </summary>
/// <example>
/// var planes = GeometryUtility.CalculateFrustumPlanes(camera);
/// if (GetFrustumLineIntersection(camera, planes, ray, out d1, out d2)) {
/// Gizmos.DrawLine(ray.GetPoint(d1), ray.GetPoint(d2));
/// }