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 / 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=/`;
};
@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 / 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 / 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 / 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 / accordion-shortcode.php
Last active April 30, 2021 21:32
Custom Shortcode UI Functionality: TinyMce And Repeater
<?php
/**
* Accordion ShortCode.
*
* @param array $accordion_attrs Accordion ShortCode attribute.
*
* @return string
*/
function accordion_register_shortcode( $accordion_attrs ) {

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

I just had to set up Jenkins to use GitHub. My notes (to myself, mostly):

Detailed Instructions

For setting up Jenkins to build GitHub projects. This assumes some ability to manage Jenkins, use the command line, set up a utility LDAP account, etc. Please share or improve this Gist as needed.

Install Jenkins Plugins

Keybase proof

I hereby claim:

  • I am rahulsprajapati on github.
  • I am rahulsprajapati (https://keybase.io/rahulsprajapati) on keybase.
  • I have a public key whose fingerprint is 8D77 C942 62B5 6A77 FF2E 3020 FA83 2C34 7A42 5F12

To claim this, I am signing this object:

@rahulsprajapati
rahulsprajapati / admin.php
Created March 2, 2017 18:07
Tinymce Editor for Shortcode UI plugin.
if ( ! function_exists( 'shortcode_enqueue_editor_scripts' ) ) {
/**
* Enqueue our editor area scripts and styles.
*/
function shortcode_enqueue_editor_scripts() {
wp_register_script( 'shortcode_editor_script', get_template_directory_uri() . '/js/admin/editor-script.js', array( 'shortcode-ui' ), false, true );
wp_enqueue_script( 'shortcode_editor_script' );
}
/**
* Enqueue shortcode ui editor script after shortcode UI assets have been enqueued.