Skip to content

Instantly share code, notes, and snippets.

View wiledal's full-sized avatar
πŸ₯ƒ

Hugo Wiledal wiledal

πŸ₯ƒ
View GitHub Profile
@wiledal
wiledal / process.sh
Created May 4, 2017 14:40
Batch process images
for i in *.png; do ffmpeg -i $i -vf scale=500:500 $i -y; done
@wiledal
wiledal / tools.js
Last active August 3, 2018 13:52
Deployment Tools
#!/usr/bin/env node
const spawn = require('child_process').spawn
const argv = process.argv
const servers = {
internal: [
{
user: 'root',
host: 'your internal setup',
@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
@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 / 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 / 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 / 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 "[email protected]"
# 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" "[email protected]"
# Convert audio to .mp3
/opt/homebrew/bin/ffmpeg -y -i "$@" -vn -ar 44100 -ac 2 -b:a 192k "[email protected]"
@wiledal
wiledal / typed-css-modules-in-nextjs.md
Last active July 9, 2024 08:38
Add typed css modules in nextjs
@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 / 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>(