Skip to content

Instantly share code, notes, and snippets.

View moritzsalla's full-sized avatar

Moritz Salla moritzsalla

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Shell cheatsheet

Count all words in specific file type in sub directory

find . -name "*.md" -type f -exec cat {} + | wc -w
@moritzsalla
moritzsalla / contour-shader.md
Last active May 25, 2022 20:37
Contour tracer shader
// contour isoline cartography shader
export const frag = `
  #extension GL_OES_standard_derivatives : enable
  #ifdef GL_ES
   precision highp float;
  #endif

  varying vec2 var_vertTexCoord;
@moritzsalla
moritzsalla / hook-fallback.tsx
Last active January 7, 2023 20:35
Some react tricks
// fallback for a partially supported hook
// source https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/hooks/use-id.ts
import React from 'react'
import { useIsoMorphicEffect } from './use-iso-morphic-effect'
import { useServerHandoffComplete } from './use-server-handoff-complete'
import { env } from '../utils/env'
export let useId =
// Prefer React's `useId` if it's available.
@moritzsalla
moritzsalla / skip-build.sh
Created February 4, 2023 22:24
Skip Vercel build step
#!/bin/bash
echo "VERCEL_GIT_COMMIT_MESSAGE: $VERCEL_GIT_COMMIT_MESSAGE"
if [[ "$VERCEL_GIT_COMMIT_MESSAGE" != *"[skip build]"* ]] ; then
# Proceed with the build
exit 1;
else
# Don't proceed with the build
@moritzsalla
moritzsalla / test.yml
Created August 2, 2023 16:01
Github action - Unit test
name: Tests
on:
pull_request:
jobs:
Unit:
runs-on: ubuntu-latest
strategy:
const FocusDemo = () => {
// with callback
const [inputRef, setInputFocus] = useFocus<HTMLInputElement>();
// on component mount
const ref = useAutoFocus<HTMLInputElement>();
return (
<>
<button onClick={setInputFocus} >
import { useEffect, useRef } from "react";
/**
* A React hook that returns true if the component is being rendered for the first time.
*
* @returns boolean
* @example
* ```tsx
* import { useIsInitialRender } from "hooks/useIsInitialRender";
*
const TIMEOUT_DURATION_MS = 3000;
/**
* Fetches a resource with a timeout.
*
* @param input - The resource to fetch.
* @param init - The options for the fetch.
* @param timeoutDuration - The timeout duration in milliseconds.
*
* @returns A promise that resolves to the response of the fetch.
@moritzsalla
moritzsalla / concurrent-fetch.test.ts
Created September 5, 2023 15:56
concurrent-fetch
import { suppressConsoleLogs } from "test/utils/suppressConsoleLogs";
import { concurrentFetch } from "./concurrentFetch";
describe("concurrentFetch", () => {
it(
"should return an array of resolved values",
suppressConsoleLogs(async () => {
const result = await concurrentFetch(
Promise.resolve("value1"),