Skip to content

Instantly share code, notes, and snippets.

View isocroft's full-sized avatar
😜
Seriously fooling around!

Ifeora Okechukwu isocroft

😜
Seriously fooling around!
View GitHub Profile
@isocroft
isocroft / singleDB_multiTenancy_in_Laravel.php
Last active June 5, 2025 13:19
How to properly setup tenant scoping for routes and models (by centralizing the logic for scoping) in Laravel 9.x+, 10.x+, 11.x+, 12.x+ and 13.x+
<?php
/* Laravel Config */
$config = [
'tenants' => [
'mirrors' => [
'id_name' => 'slug_id',
'id_type' => 'uuid_v4' // 'uuid_v4', 'cuid_v2'
],
'column_key' => 'tenant_id'
@isocroft
isocroft / practical_guidelines_for_writing_great_tests_in_imperative-styled_programming_languages.md
Last active July 17, 2025 05:48
These are the practical guidelines for writing great tests in imperative-styled programming languages

Practical Guidelines For Writing Great Tests In Imperative-styled Programming Languages (e.g Go, Python, Rust, JavaScript)

Common Testing Issues

All common issues with tests from flaky tests to brittle and tests can all be traced back to either coupling or dangling side-effects.

There are several types of coupling that can affect tests as follows:

@isocroft
isocroft / errorChecker.js
Last active May 14, 2025 13:54
An error checker experiment to surface errors up the call-stack
const isPromise = () => {
};
const isPrimitive = (target) => {
return ['number', 'boolean', 'string'].includes(typeof target);
};
const isError = (target) => {
if (!(target instanceof Object)) {
@isocroft
isocroft / reactOtelInstrumentationScript.ts
Last active May 26, 2025 19:45
An Opentelemetry auto-instrumentation script for ReactJS apps
//import { ZipkinExporter } from "@opentelemetry/exporter-zipkin";
import api, { Span, SpanStatusCode, SpanOptions, SpanKind } from "@opentelemetry/api";
import { OTLPTraceExporter } from "@opentelemetry/exporter-otlp-http";
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
import { SimpleSpanProcessor, ConsoleSpanExporter, BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { ZoneContextManager } from "@opentelemetry/context-zone";
import { Resource } from "@opentelemetry/resources";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
@isocroft
isocroft / apiVersionedDTOContractNormalizer.php
Last active May 4, 2025 11:06
A normalizer (adapter) for api versioned contract DTOs used to fully decouple API responses in a modular monolith or micro-service - inverted rolling versions
<?php
/**
* To truly decouple one dependent code from another dependency, there must be full collaboration
* or full disaffiliation. There are no in-betweens
*
* The Open-Close principle gets in the way of that:
*
* See: https://isocroft.medium.com/the-open-close-principle-is-backwards-and-broken-930646d92f8b
*/
@isocroft
isocroft / useResumableFileUploader.tsx
Last active May 14, 2025 09:31
A ReactJS hook for setting up a resumable file upload using a tus client + a tus server
import { useEffect, useCallback, useRef, useState, useMemo } from "react";
import { Upload } from "tus-js-client";
enum UploadStatus {
IDLE = "idle",
UPLOADING = "uploading",
PAUSED = "paused",
RESUMED = "resumed",
COMPLETED = "completed",
ERROR = "error",
@isocroft
isocroft / race.js
Last active May 24, 2025 12:42
A basic (yet slightly coupled) setup for cancelling either of 2 concurrent tasks racing each other to completion (i.e. to a promise settlement)
class HttpResponseError extends Error {
constructor (message, response) {
super(message);
this.response = response
}
}
async function simpleFetch(
url /* @type( string | RequestInfo | URL ) */,
options /* @type( Omit<RequestInit, "signal"> && { controller: AbortController } ) */
@isocroft
isocroft / useInfiniteScrollForQueries.tsx
Last active April 7, 2025 20:58
React Infinite Scroll Hook using react-query and react-busser
import { useEffect } from "react";
import { useIsDOMElementVisibleOnScreen } from "react-busser";
import type { InfiniteQueryResult, InfiniteQueryKey, InfiniteQueryFunction, InfiniteQueryOptions } from "react-query";
import { useInfiniteQuery } from "react-query";
export type InfiniteScrollQueryOptions<TK, TR, TMV, TE> = {
queryKey: InfiniteQueryKey<TK>;
queryFn?: InfiniteQueryFunction<TR, TK, TMV>;
config?: InfiniteQueryOptions<TR, TMV, TE>;
};
@isocroft
isocroft / GoogleTagManager.tsx
Created April 6, 2025 21:30
Google tag manager component for ReactJS in NextJS RSC
"use client"
import { useEffect } from "react";
import TagManager from "react-gtm-module";
export default function GoogleTagManager () {
useEffect(() => {
const gtmId = process.env.NEXT_PUBLIC_GTM_ID;
if (gtmId) {
TagManager.initialize({ gtmId });
@isocroft
isocroft / flexibleAPIEndpoints.py
Last active May 20, 2025 22:14
A python script that makes any API endpoints wrapper very easy to create and modify
import requests
import json
import re
import urllib.parse
from datetime import datetime, date
__all__ = [
"PayStacky"
]