Hi all. I am

Muhammad Ahmad

>

// Where am I based?

constlocation="Lahore, Pakistan"

// Are you open to new opportunities?

constavailability="Open to work"

// What can we build together?

constemail="hello@mahmad.xyz"

  • // PHP: Remove empty elements from array recursively
    function array_filter_recursive($input) {
        foreach ($input as &$value) {
            if (is_array($value)) {
                $value = array_filter_recursive($value);
            }
        }
        return array_filter($input);
    }
  • // WordPress: Disable Gutenberg editor for posts
    add_filter('use_block_editor_for_post', '__return_false', 10);
  • // TypeScript: DeepReadonly utility type
    type DeepReadonly<T> = {
        readonly [P in keyof T]: DeepReadonly<T[P]>;
    };
  • // JavaScript: Copy text to clipboard with fallback
    async function copyToClipboard(text) {
        if (navigator.clipboard) {
            await navigator.clipboard.writeText(text);
        } else {
            const temp = document.createElement('textarea');
            temp.value = text;
            document.body.appendChild(temp);
            temp.select();
            document.execCommand('copy');
            document.body.removeChild(temp);
        }
    }
  • // Next.js API Route: Simple JSON response
    // pages/api/ping.ts
    import type { NextApiRequest, NextApiResponse } from 'next'
    
    export default function handler(req: NextApiRequest, res: NextApiResponse) {
        res.status(200).json({ message: "pong" });
    }
  • // PHP: Get custom field (ACF) outside the loop in WordPress
    $post_id = 42;
    $value = get_field('custom_field_name', $post_id);
  • // TypeScript: Type-safe object.keys
    function typedKeys<T extends object>(obj: T) {
        return Object.keys(obj) as Array<keyof T>;
    }
  • // JavaScript: Throttle function
    function throttle(fn, delay) {
        let last = 0;
        return (...args) => {
            const now = new Date().getTime();
            if (now - last >= delay) {
                fn.apply(this, args);
                last = now;
            }
        };
    }