How to stop SPAM in gmail account permanently? A guide to creating filters in Google Mail [no third party app]

SPAM, don’t we hate it when our inbox is full of credit card offers, insurance policies and billions of pounds that some rich dude left for you in his will? Everyone wants to get rid of them but somehow, some stupid website out there keeps leaking on our email address and we keep receiving stupid junk emails. We all know that SPAM or Junk Email means unsolicited messages that you receive by email. But here is a fun fact: ...

March 9, 2018 · 13 min · Harshvardhan Malpani

Linux Bash – How to change all filenames to uppercase leaving the file extension unchanged

Sometimes a batch of files needs uppercase names while the extension stays lowercase, for example when another system expects ABC123.jpg rather than abc123.jpg or ABC123.JPG. Renaming them one by one is tedious, so I use a short bash loop. Use this simple code in the bash shell. The following code will change all xxx.jpg files to XXX.jpg in the current working directory, so cd into the folder first. for i in *.jpg; do ext=${i##*.}; name=$(basename "$i" ".$ext" | tr '[a-z]' '[A-Z]').$ext; if [ "$i" != "$name" ] then mv $i $name; fi done; How it works for i in *.jpg; do loops over every file ending in .jpg in the current folder, with one file name in $i on each pass. The match is case-sensitive, so .JPG files are skipped. ext=${i##*.} is bash parameter expansion. ##*. removes the longest part of the name that ends in a dot, leaving only the extension, so photo.v2.jpg gives jpg. basename "$i" ".$ext" prints the file name with the extension removed. tr '[a-z]' '[A-Z]' turns every lowercase letter into uppercase, and .$ext puts the original extension back on the end. photo_01.jpg becomes PHOTO_01.jpg. if [ "$i" != "$name" ] skips files whose names are already uppercase. Without it, mv would complain that the source and the destination are the same file. mv $i $name does the rename. To rename other files, change *.jpg to *.png, *.pdf or any other pattern. The extension is worked out from each file name, so nothing else needs to change. To check what the loop will do before it renames anything, replace mv with echo mv; it then prints each rename instead of running it. ...

February 28, 2018 · 2 min · Harshvardhan Malpani

How to update Magento community edition using CLI

This is the sequence of commands I use to update a Composer-based Magento 2 Community Edition store to a newer release over SSH. It was written for Magento 2.2, and the example moves to 2.2.6. Replace 2.2.6 with the version you want. Before you start Back up the database and the files. setup:upgrade changes the database and there’s no undo, and the “hard fix” further down deletes vendor/ and var/ completely. Run everything from the Magento root, the folder that contains composer.json and bin/magento, as the user that owns the Magento files rather than root. Put the store in maintenance mode with php bin/magento maintenance:enable, so visitors don’t see a half-updated site. Turn it off with php bin/magento maintenance:disable at the end. Stay within one release line. These steps are for moves like 2.2.5 to 2.2.6. Jumping to a new minor version such as 2.3 usually needs more changes in composer.json, and sometimes a newer PHP version, so read the release notes first. The update composer require magento/product-community-edition 2.2.6 --no-update composer update rm -rf var/di var/generation var/cache var/view_preprocessed generated/* php bin/magento cache:clean php bin/magento cache:flush php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento indexer:reindex php bin/magento deploy:mode:set production composer require magento/product-community-edition 2.2.6 --no-update changes the required Magento version in composer.json without downloading anything yet. composer update downloads the new version and its dependencies. Note that it updates every package composer.json allows, not only Magento, so third-party extensions can move to newer versions too. rm -rf var/di var/generation var/cache var/view_preprocessed generated/* removes generated code, cache and preprocessed theme files left over from the old version. Magento 2.1 kept generated code in var/di and var/generation; 2.2 moved it to generated/. Listing both covers a store that is coming from 2.1. php bin/magento cache:clean and php bin/magento cache:flush empty Magento’s cache. cache:clean removes Magento’s own entries, cache:flush clears the whole cache storage. php bin/magento setup:upgrade updates the database schema and data to match the new module versions. php bin/magento setup:di:compile generates the dependency injection configuration and the generated classes again. php bin/magento indexer:reindex rebuilds the indexes. php bin/magento deploy:mode:set production switches the store to production mode. While doing that, Magento compiles the code and deploys the static files (CSS, JavaScript, images) itself, which is why there’s no separate setup:static-content:deploy in this list. When it finishes, check the storefront and the admin. ...

February 1, 2018 · 4 min · Harshvardhan Malpani

CORS policy for subdomains – htaccess – apache server

Browsers won’t let a page on one origin read a response from another origin (load a web font, or read the result of an AJAX call) unless the other server says it’s allowed, with an Access-Control-Allow-Origin header. On a Magento store this shows up as CORS errors in the browser console when the shop, its static files and other parts of the site live on different subdomains. The catch is that Access-Control-Allow-Origin takes exactly one origin or *. You can’t list several subdomains in it. The rules below get around that: Apache checks the Origin header of each request against a pattern and, if it matches, sends that same origin back as the allowed one. ...

December 20, 2017 · 3 min · Harshvardhan Malpani

How to manage Magento 2 product attribute values options using console

Keeping a dropdown attribute’s options up to date in the Magento 2 admin means a lot of clicking: deleting the values you no longer sell and adding new ones, one row at a time. This script does both in one go. You give it the list of values the attribute should end up with, and it makes the Manage Options table match that list. This is an update to my previous script which was used to add custom product attribute values using the backend – Add values to product attribute ...

November 22, 2017 · 4 min · Harshvardhan Malpani

Insert Indian States in Magento Database

Magento ships with lists of states or regions for some countries, but when I wrote this India wasn’t one of them. For a country without a region list, customers get a free-text “State/Province” box instead of a dropdown, so the same state ends up spelled several different ways across orders, and anything that depends on the state, such as tax rates per state, is harder to set up. The query below adds the Indian states and union territories so they show up as a dropdown at checkout, in customer addresses and in the admin. ...

November 1, 2017 · 3 min · Harshvardhan Malpani

How to create Magento 2 category programmatically?

Creating a handful of categories in the admin is fine, but when you’re setting up a new store or migrating a category tree from another system, clicking through the form for each one gets old quickly. This standalone PHP script boots Magento 2 and creates categories with a single function call each. Before you start Save the script as a PHP file (for example create-category.php) in the Magento root folder, the one that contains app/ and bin/. It includes ./app/bootstrap.php, and that path is resolved from the folder you run it in. Run it from the command line with php create-category.php, as the user that owns the Magento files. Find the ID of the parent category you want to use. Go to Catalog > Categories in the admin and select the category; its ID is shown next to its name at the top of the form. Use this code: ...

October 27, 2017 · 3 min · Harshvardhan Malpani

How to secure a folder by whitelisting one IP using HTACCESS and denying all others

If a folder such as /admin should only ever be used from one place, say your office, you can lock it to that IP address in .htaccess, so everyone else gets 403 Forbidden before the admin login page even loads. This post does it with mod_rewrite, and then adds a small PHP script that updates the allowed IP for you, which helps when your connection’s IP changes from time to time. ...

October 26, 2017 · 4 min · Harshvardhan Malpani

Magento 2.1x Cron Jobs

Magento 2 relies on cron for its background work: reindexing when indexers are set to “Update by Schedule”, applying catalog price rules, sending newsletters, generating sitemaps, updating currency rates and more. If cron isn’t set up, none of that happens, and sooner or later the admin shows a message that indexers are invalid and asks you to make sure cron is running. These are the cron entries I add for a Magento 2.1 store, either through cPanel or with crontab -e. ...

August 12, 2017 · 3 min · Harshvardhan Malpani

How to unlike all Facebook pages from your profile and Clean your newsfeed

Hello humans, I have tried to keep this tutorial simple and detailed. Please proceed with caution. The following tutorial and the procedure will unlike pages you have liked from your profile, Please be clear about that the fact that the code provided here is clean and does not intend to do any harm to your Facebook account. Note – This code uses jQuery library in its original form. So you do not need to be scared while using this “scary” looking code. ...

May 18, 2017 · 3 min · Harshvardhan Malpani