Skip to content

Instantly share code, notes, and snippets.

View tpjnorton's full-sized avatar

Tom Norton tpjnorton

View GitHub Profile
@tpjnorton
tpjnorton / useWebSocket.ts
Last active October 28, 2020 10:27
A Handy React Hook for creating auto-closing WebSockets.
const useWebSocket = (url, protocols, onMessage, onError) => {
const ws = useRef(null);
useEffect(() => {
const socket = new WebSocket(url, protocols);
socket.onmessage = onMessage;
socket.onerror = onError;
ws.current = socket;
return () => {
ws.current.close();
};
const useMounted = () => {
const isMounted = useRef(false);
useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
@tpjnorton
tpjnorton / .bashrc
Created April 9, 2018 06:55
Webots Development Environment Variables
export WEBOTS_HOME=/home/tom/develop/$WEBOTS_VER
export LD_LIBRARY_PATH="/home/tom/develop/$WEBOTS_VER/lib"
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export WEBOTS_ALLOW_MODIFY_INSTALLATION=true
export WEBOTS_DISABLE_SAVE_PERSPECTIVE_ON_CLOSE=1
alias web="cd $WEBOTS_HOME"
alias webots=/home/tom/develop/$WEBOTS_VER/webots
alias trans="web; git checkout -- $WEBOTS_HOME/resources/translations"
alias mks="make release -j 12 -C $WEBOTS_HOME/src/webots"