Skip to content

Instantly share code, notes, and snippets.

View wiledal's full-sized avatar
🥃

Hugo Wiledal wiledal

🥃
View GitHub Profile
@wiledal
wiledal / pull_request_template.md
Last active November 17, 2023 08:46
PR Template

Description

Closes JIRA-XXXX

Type of change

  • 🐛 Bug fix
  • ✨ New feature
@wiledal
wiledal / deploy.yml
Created August 21, 2023 06:48
Github Actions - Monorepo deploy workflow
# Deploy frontend after successful backend deployment in sequence
# If frontend changed, deploy only frontend
# If backend changed, deploy only backend
# If frontend and backend, deploy frontend after backend
name: "Deploy services"
on:
push:
branches: ["main"]
jobs:
@wiledal
wiledal / try-catch.ts
Last active August 22, 2023 12:13
until.ts
/**
Value first, might be nicer
@example
const [value] = tryCatch(doSomething())
if (!value) {
// something went wrong
}
*/
const tryCatch = async <TSuccess, TError extends Error>(
@wiledal
wiledal / get-browser-platform.test.ts
Last active July 19, 2023 17:36
Get Browser Platform
import { getBrowserPlatform } from '@/src/lib/browser-platform/browser-platform';
const DESKTOP_UA =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36';
const IPHONE_UA =
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
const ANDROID_UA =
'Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36';
describe('browser-platform', () => {
@wiledal
wiledal / typed-css-modules-in-nextjs.md
Last active January 4, 2022 16:04
Add typed css modules in nextjs
@wiledal
wiledal / automator-ffmpeg-scripts.sh
Last active February 10, 2023 08:31
OSX Automator FFMPEG scripts
# Convert a video file to 720p with 24fps
/opt/homebrew/bin/ffmpeg -i "$@" -preset slow -codec:a aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 2500k -minrate 1500k -maxrate 4000k -bufsize 5000k -vf scale=-1:720 -filter:v fps=24 "$@-converted.mp4"
# Simpler
/opt/homebrew/bin/ffmpeg -y -i "$@" -preset slow -codec:a aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 2500k -filter:v "scale=-2:720, fps=48" "$@-converted.mp4"
# Convert audio to .mp3
/opt/homebrew/bin/ffmpeg -y -i "$@" -vn -ar 44100 -ac 2 -b:a 192k "$@.mp3"
@wiledal
wiledal / calculate-three-viewport-at-depth.ts
Created October 21, 2021 15:13
Calculate ThreeJS viewport at depth
import { PerspectiveCamera } from "three";
export const getDepthPositionMult = (depth: number, camera: PerspectiveCamera) => {
const { aspect, fov } = camera;
const vFov = (fov * Math.PI) / 180;
const planeHeightAtDistance =
2 * Math.tan(vFov / 2) * (depth + camera.position.z);
const planeWidthAtDistance = planeHeightAtDistance * aspect;
@wiledal
wiledal / use-konami.ts
Created August 23, 2021 20:10
Simple konami code hook
import { useEffect, useRef } from "react";
const UP = "ArrowUp";
const DOWN = "ArrowDown";
const LEFT = "ArrowLeft";
const RIGHT = "ArrowRight";
const B = "b";
const A = "a";
export const KONAMI_CODE = [UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, B, A];
@wiledal
wiledal / useGlobalState-usage.jsx
Last active May 17, 2019 00:05
A basic global-state hook pattern for React
import React from 'react'
import { useGlobalState } from '../hooks/useGlobalState.js'
export default function App () {
// The first time we call useGlobalState, we can set the default state, ignored after that.
const [ globalState, setGlobalState ] = useGlobalState({
count: 0,
theme: 'light'
})
@wiledal
wiledal / three-stencil-mask.js
Created February 22, 2019 09:25
Basic method to apply a stencil mask from objects in a scene to mask another scene
/*
Usage
init () {
const renderer = new THREE.WebGLRenderer()
const camera = new THREE.PerspectiveCamera()
renderer.autoClear = false // turn off clearing of renderer on each render-call
const scene1 = new THREE.Scene() // scene with stencil objects