Skip to content

Instantly share code, notes, and snippets.

View flamerohr's full-sized avatar

Chris Joe flamerohr

  • Auckland, New Zealand
View GitHub Profile
@flamerohr
flamerohr / use-animation-frame.js
Last active October 5, 2020 09:30
An animation frame hook
import {
useRef, useLayoutEffect,
} from 'react';
const FRAME_RATE = 1000 / 60;
/**
* A react hook for using animation frame, which will cancel when unmounted.
* This was intended for basic drawing logic on a canvas, anything too complex should
* consider using a drawing library instead.

Keybase proof

I hereby claim:

  • I am flamerohr on github.
  • I am flamerohr (https://keybase.io/flamerohr) on keybase.
  • I have a public key ASBNMetcQv0IpOF-nl4963iBezu0LfGNAG_WJSmAOROv7wo

To claim this, I am signing this object:

049955ca0b42c586a5422a9d47fe1edf80c871b90740b2784a563af708a33859b7196059d704cec6881facc187e12bdb2c1f1868ebe66393b50003696bf9d037da;JonForest
@flamerohr
flamerohr / gist:b08ba075b6cca48cd569
Last active August 29, 2015 14:06
Check for jquery ajax parse errors
// glocal function to use with the success in all $.ajax calls
// two callbacks are given, to handle when the ajax data succeeds and when the ajax data fails.
function check_response(success_callback, error_callback) {
// the function the success will call
var check(data, textStatus, jqXHR) {
try {
// try to parse the json
data = $.parseJSON(data);