Skip to content

Instantly share code, notes, and snippets.

View codeBelt's full-sized avatar
💭
I may be slow to respond.

Robert S. codeBelt

💭
I may be slow to respond.
View GitHub Profile
@codeBelt
codeBelt / code.md
Created November 14, 2025 22:20
Simple API Mock Code
const urlParams: string = config.params ? `?${new URLSearchParams(config.params).toString()}` : '';
const urlWithParams = url + urlParams;

const requestInit: RequestInit = {
  method: method.toUpperCase(),
  headers: config.headers,
  body: config.body ? JSON.stringify(config.body) : undefined,
};
const response =
/**
* A UI component that visually indicates the active Tailwind CSS breakpoint
* on the screen. It shows a floating indicator in the bottom-right corner of the page,
* displaying the current breakpoint based on the viewport width.
*
* This component is only rendered in development mode (`process.env.NODE_ENV !== 'production'`),
* helping developers quickly identify the active breakpoint while building responsive layouts.
*
* It uses the following breakpoints based on the default Tailwind CSS configuration:
* - XS (extra small) — `sm:hidden`
@codeBelt
codeBelt / example.md
Created January 23, 2024 02:53
TypeScript Object with Dynamic Keys
import SingletonRouter, { Router } from 'next/router';
import { useEffect } from 'react';
const defaultConfirmationDialog = async (msg?: string) => window.confirm(msg);
/**
* Inspiration from: https://stackoverflow.com/a/70759912/2592233
*/
export const useLeavePageConfirmation = (
shouldPreventLeaving: boolean,
@codeBelt
codeBelt / README.md
Created December 27, 2022 15:16 — forked from tnightingale/README.md
Canada Population
// JavaScript Version
export const buildFirstMiddleLastList = (list) => {
const { 0: first, [list.length - 1]: last, ...rest } = list;
return {
first: first,
middle: Object.values(rest),
last: list.length > 1 ? last : undefined,
};
// JavaScript Version
export const buildFirstMiddleLastList = (list) => {
const { 0: first, [list.length - 1]: last, ...rest } = list;
return [
first,
Object.values(rest),
list.length > 1 ? last : undefined
];
const arrayData = ['a', 'b', 'c', 'd', 'e'];
const arrayData = ['a', 'b', 'c', 'd', 'e'];
arrayData[0]; // First element is "a"
arrayData[arrayData.length -1]; // Last element is "e"
// Middle elements
arrayData[1]; // "b"
arrayData[2]; // "c"
arrayData[3]; // "d"
const arrayData = ['a', 'b', 'c', 'd', 'e'];
const { 0: first, [arrayData.length - 1]: last, ...rest } = arrayData;