Skip to content

Instantly share code, notes, and snippets.

View MarwanShehata's full-sized avatar
🎯
"Luck is what happens when preparation meets opportunity.", Seneca

Marwan Shehata MarwanShehata

🎯
"Luck is what happens when preparation meets opportunity.", Seneca
View GitHub Profile
@MarwanShehata
MarwanShehata / dom-parent-collector.user.js
Last active May 17, 2025 18:37
DOM Parent Collector
// ==UserScript==
// @name DOM Parent Collector
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Collect DOM parents of clicked elements and organize them
// @author You
// @match *://*/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// ==UserScript==
// @name LinkedIn Easy Apply Bot (Enhanced)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automates applying to "Easy Apply" jobs on LinkedIn with UI and persistence.
// @author Your Name & Original Author
// @match *://www.linkedin.com/jobs/search/*
// @match *://www.linkedin.com/jobs/collections/*
// @match *://www.linkedin.com/jobs/view/*
// @grant GM_setValue
@MarwanShehata
MarwanShehata / ru-joblum-auto-apply.user.js
Created May 16, 2025 18:28
Joblum Board Auto-Apply
// ==UserScript==
// @name Joblum Board Auto-Apply
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automates applying to frontend web developer jobs on a job board.
// @author You
// @match *://ru.joblum.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
@MarwanShehata
MarwanShehata / type-safe-env
Last active April 23, 2025 19:46
This TypeScript code enhances environment variable type safety through Zod validation. It creates a schema that explicitly defines expected environment variables. The code then validates the current environment against this schema and extends TypeScr
/* eslint-disable @typescript-eslint/no-namespace */
/**
* Configuration for type-safe environment variables.
* Imported through src/app/page.tsx
* @see https://x.com/mattpocockuk/status/1760991147793449396
*/
import { z } from 'zod'
const envVariables = z.object({
@MarwanShehata
MarwanShehata / ts-decorator-component.ts
Last active April 4, 2025 18:45
This snippet demonstrates how to use a custom class decorator in TypeScript to dynamically enhance a class by adding new properties and methods. The `@Component` decorator injects a `uniqueID` and an `insertInDOM` method into the target class, showc
// TS Decorators
function Component(constructor: Function) {
// here we can do something like add/modify/enhance/delete properties from class methods
constructor.prototype.uniqueID = Math.random();
constructor.prototype.insertInDOM = () => {
console.log(`Inserting component in DOM`);
};
}
@MarwanShehata
MarwanShehata / exhaustive-switch-never.ts
Last active April 2, 2025 15:38
This ensures that if a new kind is added to the Animals type and isn't handled in the switch, TypeScript will catch it as a type error at compile time. 🚀
// type `never` is great for exhaustive checking, great for exhaustive switch statements
type Bird = {
kind: 'bird'
legs: number
wings: 2
}
type Dog = {
kind: 'dog'
legs: number
}
// ==UserScript==
// @name Email Scraper
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Scrape emails across multiple pages and save to CSV
// @match https://solicitors.lawsociety.org.uk/*
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-end
// @license MIT
@MarwanShehata
MarwanShehata / testTryCatch.ts
Created March 20, 2025 18:24 — forked from mthomason/testTryCatch.ts
A fixed version of an tryCatchWrapper for TypeScript.
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@MarwanShehata
MarwanShehata / try-catch.ts
Created March 20, 2025 17:43 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@MarwanShehata
MarwanShehata / validator.ts
Last active October 26, 2024 19:44
This is not a library, this is just a list of functions I decided to put in a central location so I can copy them to future projects as needed. These functions are in typescript an do both compile-time (with generics) AND runtime validation. Feel fr
// **** Types **** //
export type TFunc = (...args: any[]) => any;
export type TEmail = `${string}@${string}`;
export type TColor = `#${string}`;
// **** Variables **** //
const EMAIL_RGX = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i,