Skip to content

Instantly share code, notes, and snippets.

View gielcobben's full-sized avatar
💩
Hi

Giel gielcobben

💩
Hi
View GitHub Profile
@gielcobben
gielcobben / useRect.js
Created October 24, 2019 09:34 — forked from morajabi/useRect.js
useRect — getBoundingClientRect() React Hook with resize handler
import { useLayoutEffect, useCallback, useState } from 'react'
export const useRect = (ref) => {
const [rect, setRect] = useState(getRect(ref ? ref.current : null))
const handleResize = useCallback(() => {
if (!ref.current) {
return
}
@gielcobben
gielcobben / Animation.ts
Created March 29, 2019 15:08
useAnimation
import * as React from "react"
function useAnimationTimer(duration = 1000, delay = 0) {
const [elapsed, setTime] = React.useState(0)
React.useEffect(() => {
let animationFrame, timerStop, start
// Function to be executed on each animation frame
function onFrame() {
@gielcobben
gielcobben / personal-raf-boilerplate.js
Created January 21, 2018 17:19 — forked from bendc/personal-raf-boilerplate.js
requestAnimationFrame boilerplate code
"use strict";
// animation utils
// ===============
const trackTime = timing => {
const now = performance.now();
if (!timing.startTime) timing.startTime = now;
const elapsed = now - timing.startTime;
@gielcobben
gielcobben / optimise-images-terminal.md
Last active April 16, 2024 23:38
Optimise your pngs from the terminal in OSX

JPG:
$ brew install jpegoptim
$ find . -name "*.jpg" -exec jpegoptim -m80 -o -p --strip-all {} \;

- PNG:
$ brew install optipng
$ find . -name "*.png" -exec optipng -o7 {} \;