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 / 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;
const withPlugins = require('next-compose-plugins');
const path = require('path');
module.exports = withPlugins([], {
webpack: (config) => {
const clientEnv = process.env.CLIENT_ENV || 'production';
config.resolve.alias = {
...config.resolve.alias,
environment: path.join(__dirname, 'src', 'environments', clientEnv),
export const IndexPage = (props) => {
const onChange = async (formData) => {
const config = {
headers: { 'content-type': 'multipart/form-data' },
onUploadProgress: (event) => {
console.log(`Current progress:`, Math.round((event.loaded * 100) / event.total));
},
};