Skip to content

Instantly share code, notes, and snippets.

View DarkRoku12's full-sized avatar
🏠
Working from home

DarkRoku12 DarkRoku12

🏠
Working from home
  • Dominican Republic
View GitHub Profile
@DarkRoku12
DarkRoku12 / useWatched.ts
Last active December 25, 2023 02:18
Reach hook: useWatched
import { useState } from "react";
import { SymbolAddWatcher, SymbolForAll, Watched } from "./constants";
export type RecordIndex = string | number | symbol;
export type AnyRecord = Record<RecordIndex, any>;
export type RecordObj<T extends AnyRecord> = T & AnyRecord;
export default function useWatched<T extends AnyRecord>(
watched: Watched<T>,
watchList: Array<keyof T> | Array<string | symbol> = [SymbolForAll],
@DarkRoku12
DarkRoku12 / useUnwatched.ts
Created December 25, 2023 02:07
React hook: useUnwatched
/* eslint-disable @typescript-eslint/ban-types */
import { AnyRecord, RecordObj, SymbolAddWatcher, SymbolForAll, Watched } from "@hooks/constants";
export default function useUnwatched<T extends AnyRecord>(state: RecordObj<T> = {} as AnyRecord) {
const watchList = {} as Record<string | symbol, Function[]>;
const proxyHandler = {
set(_target: any, prop: any, value: any) {
Reflect.set(state, prop, value);
const propStateSetters = watchList[prop] || [];
@DarkRoku12
DarkRoku12 / constants.ts
Created December 25, 2023 02:06
React constants for custom hook.
/** Created by DarkRoku12 */
export const SymbolAddWatcher = Symbol("__addWatcher");
export const SymbolForAll = Symbol("__forAll");
export type RecordIndex = string | number | symbol;
export type AnyRecord = Record<RecordIndex, any>;
export type RecordObj<T extends AnyRecord> = T & AnyRecord;
// eslint-disable-next-line @typescript-eslint/ban-types
export type Watched<T extends AnyRecord> = RecordObj<T> & { [SymbolAddWatcher]: Function };
@DarkRoku12
DarkRoku12 / ts-indent.js
Last active September 8, 2023 05:29
TypeScript compatible indent rule for ESLint.
// Taken inspiration and adapted from:
// https://github.com/funmaker/eslint-plugin-indent-empty-lines/blob/4f397f490dcf0329feccef6df23b32e366fc2faf/lib/rules/indent-empty-lines.js
// https://github.com/eslint/eslint/blob/60f6a06f521c514e3834dd9f82821b10c69a5f00/lib/rules/no-trailing-spaces.js
// https://astexplorer.net -> Configure: @typescript-eslint.
// Created by DarkRoku12.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
The logic behind this code is to indent the first 'token' in the line if the indentation is not correct.
To achieve that, we need to remove the previous indentation and then set our desired one.
@DarkRoku12
DarkRoku12 / ps_system.cpp
Created July 19, 2021 19:40
Base particle system for 2D game engine
#include <algorithm>
#include "ps_system.hpp"
#include "ps_particle.hpp"
#include "ps_emitters.hpp"
// Effects - Multi-thread:
void ParticleSystem::applyEffectsMultiThread( int id , updater_data ud )
@DarkRoku12
DarkRoku12 / postgresql.conf
Created July 19, 2021 17:08
For blog post: Does columns order matters?
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
@DarkRoku12
DarkRoku12 / CountryCodes.json
Created September 2, 2017 23:24 — forked from Goles/CountryCodes.json
Country and Dial or Phone codes in JSON format
[{"name":"Israel","dial_code":"+972","code":"IL"},{"name":"Afghanistan","dial_code":"+93","code":"AF"},{"name":"Albania","dial_code":"+355","code":"AL"},{"name":"Algeria","dial_code":"+213","code":"DZ"},{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},{"name":"Andorra","dial_code":"+376","code":"AD"},{"name":"Angola","dial_code":"+244","code":"AO"},{"name":"Anguilla","dial_code":"+1 264","code":"AI"},{"name":"Antigua and Barbuda","dial_code":"+1268","code":"AG"},{"name":"Argentina","dial_code":"+54","code":"AR"},{"name":"Armenia","dial_code":"+374","code":"AM"},{"name":"Aruba","dial_code":"+297","code":"AW"},{"name":"Australia","dial_code":"+61","code":"AU"},{"name":"Austria","dial_code":"+43","code":"AT"},{"name":"Azerbaijan","dial_code":"+994","code":"AZ"},{"name":"Bahamas","dial_code":"+1 242","code":"BS"},{"name":"Bahrain","dial_code":"+973","code":"BH"},{"name":"Bangladesh","dial_code":"+880","code":"BD"},{"name":"Barbados","dial_code":"+1 246","code":"BB"},{"name":"Belarus","dial_code":"+375","
@DarkRoku12
DarkRoku12 / LICENCE SUBLIME TEXT
Created August 24, 2017 06:36 — forked from RoseySoft/LICENCE SUBLIME TEXT
Sublime Text 3 Serial key build is 3103
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
93F6323C FD7F7544 3F39C318 D95E6480
FCCC7561 8A4A1741 68FA4223 ADCEDE07