Skip to content

Instantly share code, notes, and snippets.

View RichardMarks's full-sized avatar

Richard Marks RichardMarks

View GitHub Profile
@RichardMarks
RichardMarks / README.md
Created September 5, 2023 21:02
Godot 4.1.1 Testing opening Window and FileDialog on macOS
  • When exporting an .app for macOS in Debug mode, everything works as-expected.

  • When exporting an .app for macOS in Release mode, the buttons do nothing at all.

@RichardMarks
RichardMarks / clearTimers_Snippet.js
Created March 25, 2020 18:30
clearTimers Chrome Snippet
(function () {
if (window.clearTimers) {
console.log('clearTimers snippet already available. execute "clearTimers()" in your console.')
return
}
const clearTimers = () => {
try {
const noop = () => {}
const nextId = setTimeout(noop)
@RichardMarks
RichardMarks / Controller.js
Created March 11, 2020 23:28
Versatile JS Controller/Plugin System
const Controller = () => {
const controller = {
__VERSION__: '1.0.0',
plugins: {},
installPlugin (plugin, override) {
if (!plugin || !('__pluginName__' in plugin)) {
throw new Error(`Controller was unable to install plugin - Invalid plugin was provided.`)
}
@RichardMarks
RichardMarks / promises.js
Created February 6, 2020 14:54
Promise catch order explained
// Promise catch order explained
// When catch() comes before then() in the promise chain,
// exceptions that occur in the then() handler will not be caught.
// If the promise rejects, the catch() handler will be called.
// If the catch() handler returns a value or a promise that resolves,
// the then() handler will be called.
mayThrowAnException()
@RichardMarks
RichardMarks / scaleValueToRange.js
Created March 28, 2019 18:39
Scale Value to Range
const scaleValueToRange = ({
value = 0,
fromMinimum = 0,
fromMaximum = 1000,
toMinimum = -100,
toMaximum = 100
}) => {
const scaledValue = (( value - fromMinimum) / (fromMaximum - fromMinimum)) * (toMaximum - toMinimum) + toMinimum
return {
fromMinimum,
@RichardMarks
RichardMarks / Toast.css
Last active July 10, 2022 14:39
React Hooks Toast Example
.toasts-container {
position: fixed;
z-index: 65535;
right: 0;
max-width: 250px;
display: flex;
flex-direction: column-reverse;
}
.toasts-container > .toast-container {
@RichardMarks
RichardMarks / maxProduct.js
Created September 28, 2018 04:40
Maximum Product of Two Positive Integers
const maxProduct = numbers => {
const count = numbers.length
let left = 0
let right = 0
for (let i = 0; i < count; i += 1) {
if (numbers[i] > left || numbers[i] > right) {
if (left < right) {
left = numbers[i]
} else {
right = numbers[i]
@RichardMarks
RichardMarks / move_sprite.py
Created September 17, 2018 18:14
normalized 8-directional sprite movement using lookup tables
def move_sprite(sprite, dt, key_up, key_down, key_left, key_right):
"""
returns the x and y tuple offset for normalized 8-directional movement
sprite is expected to have x, y, x_speed, and y_speed properties
speed is expected to be represented in pixels per second
"""
# Note: using legacy "mm" and "mt" variable names
# whose original meaning has been forgotten over the last 20 years
mm = [0, 0, 1, 3, 1, 2, 0, 0, 3, 1, 5, 5, 5, 4, 0, 0, 2, 1, 4, 5, 4, 4]
mt = [0, 0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475]
@RichardMarks
RichardMarks / image-crop-tool.py
Created September 13, 2018 18:27
Python3 Image Crop Tool
#!/usr/bin/env python3
# Image Crop Tool v1.0
# (C) Rambling Indie Games, LLC
# Developed by Richard Marks <[email protected]>
# depends on Pillow third party library for PIL in Python 3.6
# pip3 install pillow
from PIL import Image
import json
@RichardMarks
RichardMarks / poker.cpp
Created April 22, 2018 03:50
C++ Poker
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <iterator>
#include <string>
#include <sstream>
#include <cassert>
class Card {