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 / 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 leymannx/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;
/**
@msankhala
msankhala / tmux-restore-lost-sessions.md
Created April 10, 2023 12:50
How to restore tmux lost sessions

How to restore tmux lost sessions

Tmux is a terminal multiplexer that allows users to create multiple sessions, panes, and windows within a single terminal window. It is an excellent tool for developers and system administrators who often work with multiple terminal sessions at once. However, sometimes users may face a situation where their tmux session gets lost due to system restart, terminal crash, or any other reason. In this blog post, we will discuss how to restore a lost tmux session.

There are various plugins available for tmux, including tmux-resurrect and tmux-continuum. These plugins allow users to save and restore their tmux sessions, making it easy to recover from a lost session. However, sometimes these plugins may not work correctly, and users may still lose their tmux session. In such cases, users can follow the steps mentioned below to restore their lost tmux session.

Step 1: Check for session files

The first step is to check if the session files created by tmux-resurrect are present

@msankhala
msankhala / DeleteFeeds.php
Created November 25, 2022 12:49
Drupal 9 batch api example using BatchBuilder
<?php
namespace Drupal\miax_content\Command;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drush\Commands\DrushCommands;
use Drupal\miax_content\Services\DeleteFeedsBatchService;
@msankhala
msankhala / useScript-react-hooo.js
Created February 2, 2022 00:48
React hook useScript
// hooks/useScript.js
import { useEffect } from 'react';
const useScript = url => {
useEffect(() => {
const script = document.createElement('script');
script.src = url;
script.async = true;
@msankhala
msankhala / prototype-design-pattern.js
Created December 19, 2021 08:16
Prototype design pattern javascript
const atv = {
make: 'Honda',
model: 'Rincon 650',
year: 2018,
mud: () => {
console.log('Mudding');
}
};
const secondATV = Object.create(atv);
@msankhala
msankhala / builder-design-pattern-js.js
Created December 19, 2021 08:15
Builder design pattern javascript
class Car {
constructor(make, model, year, isForSale = true, isInStock = false) {
this.make = make;
this.model = model;
this.year = year;
this.isForSale = isForSale;
this.isInStock = isInStock;
}
toString() {