Skip to content

Instantly share code, notes, and snippets.

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

Ifeora Okechukwu Patrick isocroft

😜
Seriously fooling around!
View GitHub Profile
@isocroft
isocroft / jest-custom-matchers.js
Created June 16, 2025 10:58
This is a file that holds a good amount of custom matchers for Jest
expect.extend({
toBeArrayContainingObject(received, argument) {
const pass = this.equals(received,
expect.arrayContaining([
expect.objectContaining(argument)
])
)
if (pass) {
@isocroft
isocroft / versionOne_ReactTestingLibrary_Async.js
Last active May 30, 2025 12:09
This is version 1 of a simple test for how using async/await with react testing library can slow down tests
import React, { useState } from "react";
import { render, act, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { roles, Components } from "constants/ui-copy";
function RecipeForm ({ onSubmit }) {
function formToObject(form) {
const formData = new FormData(form);
return Object.fromEntries(formData.entries());
}
@isocroft
isocroft / HttpButton.tsx
Last active April 15, 2026 19:06
A custom reactJS component for making a http request when JavaScript is disabled on the browser.
import React, { useRef, useEffect } from "react";
import Button from "./Button";
import type { ButtonProps } from "./Button";
import { useAuthTokenFromContext } from "../AuthProvider";
export const HttpButton = ({
children,
action,
enctype = "application/x-www-form-urlencoded",
@isocroft
isocroft / reader-tagged_comments_specification.md
Last active December 19, 2025 11:09
A basic specification for reader-tagged comments proposal (essay)

Reader-Tagged Comments Specification

A handy standard specification proposal for writing very useful comments directed at anyone reading software source code with aided understanding as the primary objective.

[1]. Front Matter

@isocroft
isocroft / intro_to_structured_concurrency_in_javascript_python_and_go.md
Last active April 29, 2026 18:03
This is a very easy and cool introduction to the world of structure concurrency in 3 different programming languages: JavaScript, Python & Go

Introduction To Structured Concurrency In Javascript, Python And Go

[PRIMER]: The 2 Models Of Concurrency

Threads are usually misunderstood. There are not all bad. They have simply been dealt a bad hand with pre-emptive scheduling and all its' attendant consequences e.g. locks and busy waits. Once threads are implemented using immutable variables, atomic message queues and cooperative scheduling, they operate much better. Sadly, there's little we can do about the overhead of state management for threads.

  1. Thread-based model of concurrency (e.g. well, Threads)
  2. Event-based model of concurrency (e.g. Actors + mailbox, E
@isocroft
isocroft / singleDB_multiTenancy_in_Laravel.php
Last active February 1, 2026 15:40
How to properly setup tenant scoping for routes and models (by centralizing the logic for scoping) in Laravel v11.x+, v12.x+ and v13.x+
<?php
namespace Parlie\Traits\Routing\Middleware\Guard;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
trait ApplyTenantRouteGuard {
@isocroft
isocroft / practical_guidelines_for_writing_great_tests_in_imperative-styled_programming_languages.md
Last active February 14, 2026 10:45
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 April 25, 2026 08:13
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
*/