Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@PatelUtkarsh
PatelUtkarsh / jetpack-config.php
Last active April 2, 2024 12:14
Disable jetpack sync
<?php
/**
* Plugin Name: Disable jetpack sync.
*/
add_filter( 'jetpack_sync_modules', '__return_empty_array', PHP_INT_MAX );
@PatelUtkarsh
PatelUtkarsh / redirect-canonical.php
Last active February 13, 2024 08:31
WordPress network site with different home url and site adress with reverse proxy redirects trailing slash to site address instead of home url.
<?php
/**
* Plugin name: Redirect canonical to home URL for trailing slash.
* Description: Fix for WordPress network site with different homeurl and site address with reverse proxy, which redirects non-trailing slash to site address instead of home url.
* Version: 1.0
* Author: Utkarsh
* Author URI: https://utkarshpatel.com
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
@PatelUtkarsh
PatelUtkarsh / auto-merge.yml
Last active January 20, 2024 05:14
Auto merge PR on adding label and trigger deployment if the branch supports it. Must have PAT(Personal access token) added to GH action.
name: Auto Merge and Push on Label
on:
pull_request_target:
types: [labeled]
jobs:
auto-merge-and-push:
runs-on: ubuntu-latest
if: github.event.label.name == 'In dev'
@PatelUtkarsh
PatelUtkarsh / phpcs.md
Created April 29, 2016 12:54
PHPCS for Linux

Installation

Install PEAR

sudo apt-get install php-pear

Install PHP_CodeSniffer

@PatelUtkarsh
PatelUtkarsh / greythr.sh
Last active August 16, 2023 08:21
Attendence Login or logout to greythr
#!/bin/bash
#set login & password or this will ask everytime
#login=
#password=
#comment this if you set login password on top!
read -p "User name or email: " login
echo -n Password:
@PatelUtkarsh
PatelUtkarsh / perf.php
Last active February 25, 2023 12:48
Compare performance of class_implements vs implementsInterface (using ReflectionClass) for 1,00,000 class.
<?php
// Define an interface
interface MyInterface {
public function myFunction();
}
// Define 1000 classes that implement the interface
for ($i = 1; $i <= 100000; $i++) {
$className = 'MyClass' . $i;
eval("
@PatelUtkarsh
PatelUtkarsh / root-based-category-urls.php
Last active February 8, 2023 01:39 — forked from mikeschinkel/root-based-category-urls.php
Enabled Root-based Category URLs in WordPress (Any bugs? Post comments below.)
<?php
/*
* Plugin Name: Root-based Category URLs
* Description: Enables root-based Category URLs, i.e. Makes /category/my-category/ URLs route as /my-category/
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel
* Plugin URI: https://gist.github.com/1421235
* Version: 0.1.1
*/
@PatelUtkarsh
PatelUtkarsh / script.sh
Created January 11, 2023 10:34
Migrate domain to new domain? A script to verify domains are redirecting 1:1 in new site based on old sitemap.
function verify_sitemap_urls() {
if [ -z "$1" ]; then
echo "Usage: check_sitemap [file_path/url] (new_domain)"
echo "If no new domain passed it will use the url from sitemap; if domain is passed then it will replace the domain in sitemap url with same path."
return
fi
if [[ "$1" == *"http"* ]]; then
TEMPFILE=$(mktemp)
# Download the sitemap file from the given URL
@PatelUtkarsh
PatelUtkarsh / disable-plugin-update-mu.php
Created August 15, 2022 04:06
Disable plugin updates WordPress
<?php
// Return zero updates and current time as last checked time
function __disable_wp_updates() {
include ABSPATH . WPINC . '/version.php';
return (object) array(
'updates' => array(),
'version_checked' => $wp_version,
'last_checked' => time(),
);
@PatelUtkarsh
PatelUtkarsh / proxy.js
Created June 22, 2022 04:40
Cloudflare worker proxy object storage image
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const hiddenImageOrigin = "s3 url without trailing shash"
const requestURL = new URL(request.url)
// Append the request path such as "/assets/image1.jpg" to the hiddenImageOrigin.
// You could also process the path to add or remove directories, modify filenames, etc.
const imageURL = hiddenImageOrigin + requestURL.pathname;