Skip to content

Instantly share code, notes, and snippets.

View ruturajpatki's full-sized avatar

Ruturaj V. Patki ruturajpatki

View GitHub Profile
@ruturajpatki
ruturajpatki / RenameAndRelocate.bat
Last active August 20, 2025 09:08
Windows Batch file to rename a file by removing a specific text from the filename and then move the file to selected folder. Place the script inside the same folder where the files to be renamed are stored. The script will ask you the folder name to move files after rename (it will create the folder if does not exist), the text to be removed fro…
@echo off
setlocal enabledelayedexpansion
:: Prompt user for the folder name
set /p foldername="Enter the folder name to save files to: "
if not exist "%foldername%" mkdir "%foldername%"
:: Prompt user for the string to remove from filenames
set /p removestring="Enter the string to remove from filenames (e.g., sigma-): "
@ruturajpatki
ruturajpatki / get-ytid.php
Created June 11, 2024 05:23
Simple PHP Function to extract YouTube Video ID from several different types of YouTube links.
function extractYouTubeID($url) {
$pattern = '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)|embed/|v/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i';
preg_match($pattern, $url, $matches);
return $matches[1] ?? null;
}
/*
Here is a quick test of all supported YouTube URL types.
$urls = [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
@ruturajpatki
ruturajpatki / formatIndianCurrency.php
Created January 24, 2024 16:21
Pure PHP implementation to format any given number in Indian Currency Format.
function formatIndianCurrency($number) {
// Step 0: Check if the number is negative
$isNegativeNumber = false;
if ($number < 0) {
$isNegativeNumber = true;
$number = abs($number);
}
// Step 1: Check for decimal point
if (strpos($number, '.') !== false) {
@ruturajpatki
ruturajpatki / SendKeys-Tokens.txt
Last active September 9, 2023 07:24
List of tokens which can be used in SendKeys.SendWait sequence.
You can use a variety of special tokens with SendKeys to simulate different keys and key combinations. Here's a list of some commonly used special tokens:
{ENTER}: Enter key.
{TAB}: Tab key.
{ESC}: Escape key.
{BACKSPACE}: Backspace key.
{DELETE}: Delete key.
{INSERT}: Insert key.
{HOME}: Home key.
{END}: End key.
@ruturajpatki
ruturajpatki / jQueryDynamicEventDelegation.html
Last active September 5, 2023 05:50
To attach a jQuery event with a wildcard CSS selector, you can use the `on` method along with a custom filter function that matches elements based on a pattern. If you want the event handler to work for dynamically added elements, you should use event delegation. Event delegation allows you to attach an event handler to a parent element that alr…
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div id="button-container">
<!-- Existing buttons -->
<button id="item1">Item 1</button>
<button id="item2">Item 2</button>
@ruturajpatki
ruturajpatki / IsValidDomainName.vb
Last active August 13, 2023 07:33
VB.Net function to check if the specified domain name is in standard domain name format.
'Imports System.Text.RegularExpressions
Private Function IsValidDomainFormat(domainName As String) As Boolean
Dim pattern As String = "^(?![0-9]+$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z]{2,})+$"
Dim regex As New Regex(pattern)
Return regex.IsMatch(domainName)
End Function
@ruturajpatki
ruturajpatki / theme-widget-categories.php
Last active June 28, 2019 23:15
Custom Widget to list WordPress categories along with the Post count. Requires styling with CSS to blend it well with theme.
<?php
// Adds widget: Categories
class RutuCategories_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'rutu_categories_widget',
esc_html__( 'Rutu Categories', 'mfl' ),
array( 'description' => esc_html__( 'Custom Categories widget.', 'mfl' ), ) // Args
@ruturajpatki
ruturajpatki / woo-cat-conditional-redirect.php
Last active May 24, 2019 08:39
Redirect WooCommerce Category to Product page if it has only 1 product in it.
<?php
/* Redirect if there is only one product in the category */
add_action( 'wp_head', 'woocom_redirect_if_single_product_in_category', 10 );
function woocom_redirect_if_single_product_in_category() {
global $wp_query;
if (is_product_category()) {
$cat_obj = $wp_query->get_queried_object();
$catcount = $cat_obj->count;