A basic time difference calculator in google script js

In your Google Sheet, Click “Tools” and then choose “Script Editor“. Put the code given below. Don’t forget to use function in your result column as “=dodiff(cell1,cell2)“ function dodiff(a, b) { if (a) a = fix(a); if (b) b = fix(b); if (Array.isArray(a) && Array.isArray(b)) { if (b[1] > a[1]) m = b[1] - a[1]; else { m = b[1] - a[1] + 60; b[0]--; } if (b[0] >= a[0]) h = b[0] - a[0]; else { h = b[0] - a[0] + 12; } m = m / 60; return (h + m).toPrecision(4); } } function fix(a) { if (a) x = a.toString().replace(" ", '').replace("am", "").replace("pm", "").replace("PM", "").replace("AM", ""); x = x.split(":"); x[0] = parseInt(x[0]); x[1] = parseInt(x[1]); return x; }

October 15, 2019 · 1 min · Harshvardhan Malpani

How to add Facebook Messenger for live chat on your website?

How to add facebook messenger in website so that users can chat live to your page? Requirements: Page ID – you need to know what is your page id Whitelisted Domain – you need to add website on which you want show widget in your page’s whitelist Access to add/edit code in your website 1 – Getting Page ID Go to your page, click on about, scroll down a bit and you will see Page ID ...

October 7, 2019 · 2 min · Harshvardhan Malpani

Convert dropdown attribute to text swatch in Magento2 Admin Panel

Run the following code in console: $=new jQuery.noConflict(); $("#swatch-text-options-panel tr td:nth-child(4) input").each(function (e,el) { $(this).parent().parent().find("td:nth-child(3) input").val($(this).val());});

September 24, 2019 · 1 min · Harshvardhan Malpani

How to disable products in Magento2 which dont have any gallery image?

UPDATE `catalog_product_entity_int` SET `value`=2 where `entity_id` in (SELECT a.`entity_id` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_media_gallery_value` AS b ON a.entity_id = b.entity_id LEFT JOIN `catalog_product_entity_media_gallery` AS c ON b.value_id = c.value_id WHERE c.value IS NULL) and `attribute_id` = 96 It is SQL query Assumption: value=2 means disable and value=1 means enable attribute_id=96 means “status” attribute References: https://gist.github.com/tegansnyder/8464261#gistcomment-2910808 https://magento.stackexchange.com/a/83033/32283

August 22, 2019 · 1 min · Harshvardhan Malpani

How to batch edit multiple images to make square sized pictures with original image in center using php imagejpeg?

<?php // WORKS FOR JPEG IMAGES ONLY. FOR PNG, change function names // also create a folder named "out" in the $datadir folder ///only 4 lines to be edited //1. dir in which your image files are present $datadir="J:/dgcert/"; //2. Expected min. Width of the output file $_outw=840; //3. Expected min. Height of the output file $_outh=840; //4. output folder (inside datadir) $outfolder= '/out/'; //5. force final size -- -- If set to 1/true then line 2 and 3 will become max sizes of output image // TO BE DONE IN FUTURE . does not work as of now $forcesize=0; ////// no more edits needed $files=array_diff(scandir($datadir),array(".","..")); foreach ($files as $file) { if(is_file($datadir.'/'.$file)){ $outw=$_outw; $outh=$_outh; $mugl_im= imagecreatefromjpeg($datadir.$file); list($thiswidth, $thisheight)= getimagesize($datadir.$file); if($outw<$thiswidth) $outw=$thiswidth; if($outh<$thisheight) $outh=$thisheight; if($outw<$outh)$outw=$outh; if($outh<$outw)$outh=$outw; //echo $width . $height;exit; $thumb = imagecreatetruecolor($outw, $outh); //white color rgb $bg = imagecolorallocate ( $thumb, 255, 255, 255 ); imagefilledrectangle($thumb,0,0,$outw,$outh,$bg); imagecopyresized($thumb,$mugl_im,ceil(($outw-$thiswidth)/2),ceil(($outh-$thisheight)/2),0,0,$thiswidth,$thisheight,$thiswidth,$thisheight); imagejpeg($thumb,$datadir.$outfolder.$file); imagedestroy($thumb); imagedestroy($mugl_im); } } ?>

August 18, 2019 · 1 min · Harshvardhan Malpani

How to track qty changes in cart?

This is not CMS or software specific. Can be used for shopify, magento, wordpress or any other cart page Assumption: All the cart items have an input field for quantity in case they want to change qty for any item Assumption: All those input fields can be selected using queryselector. Either they have common name attribute or a common class. Purpose: We want to change class of update button to show that he has to press update button because quantities have been altered. ...

July 21, 2019 · 1 min · Harshvardhan Malpani

How to add qty plus minus buttons in shopify?

Sorry this is not a detailed description but a summary with all code Add available quantities first – as shown in this article – How to show stock quantities in all variants of shopify ^The above part is utmost necessary. because the following functions use previous js variables. So here we go. Good Luck!! javascript on the product page <script> $(document).ready(function($){ var $j=new jQuery.noConflict(); var qtyinput=$j("#quantity"); var qtyplus=$j("#qtyplus"); var maxallowed=parseInt($j(qtyinput).attr('max')); var qtyminus=$j("#qtyminus"); var qtyvalue=parseInt($j(qtyinput).val()); setTimeout(function(){$j(qtyminus).removeClass("hidden"); $j(qtyplus).removeClass("hidden"); },8000); $j(qtyminus).click(function($){ qtyvalue=parseInt($j(qtyinput).val()); maxallowed=parseInt($j(qtyinput).attr('max')); if(qtyvalue<2){checkFreeze(); return;} $j(qtyinput).val(qtyvalue-1); checkFreeze(); }); $j(qtyplus).click(function($){ qtyvalue=parseInt($j(qtyinput).val()); maxallowed=parseInt($j(qtyinput).attr('max')); // console.log(qtyvalue + " -- - -" + maxallowed); if(maxallowed<=qtyvalue){ checkFreeze(); return;} $j(qtyinput).val(qtyvalue+1); checkFreeze(); }); }); </script> html tags on product page. make sure you add these AROUND quantity input ...

July 21, 2019 · 2 min · Harshvardhan Malpani

How to reverse the ids in a mysql table column without breaking primary key constraint?

Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data. What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like shifting the first row to end and moving last row to starting. Initial Data id name email anything 1 jacob whatever how to reverse 3 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 8 monica iamsexy primary key constraint 9 batman idontexistinrealworld i am batman Data after update id name email anything 9 jacob whatever how to reverse 8 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 3 monica iamsexy primary key constraint 1 batman idontexistinrealworld i am batman Dude, you are just reversing the column, what is so tough in this? So, this seems simple to reverse an array if isolated by key “id“. But you have to understand that this column is the primary key. So if you run a command to change id for “jacob” to “9“. It will give you error: “Duplicate entry for id 9“ ...

June 1, 2019 · 2 min · Harshvardhan Malpani

Magento 2 Multi Select click all code – Tax Rates

Put the following code in console. require(["jquery"],function($){ $( ".mselect-fixed label" ).each(function( index ) { if($(this).children("input").hasClass("mselect-checked")){} else $(this).trigger('click'); }); });

April 26, 2019 · 1 min · Harshvardhan Malpani

How to use .htaccess to run all .html files as .php by using PHP handlers in Apache w/o CGI?

If you are not able to find the correct Handler, Simply create a .php file with the following contents: <?php echo $_SERVER['REDIRECT_HANDLER']; ?> and run/open this file in browser. example application handler Use this output in .htaccess file Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line: AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm Example ...

January 23, 2019 · 1 min · Harshvardhan Malpani