Skip to content

Instantly share code, notes, and snippets.

View msankhala's full-sized avatar
🎯
Focusing

Mahesh Sankhala msankhala

🎯
Focusing
View GitHub Profile
@msankhala
msankhala / drupal-css-aggregated-css-files.php
Created May 27, 2026 09:22
drupal-css-aggregated-css-files.php
// Drupal creates aggregated CSS file based on URL. The URL of aggreated css files looks like this.
// /sites/default/files/css/css_r2mI5EYphoR4On2HmnhByWxu6QR1_AhZ5GtagUZw2aE.css?delta=1&language=en&theme=particle&include=eJxtUttyxCAI_SG7vuz_MMQQl6yKFdJp-vUlO53upX1RDiAHDqIqGXBbKZmMuGrUxaHRwGQsDdS2mQXog0bGTAH_PrjgILuwgqbB3UJKC3QaKg0Lf-FRJvYhVWDh4pXDIqMedepU9vgIYNWQRXIhMMwHaTON5r1cueXQpZQ4j61jOR32W-F21aC7GtU4oVLoOIxToZhkUFjfNxo7bAwmUox7_LlvPSaRKxN0d8UX7JWngWO_5WWEbDXezZfo-SF8forfZ4nufoaYX_EJV_wM6Uozu7SAyWeYD_F-rdMyxHfT5rCqt1u7NFfoRo0M6YI2iZ3uZvAo2w4uLs0xYT92cdeoOhPChK35UgYl7uQrajM5-VzZiY_zpt2EA9KmJtV_xF5I_82v1Db4YOWJi_N-AwqU7mo
// Where include parameter decides what all the files to include in aggregated css. You can decode this with below script.
$include_param = 'eJxtUt16wyAIfSFXb_o-fESJIzWSAXbL28_069at241yOPzIQTQjB24LJReNi0WbB3RSTM7SwLxnFqAracFCAf8mvKKSv7KBJeXNwyy6HmHrVPf4E8BioYiUSuBYjprNLfpodeFWwia1xqx9w3o67JfK7WLBdnNa44RGYUN1TpViEqWwvHXSHTqDi1TnLd7vkNIMSeTCBNtwxSc8Kk-Kut_iCkLxNT7MJ_b8gz7_4h-zxOH-DbE84x
@msankhala
msankhala / listAllEventListeners.js
Created September 11, 2025 08:23 — forked from dmnsgn/listAllEventListeners.js
List all event listeners in a document
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];
@msankhala
msankhala / php-nodejs-python-serverless-offline-with-pythonlaunch.json
Last active March 29, 2025 10:10
Vscode debugger config for php, nodejs, python and serverless-offline-with-python
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
@msankhala
msankhala / export_recipe.py
Created March 26, 2025 12:01
CORS issue Content-Disposition header issue serverless
def export_recipes_to_csv(event):
"""
Exports recipes to a CSV file.
:param recipe_list: List of recipe dictionaries.
:param filename: Output CSV file name.
"""
body = json.loads(event.get("body", "{}"))
# Get the list of recipe IDs from the request body.
recipe_ids = body.get("recipe_ids", []) # List of recipe IDs.
@msankhala
msankhala / script1-loop.sh
Created February 24, 2025 05:44
Validate Use Flock to run only one instance of process with Cron
#!/bin/bash
for i in {2..100}; do
# Your code to be executed in each iteration goes here
echo "Script 1 Iteration: $i"
sleep 1
done
@msankhala
msankhala / find-directory-count-with-pattern.sh
Created September 17, 2024 11:23
Get the count of directory in a given folder based on the pattern.
#!/usr/bin/env bash
function getColorfulString() {
RED='\033[0;31m'
NC='\033[0m' # No Color
# 30-37 sets foreground color
# 40-47 sets background color
echo "$RED$1$NC"
}
@msankhala
msankhala / kaprekar_constant.py
Created September 5, 2024 04:45
The program that will show the kaprekar constant, Given a 4 digit number it will show how many steps it take to reach to kaprekar constant.
def kaprekar_constant(num):
steps = 0
while num != 6174:
# Convert number to a 4-digit string, padding with zeros if necessary
num_str = f"{num:04d}"
# Sort digits in ascending and descending order
asc = int(''.join(sorted(num_str)))
desc = int(''.join(sorted(num_str, reverse=True)))
@msankhala
msankhala / php-abstract-class-late-static-binding.php
Created August 30, 2024 09:07
A simple gist to show PHP Abstract class and Late Static Binding and Magic method.
<?php
// Problem
/**
* Review the code:
* 1) Find errors
* 2) What would be improved from the design point of view?
* How to get rid of implementing not used methods in the child classes?
* 3) Implement a counter for the created instances of any class from the hierarchy.
* 4) Implement getCategory method so it returns the value of the constant
* defined in the child class.
@msankhala
msankhala / Drupal8HorizontalTabs.php
Created December 14, 2023 12:50 — forked from normanlolx/Drupal8HorizontalTabs.php
How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
<?php
// How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
$form = array();
$form['my_field'] = array(
'#type' => 'horizontal_tabs',
'#tree' => TRUE,
'#prefix' => '<div id="unique-wrapper">',
'#suffix' => '</div>',
);
$items = array(
@msankhala
msankhala / NearestEventFilter.php
Last active May 24, 2023 17:08
Drupal 9 Views custom filter plugin to filter content based on users zipcode
<?php
namespace Drupal\mymodule\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Geocoder\Formatter\StringFormatter;
use Drupal\user\Entity\User;
/**