Skip to content

Instantly share code, notes, and snippets.

@Glidias
Glidias / gist:4964488d24157b9046f8a3c5d301dde7
Last active June 11, 2023 09:40
Github copilot generated examples and commented fixes i had to make
// (example prompt, hardcoded array value generarted by AI successfully given starting array values of "[0, 1, 5..."
const quadTreeArrayLevelOffsets: Array<number> = [0, 1, 5, 21, 85, 341, 1365, 5461, 21845, 87381, 349525, 1398101, 5592405, 22369621, 89478485, 357913941, 1431655765, 5726623061, 22906492245, 91625968981, 366503875925, 1466015503701, 5864062014805, 23456248059221, 93824992236885, 375299968947541, 1501199875790165, 6004799503160661, 24019198012642645, 96076792050570581, 384307168202282325, 1537228672809129301, 6148914691236517205, 24595658764946068821, 98382635059784275285, 393530540239137101141, 1574122160956548404565, 6296488643826193618261, 25185954575304774473045, 100743818301219097892181, 402975273204876391568725, 1611901092819505566274901, 6447604371278022265099605, 25790417485112089060398421, 103161669940448356241593685, 412646679761793424966374741, 1650586719047173699865498965, 6602346876188694799461995861, 26409387504754779197847983445, 105637550019019116791391933781, 422550200076076467
@Glidias
Glidias / gist:802872bba5b948422d0675e3ba57e1d8
Last active March 23, 2022 10:50
Stateful state hook that may reset itself given outside conditions
/**
* @param callback Important: A *Memomized* callback reference (eg. via `useCallback()`) or a *Permanent* function
* to process/return a given lazy initialized state!
* State will re-update on next frame via useEffect if callback method supplied is different from previous case,
* but on subsequent renders only.
* @returns The state payload consisting of [state, setState]
*/
export function useStateByCallback<T>(callback: () => T) {
const payload = useState(callback);
const [, setVal] = payload;
@Glidias
Glidias / gist:34ad697d31ccbb16fe05742cedfc96a6
Last active March 23, 2022 10:51
useEffect hook that only triggers on subsequent renders when combined with useCallback
/**
* useEffect() that skips the first render execution before being mounted
* @param callback Important: A *Memomized* callback reference (eg. via `useCallback()`) or any other function
* to process/return a given lazy initialized state! eg. `usePostEffect(useCallback(.., [...]))`
* Callback will call again on next frame via useEffect() if callback method supplied is different from previous case,
* but on subsequent renders only.
*/
export function usePostEffect(callback: Function) {
const ref = useRef(false);
useEffect(() => {
@Glidias
Glidias / gist:2cbd4830566e07c7d5ba829d73d210ef
Created August 20, 2018 02:36
fiddling. Doesnt work. Just some ideas tossing about...
_callComponentMethod: function (name, dt) {
var wasLooping = this._beginLooping();
var nextN;
var lastN = null;
for (var n = this.compNodeList; n!=null; n=nextN) {
nextN = n.next;
var c = n.c;
if (c._destroyed || !c.entity.enabled || !c.enabled) {
if (lastN) {
lastN.next = nextN;
@Glidias
Glidias / skillsExpenditure
Last active May 8, 2019 03:44
SONG OF SWORDS: Character Creation Field formulas
SONG OF SWORDS: Character Creation UI Field formulas (for Beta 2.0)
/*
PSEUDO CODE LEGEND SUMMARY:
* instance field quantifier/process description
"the" - single/sole/final, etc.
"each" - for each, resolves to different results per instance
"all" - for all instances, resolves similarly across all instances
=> Direct instance implication/continuation (ie. holds internal field)
|=> per instance respective field value implication (1 to 1 relationships)