Skip to content

Instantly share code, notes, and snippets.

@r-i-c-h
r-i-c-h / calcCanvasPointDistance.js
Created August 19, 2023 05:09
HTML Canvas Calculate Distance Between 2 Points
function calcDistBetweenPoints(pt1, pt2) {
const dx = pt1.x - pt2.x;
const dy = pt1.y - pt2.y;
// Distance = Pythagorean Theorem to get Hypoteneuse of triangle represented by the two points
// doing it with Math.sqrt() is apparently faster than going directly to Math.hypot() 🤷👌
return Math.sqrt((dx * dx) + (dy * dy));
}
@r-i-c-h
r-i-c-h / canvas-drawing-functions.js
Last active August 18, 2023 23:42
HTML Canvas Shape Drawing Functions
/*** Canvas Shape Drawing Functions ***/
// 1. drawStar() - Draw an n-pointed Star w/controls for outer and inner radii - [can make sorta-polygons too]
// 2. drawCircle() - Draw a circle (ctx.arc() wrapper)
// 3A. drawPoly1() - Draw an n-sided Polygon
// 3B. drawPoly2() - Draw an n-sided Polygon
// 3C. drawPoly3() - Draw an n-sided Polygon (controls for initial Rotation in Radians)
/* Assume the following setup: */
const canvas = document.getElementById('canvas1');
const ctx = canvas.getContext('2d');
@r-i-c-h
r-i-c-h / my.gitignore
Last active April 22, 2023 00:00
Rich's .gitignore File
# Rich's .gitignore file:
# See https://help.github.com/ignore-files/...
# leading-slash stops recursion, trailing slash = directory/
# >>>Notes <<<<
notes.txt
notes.md
localnotes.md
tutsrc.txt
# >>> Dependency directories <<<
@r-i-c-h
r-i-c-h / .bash_profile-Colorful-Git-Status-Prompt
Created June 22, 2020 04:43
My Colorful git-Status-aware prompt setup in my .bash_profile
# CRAZY COLORED NEW PROMPT w/repo Branch and Status:
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
@r-i-c-h
r-i-c-h / .bash_profile-stuff-1
Created June 22, 2020 04:38
Some of the aliases from my .bash_profile
# My Aliases
alias ..="cd .."
alias rmrf="rm -rf"
# ls on steroids:
alias see="ls -laShF | more"
# Some Apple MacOS specifics for showing/hiding hidden files in the Finder
alias showfiles="defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app"
alias hidefiles="defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
@r-i-c-h
r-i-c-h / tsconfig.json
Created January 30, 2020 20:07
Rich's tsconfig.json
{
"compilerOptions": {
"noImplicitAny": true,
"target": "es5",
"sourceMap": true,
"declaration": true,
"module": "es2015",
"moduleResolution": "node"
},
"exclude": [
@r-i-c-h
r-i-c-h / .prettierrc
Created January 24, 2020 00:28
Rich's .prettierrc
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
@r-i-c-h
r-i-c-h / .prettierignore
Created January 24, 2020 00:27
Rich's .prettierignore file
build/
node_modules/
package-lock.json
yarn.lock
package.json
*.html
@r-i-c-h
r-i-c-h / webpack.config.js
Last active January 24, 2020 13:52
Webpack Code Splitting
/* orig https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269 */
module.exports = {
entry: {
main: './src/app.js',
},
output: {
// `filename` provides a template for naming your bundles (remember to use `[name]`)
filename: '[name].bundle.js',
// `chunkFilename` provides a template for naming code-split bundles (optional)