Skip to content

Instantly share code, notes, and snippets.

View rahulsprajapati's full-sized avatar
🎧
Music + Coffee + Code

Rahul Prajapati rahulsprajapati

🎧
Music + Coffee + Code
View GitHub Profile
@rahulsprajapati
rahulsprajapati / class-tachyon-helper.php
Last active January 22, 2020 20:11
Tachyon image service helper class to extend the resized image data. https://github.com/humanmade/tachyon-plugin
<?php
/**
* Tachyon image service helper class to extend the resized image data.
*
* @package tachyon-helper
*/
namespace Tachyon_Helper;
use Tachyon;
@rahulsprajapati
rahulsprajapati / fix-init.php
Last active April 8, 2020 10:15
Fix/Workaround: losing 2FA config when configuration when updating profile with "Time Based One-Time Password (Google Authenticator)" 2FA enabled
<?php
/**
* Fix/Workaround for two-factor option issues.
*/
namespace Fix;
require_once __DIR__ . '/two-factor-totp-fix.php';
Two_Factor_Totp\bootstrap();
@rahulsprajapati
rahulsprajapati / cache-api-respose.php
Created November 25, 2021 17:14
Cache sucess API responses in WordPress.
<?php
/**
* Cache http response to store response data in cache once received success response.
* This helps avoiding duplicate http requests.
* Also helpful in cases where we may have limited API requests rate. (i.e 25 requests per day)
*/
namespace WP_Local_Helper;
// Domain list which needs uncached response each time.
@rahulsprajapati
rahulsprajapati / youtube-video-id.php
Created May 3, 2022 12:10
Get youtube video id from url.
<?php
/**
* Determine the video ID from the URL.
*
* @param string $url URL.
*
* @return int|false Video ID, or false if none could be retrieved.
*/
function get_video_id_from_url( $url ) {
@rahulsprajapati
rahulsprajapati / cookies.js
Created August 8, 2022 16:04
Cookies Set and Get for Javascript.
// Setcookie.
export const setCookie = (name, value, days) => {
let expires = '';
if (days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = `; expires=${date.toGMTString()}`;
}
document.cookie = `${name}=${value}${expires}; path=/`;
};