Skip to content

Instantly share code, notes, and snippets.

@Temzasse
Temzasse / useParsedSearchParams.tsx
Last active April 6, 2024 10:12
A utility hook to parse and type URL search params based on a configuration object. This hook is useful when you want to access URL search params in a typesafe way and with proper casting.
import { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
type ParseConfig = Record<
string,
| { type: "string"; defaultValue?: string }
| { type: "number"; defaultValue?: number }
| { parse: (value: URLSearchParams) => unknown }
>;
public static class FileComparer
{
public static bool CompareEquals(string filePath1, string filePath2, int bufferSize = 65536)
{
if (filePath1 == filePath2) return true;
var buffer1 = ArrayPool<byte>.Shared.Rent(bufferSize);
var buffer2 = ArrayPool<byte>.Shared.Rent(bufferSize);
try
{
@tomaspietravallo
tomaspietravallo / ReactiveToVanilla.ts
Created July 5, 2021 21:35
Type for objects composed of Scalar/String/Boolean signals, that get snapshot'ed to their vanilla counterparts
type ReactiveToVanilla<Obj> = {
[Property in keyof Obj]:
Obj[Property] extends ScalarSignal ? number :
Obj[Property] extends StringSignal ? string :
Obj[Property] extends BoolSignal ? boolean
: any
};
import Scene from 'Scene';
import FaceTracking from 'FaceTracking';
import Animation from 'Animation';
/*
Model structure:
- Model
- skeleton (null)
- Armatures (null objs)
- Petal & pollen (meshes)
@celian-rib
celian-rib / useScrollBlock.ts
Last active May 24, 2024 08:54 — forked from reecelucas/useScrollBlock.js
React hook to enable/disable page scroll (Typescript version)
import { useRef } from 'react';
const safeDocument: Document = document;
/**
* Usage:
* const [blockScroll, allowScroll] = useScrollBlock();
*/
export const useScrollBlock = (): [() => void, () => void] => {
const scrollBlocked = useRef(false);
@lassemt
lassemt / script.js
Created January 15, 2020 19:45
SparkAR requestAnimationFrame alternative.
const t = require('Time');
const D = require('Diagnostics');
const Scene = require('Scene');
const objText = Scene.root.find('2dText0');
let frame = 0;
const round = (val, precision = 1) => {
const multiplier = Math.pow(10, precision || 0);
return Math.round(val * multiplier) / multiplier;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Laser Focused
// Ben Ursu | Afrosquared
// Spark AR Studio
// Instagram | https://www.instagram.com/a/r/?effect_id=206763150244323
@danamuise
danamuise / Earthquake frag shader
Created December 28, 2018 19:38
This is a GLSL post processor frag shader used in AR Spark (Facebook Messenger AR effects). It creates a random UV shaking effect.
varying vec2 hdConformedUV;
varying vec2 uv;
uniform sampler2D inputImage;
uniform int passIndex;
uniform vec2 uRenderSize;
uniform float uTime;
float random (in vec2 st)
{
return fract(sin(dot(st.xy, vec2(12.9898,78.233)))* 43758.5453123);
@walterpalladino
walterpalladino / Open Unity 16-9.scpt
Created October 18, 2018 16:36
How to Open the Unity Window on Mac OS X on a 16:9 relationship (1280x720)
tell application "Unity" to activate -- needs to be in front
tell application "System Events" to tell application process "Unity"
try
get properties of window 1
set size of window 1 to {1280, 720}
on error errmess
log errmess
-- no window open
end try
end tell
using UnityEngine.UI;
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
[ExecuteInEditMode]
public class LayoutElementFitParent : MonoBehaviour
{
[SerializeField] private float aspectRatio = 1;
[SerializeField] private bool updateMin = false;
[SerializeField] private bool updatePreferred = false;