Skip to content

Instantly share code, notes, and snippets.

View LordZardeck's full-sized avatar

Sean Templeton LordZardeck

View GitHub Profile
@LordZardeck
LordZardeck / README.md
Created April 10, 2024 03:37
Simple Context Store with useSyncExternalStore

Simple Context Store with useSyncExternalStore

Sometimes we don't want to prop drill or have many components where we don't know where they will exist in the component tree, but have frequent enough updates where a simple Context will cause unncessary re-renders or performance issues. By utilizing useSyncExternalStore with a simple store, we can avoid this and have only the components who care about the updates get re-rendered.

This may be similar to something like Redux or Zuestand, but for simple things, those are overkill to import an entire package for. The example I provided above can be a nice quick way of handling these occasional use cases without diving full send into a state management library.

@LordZardeck
LordZardeck / example.js
Created August 23, 2022 17:52
Sequential Promises using Map Reduce
[1, 2, 3, 4, 5]
.reduce(
sequentialPromise(element => new Promise(resolve =>
setTimeout(
() => {
console.log(`Handled ${element}`);
resolve(element * Math.floor(Math.random() * 100));
},
Math.random() * 1000
)
@LordZardeck
LordZardeck / deepMapGet.js
Last active July 7, 2022 16:38
Deep Map Get/Set
function deepMapGet(map, keys) {
return keys.reduce(
(resultValue, key) =>
resultValue === undefined ? resultValue : resultValue.get(key),
map,
);
}
import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import sqlite from 'sqlite3';
import {
app,
remote
} from 'electron';
const basename = path.basename(__filename);
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
[ExecuteInEditMode]
public class HandManager : MonoBehaviour
{
/// <summary>
/// The area of a card that should be used to determine whether to select the previous, current, or next card
@LordZardeck
LordZardeck / Result.md
Last active February 13, 2018 19:27
Crazy feature I discovered in PHP. You can access protected properties of a instance if the method that's accessing those protected propteries exist on the same type of that instance, even if it's not the instance you are accessing from. Seems similar to C# nested types: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-an…

HasProtectedProperty

string(6) "foobar"

HasPrivateProperty

string(6) "barfoo"
@LordZardeck
LordZardeck / MagentoController.php
Created January 18, 2018 16:21
Reference to how to prevent access to a page for guests in Magento 2
<?php
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
class Index extends Action
{
@LordZardeck
LordZardeck / prepare-commit-msg
Last active May 31, 2020 14:59
Git hook to prepend Active Collab GUIDs for tasks to the commit message. Requires branch names to contain the GUID, such as `feature/ABC-123_456-my-branch-feature`. To install, place the file in your project's `.git/hooks` directory
#!/bin/sh
ticket=$(git symbolic-ref HEAD | grep -e '[A-Z]\+-[0-9]\+_[0-9]\+' -o)
if [ -n "$ticket" ]; then
echo "$ticket - $(cat $1)" > $1
fi
@LordZardeck
LordZardeck / GDD.md
Created June 26, 2017 15:40
Game Design Document Markdown Template

Revision: 0.0.1

GDD Template Written by: Benjamin “HeadClot” Stanley

  • Overview
    • Theme / Setting / Genre
    • Core Gameplay Mechanics Brief
  • Targeted platforms
@LordZardeck
LordZardeck / config.js
Created August 18, 2016 05:56
GistRun Angular w/ Babel Starter Kit
/* global System */
System.defaultJSExtensions = true;
System.config({
transpiler: "babel",
babelOptions: {
stage: 0,
optional: [
"runtime"