Skip to content

Instantly share code, notes, and snippets.

View dr5hn's full-sized avatar
🪄
Turning ☕ into code | Full Stack Magician 🧙‍♂️✨

Darshan Gada dr5hn

🪄
Turning ☕ into code | Full Stack Magician 🧙‍♂️✨
View GitHub Profile
@dr5hn
dr5hn / functions.php
Created September 3, 2021 10:07
Remove default Wordpress admin dashboard widgets
/**
* Remove Unwanted Dashboard Widget
*/
function remove_dashboard_meta()
{
// remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); // Activity
remove_meta_box('dashboard_primary', 'dashboard', 'normal'); // WordPress News
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); // Quick Draft
// remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); // At a Glance
remove_meta_box('dashboard_site_health', 'dashboard', 'normal'); // Site Health
@dr5hn
dr5hn / functions.php
Created September 2, 2021 06:57
How To Disable Widget Block Editor In WordPress 5.8+
// Ref: https://wpcodeus.com/disable-widget-block-editor-in-wordpress-5-8/
/**
* Disable Default Lazy Loading In WordPress
* In order to disable widget block editor in WordPress by default,
* you need to add the following code into your themes functions.php file.
*/
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
@dr5hn
dr5hn / cryptography.js
Created November 11, 2020 07:47
Encrypt and Decrypt file and text using cypto-js
const fs = require('fs');
const crypto = require('crypto');
// Generated pair of public & private keys
const cryptoPubKey = fs.readFileSync('public.pem');
const cryptoPriKey = fs.readFileSync('private.pem');
const algorithm = 'aes-256-cbc';
module.exports = {
async fileEncryption (file) {
return new Promise(function (resolve) {
@dr5hn
dr5hn / csv_remove_column.py
Last active August 21, 2024 09:48
Delete column(s) from very large CSV file using pandas [How to delete columns in a CSV file?]
# Source: https://stackoverflow.com/questions/38149288/delete-columns-from-very-large-csv-file-using-pandas-or-blaze
# pip3 install pandas
import pandas as pd
cols_to_keep = [
'email',
'phonenumber',
'name'
] # columns you want to have in the resulting CSV file
@dr5hn
dr5hn / sendgrid.sh
Last active September 19, 2023 09:19
Send email from bash or shell script by using SendGrid API
#!/bin/bash
#-----------------------------
# REFERENCES
# https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
# https://sendgrid.com/docs/for-developers/sending-email/curl-examples/
# https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/errors.html
#-----------------------------
SUBJECT="🗄️ Backup Reports";
@dr5hn
dr5hn / clear_sidekiq_redis_queue_rubyonrails.md
Last active July 24, 2018 14:31
Clear sidekiq / redis queue (Ruby On Rails) ROR ()

Clear sidekiq / redis queue

Sidekiq is mostly used for moving long-running jobs into a background process. It uses Redis to manage its job queue. During development, we often need to clear this queue of jobs to start afresh. For instance, I was generating multiple reports using background jobs. Each report was to be mailed to multiple users. Sometimes, I needed to check the output of a task that was in queue after five other jobs. To clear the queue of jobs, I ran the following commands as listed in Sidekiq wiki.

Run following commands

Sidekiq::ScheduledSet.new.clear
@dr5hn
dr5hn / functions.php
Created October 15, 2017 09:54
Always Save Card on Checkout - Stripe Plugin - Woocommerce
<?php
/**
* Auto check Save to Account -- By Darshan Gada
*/
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
@dr5hn
dr5hn / functions.php
Created October 15, 2017 09:52
How to show subtotal after applying and deducting coupon discount.
<?php
/**
* Show the cart subtotal after coupon discount -- By Darshan Gada
* @uses coupon_discount()
*/
function update_woocommerce_cart_subtotal( $cart_subtotal, $compound, $obj ){
$t = 0;
foreach ( $obj->cart_contents as $key => $product ) :
$product_price = $product['line_total'];
@dr5hn
dr5hn / functions.php
Created October 15, 2017 09:50
How to show product image on checkout page. Woocommerce
<?php
/*
* Showing Product Image on Checkout Page -- By Darshan Gada
*/
add_action('woocommerce_before_checkout_form', 'displays_cart_products_feature_image');
function displays_cart_products_feature_image() {
foreach ( WC()->cart->get_cart() as $cart_item ) {
$item = $cart_item['data'];
@dr5hn
dr5hn / functions.php
Last active October 15, 2017 09:42
WooCommerce - Change Checkout Field Label and Place Holder Text
<?php
/*
* WooCommerce - Change Checkout Field Label and Place Holder Text -- By Darshan Gada
* For more options: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
*/
// WooCommerce Checkout Fields Hook
add_filter( 'woocommerce_checkout_fields' , 'webgeeks_wc_checkout_fields' );
// This example changes the default placeholder text for the state drop downs to "Select A State"