Skip to content

Instantly share code, notes, and snippets.

View computercam's full-sized avatar
👁️

Cameron computercam

👁️
View GitHub Profile

Saved for my personal reference, all content belongs to codetheory.in

Controlling the Frame Rate with requestAnimationFrame

Limiting the frame rate while using requestAnimationFrame can be a common want especially when coding Games where you want your animations and mechanics to not exceed a particular mark of frames per second. Let’s go through 2 ways of doing it.

Quick and Easy Way

Using setTimeout inside the rAF method is an easy way.

@computercam
computercam / getGrid.js
Created June 19, 2022 14:05
generates a flat array of data for a four quadrant grid
export function getGrid (size) {
const length = Math.pow(size, 2)
const offset = (size / 2) * -1
const grid = Array.from({ length }).map((_, index, array) => {
const row = Math.floor(index / size)
const column = index % size
const x = row + offset + 0.5
const y = column + offset + 0.5
@computercam
computercam / README.md
Last active February 28, 2024 17:30
Record Screen. Script and cronjob to automate recording osx screen

Requires ffpmeg

brew install ffmpeg

Make sure the script is executable

chmod u+x /Volumes/External/screenshots/record_screen
@computercam
computercam / fixvscode.sh
Created December 6, 2020 20:37
VSCodium / CODE-OSS visual studio marketplace product.json
#!/usr/bin/env bash
[[ `uname` == "Linux" ]] && PRODUCT_JSON="/usr/lib/code/product.json"
[[ `uname` == "Darwin" ]] && PRODUCT_JSON="/Applications/VSCodium.app/Contents/Resources/app/product.json"
echo "edit the following file"
echo "$PRODUCT_JSON"
echo ""
echo "find the following property"
echo "extensionsGallery"
echo ""
@computercam
computercam / nextcloud-docker-backup.sh
Last active September 18, 2024 17:13
docker nextcloud backup / restore
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TIMESTAMP=`date +"%Y-%m-%d-%T"`
BACKUP_DIR="${DIR}/${TIMESTAMP}"
APPDATA_DIR="${DIR}/../appdata"
MYSQL_USER="root"
MYSQL_PASSWORD="abc123"
MYSQL_DB="nextcloud_db"
#!/bin/sh
tmp="`mktemp`"
url="https://api.github.com/users/ferrybig/repos?per_page=100"
while [ ! -z "$url" ]; do
echo "Fetching $url..." >&2
curl --dump-header "$tmp" "$url"
url="`< "$tmp" grep Link | grep -oE "[a-zA-Z0-9:/?=.&_]*>; rel=.next" | cut -d'>' -f1`"
done | grep clone_url | cut -d'"' -f4 | while read url;
do
project="`basename "$url"`"
@computercam
computercam / ext4magic_recover_text.sh
Created April 30, 2020 04:09
ext4magic recover text files
# Recover files from ext4magic based on the path to the missing textfile
# After running ext4magic -m /path/to/device, from the directory containing RECOVERDIR, run this script with the path to the directory containing text files you want to recover.
# Example:
# ext4magic_recover_text.sh /home/cameron/lostfiles
function get_timestamp() {
date -d @${1} | cut -d' ' -f1-6 | sed 's/ /_/g'
}
for file in $(grep -Rl $1 ./RECOVERDIR/ 2> /dev/null)
#!/bin/bash
# !!WARNING!!
# This will DELETE all efforts you have put into configuring nix
# Have a look through everything that gets deleted / copied over
nix-env -e '.*'
rm -rf $HOME/.nix-*
rm -rf $HOME/.config/nixpkgs
import subprocess
import re
command = ['qdbus', 'org.kde.plasmashell', '/PlasmaShell', 'org.kde.PlasmaShell.evaluateScript']
command.append("""
var allDesktops = desktops();
for (i=0;i<allDesktops.length;i++)
{
d = allDesktops[i];
d.wallpaperPlugin = "org.kde.image";
@computercam
computercam / git-cheat-sheet.md
Created May 29, 2019 16:01 — forked from juristr/git-cheat-sheet.md
My Git cheat sheet

Git Cheat Sheet

Committing and Undoing

Adding file for committing

$ git add <filename>