Skip to content

Instantly share code, notes, and snippets.

View RyadPasha's full-sized avatar
🎯
Focusing

Mohamed Riyad RyadPasha

🎯
Focusing
View GitHub Profile
@RyadPasha
RyadPasha / HTTPClient.py
Created March 13, 2025 09:03
A reusable HTTP client wrapper for making API requests with default settings.
"""
http_client.py
A reusable HTTP client wrapper for making API requests with default settings.
Features:
- Supports GET, POST, PUT, and DELETE requests.
- Automatically applies a base URL, timeout, and default headers.
- Handles request errors gracefully.
@RyadPasha
RyadPasha / middlewares.py
Created February 26, 2025 04:38
Middleware for Logging AWS Lambda Requests
"""
Middleware for Logging AWS Lambda Requests
This module implements a middleware for logging AWS Lambda function
requests and responses using AWS Lambda Powertools. It provides
automatic logging of request metadata, including headers, query
parameters, source IP, execution time, and response details.
Requires: Python 3.10+
// ==UserScript==
// @name Teams Copy Enabler
// @namespace http://tampermonkey.net/
// @version 2024-12-09
// @description Allow Copy and Right Click in Teams
// @author Mohamed Riyad
// @match https://teams.live.com/**
// @match https://teams.microsoft.com.mcas.ms/**
// @run-at document-start
// @icon https://statics.teams.cdn.live.net/evergreen-assets/icons/microsoft_teams_logo_refresh.ico
@RyadPasha
RyadPasha / timeElapsed.js
Created October 7, 2024 13:54
Convert time into human-readable elapsed time
function timeElapsed(t__, input, isUnixTimestamp = true, mostSignificantOnly = 1) {
let seconds;
if (isUnixTimestamp) {
const now = Math.floor(Date.now() / 1000); // Current time in seconds
seconds = now - input; // Calculate the difference in seconds
// If the time difference is negative (future time), use absolute value
if (seconds < 0) seconds = Math.abs(seconds);
} else {
@RyadPasha
RyadPasha / populateSelectWithGroups.js
Created October 1, 2024 21:35
Populates a `selectpicker` with grouped options, supporting dynamic field keys and optional limits on group and total selections.
function populateSelectWithGroups(data, valueKey = 'value', contentKey = 'content', checkedKey = 'checked', maxSelectionsPerGroup = null, maxSelections = null) {
const $selectElement = $('#prerequisite_id');
// Clear existing options
$selectElement.empty();
// Loop through the object to create and append option groups
$.each(data, function(groupLabel, options) {
// Create the optgroup element using jQuery
const $optGroup = $('<optgroup>').attr('label', groupLabel);
@RyadPasha
RyadPasha / DeviceModelManager.swift
Created January 4, 2024 19:47
A utility struct for managing device model mappings based on hardware machine identifiers.
//
// DeviceModelManager.swift
// A utility struct for managing device model mappings based on hardware machine identifiers.
//
// @author Mohamed Riyad <[email protected]>
// @link https://RyadPasha.com
// @license MIT
//
import Foundation
@RyadPasha
RyadPasha / MultiSourceTranslator.ts
Last active December 15, 2023 01:55
A class that provides translation capabilities with support for multiple sources, such as file-based translations and database translations.
/**
* MultiSourceTranslator is a class that provides translation capabilities with support for multiple sources, such as
* file-based translations and database translations. It allows you to load translations for multiple languages and
* supports string interpolation using placeholders.
*
* @class MultiSourceTranslator
* @author Mohamed Riyad <m@ryad.dev>
* @link https://RyadPasha.com
* @copyright Copyright (C) 2023 RyadPasha. All rights reserved.
* @license MIT
@RyadPasha
RyadPasha / inspect.ts
Created August 1, 2023 16:02
Printing a circular structure in a JSON-like format
import util from 'util' // In TS
// Or
import { inspect } from 'util' // Directly (TS)
// Or
const util = require('util') // In JS
// Or
const { inspect } = require('util') // Directly (JS)
// Then:
console.log(util.inspect(request)) // Or `console.log(inspect(request))` in case you directly imported it
@RyadPasha
RyadPasha / TimeUtility.ts
Last active July 26, 2023 15:07
TimeUtility is a utility class that provides a set of methods to handle time-related operations.
/**
* TimeUtility is a utility class that provides a set of methods to handle time-related operations.
*
* @class DatabaseManager
* @author Mohamed Riyad <m@ryad.me>
* @link https://RyadPasha.com
* @copyright Copyright (C) 2023 RyadPasha. All rights reserved.
* @license MIT
* @version 1.0.0-2023.07.26
* @see {@link https://momentjs.com/} for more information on Moment.js
@RyadPasha
RyadPasha / Logger.ts
Last active January 3, 2024 22:07
Logger class that wraps 'winston' and provides custom logging capabilities with different log levels.
/**
* Logger class that wraps 'winston' and provides custom
* logging capabilities with different log levels.
*
* @class Logger
* @author Mohamed Riyad <m@ryad.dev>
* @link https://RyadPasha.com
* @copyright Copyright (C) 2024 RyadPasha. All rights reserved.
* @license MIT
* @version 1.0.2-2024.01.03