Skip to content

Instantly share code, notes, and snippets.

View aboqasem's full-sized avatar
🇵🇸

Mohammad Al Zouabi aboqasem

🇵🇸
View GitHub Profile
@aboqasem
aboqasem / use-event-listener.ts
Last active October 14, 2021 04:26
useEventListener - Event listener hook for React and Next.js
import { useEffect, useRef } from 'react';
type AllEventMaps = HTMLElementEventMap & DocumentEventMap & WindowEventMap;
export function useEventListener<K extends keyof HTMLElementEventMap>(
type: K,
listener: (event: HTMLElementEventMap[K]) => void,
element: HTMLElement,
): void;
@aboqasem
aboqasem / execute.js
Last active March 29, 2023 00:08
Script to ignore building & deploying unaffected Nx app in Vercel
// @ts-check
const { exec } = require('child_process');
/**
* @typedef {{ command: string; description?: string; } | string} CommandOptions
* @typedef {{ out?: string; err?: string; code: number | null }} CommandOutput
*/
/** @type {(options: CommandOptions) => Promise<CommandOutput>} */
function execute(options) {
@aboqasem
aboqasem / use-array.js
Last active April 16, 2022 00:35
useArray - React hook for managing the state of an array
import { useCallback, useRef, useState } from 'react';
export function useArray(initialState = []) {
const { current: originalState } = useRef(initialState);
const [array, setArray] = useState(initialState);
const setAt = useCallback(
(index, value) => {
const newArray = array.slice();
newArray[index] = value;
@aboqasem
aboqasem / vercel.skip.js
Created June 5, 2022 07:18
Vercel Ignore Build Step Script
// @ts-check
const build = () => process.exit(1);
const noBuild = () => process.exit(0);
const {
VERCEL, // An indicator that the app is deployed and running on Vercel. Example: 1.
CI, // An indicator that the code is running in a Continuous Integration environment. Example: 1. NOTE: This Variable is only exposed during Build Step.
VERCEL_ENV, // The Environment that the app is deployed an running on. The value can be either production, preview, or development.
VERCEL_URL, // The URL of the deployment. Example: my-site-7q03y4pi5.vercel.app
@aboqasem
aboqasem / class-names.ts
Created June 14, 2022 02:07
Simple styling utilites
/**
* Join string class names and ignore falsy values.
*
* ### Example
*
* ```tsx
* <div className={`class1 class2 class3 ${condition ? 'class4' : ''} ${data ? 'class5' : ''}`} />
* // becomes
* <div
* className={classNames(
Java 12 hrs 54 mins ██████████▉░░░░░░░░░░ 52.2%
sh 6 hrs 3 mins █████▏░░░░░░░░░░░░░░░ 24.5%
YAML 4 hrs 35 mins ███▉░░░░░░░░░░░░░░░░░ 18.6%
SQL 20 mins ▎░░░░░░░░░░░░░░░░░░░░ 1.4%
JSON 19 mins ▎░░░░░░░░░░░░░░░░░░░░ 1.3%
@aboqasem
aboqasem / biome.jsonc
Last active March 20, 2024 07:00
Biome Config
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"root": ".",
"clientKind": "git",
"useIgnoreFile": true
@aboqasem
aboqasem / dev-journal.md
Last active March 9, 2024 15:15
Dev Journal

Dev Journal

Git

  • Log all commits that add/delete the search_string in the repo

    git log -S search_string
@aboqasem
aboqasem / starter.sh
Created March 18, 2024 04:42
Bash script starter
#!/usr/bin/env bash
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425
set -euo pipefail
DEBUG=${DEBUG:-}
PWD=$(pwd)
SCRIPT_DIR=$(dirname "$0")
if [ -n "$DEBUG" ]; then
@aboqasem
aboqasem / bun-random-available-port.ts
Last active March 30, 2024 04:14
Get a random available port in Bun
function randomAvailablePort(): number {
const server = Bun.serve({ fetch: () => new Response(), port: 0 });
const port = server.port;
server.stop(true);
return port;
}