How to Update Magento 2.1x to latest version via SSH

composer require magento/product-community-edition 2.1.9 --no-update
composer update
rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/*
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex

Magento 2.1x Cron Jobs

Cron Jobs
Add through cPanel/WHM

Time interval – 10 minutes -> */10 * * * *

Replace ^username^ with user dir

php /home/^username^/public_html/bin/magento cron:run >/dev/null 2>&1
php /home/^username^/public_html/update/cron.php >/dev/null 2>&1
php /home/^username^/public_html/bin/magento setup:cron:run >/dev/null 2>&1

Using Crontab editor in Terminal

Use command crontab -e

*/10 * * * * php /home/^USERNAME AND PATH^/public_html/bin/magento cron:run >/dev/null 2>&1
*/15 * * * * php /home/^USERNAME AND PATH^/public_html/bin/magento indexer:reindex >/dev/null 2>&1

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.

Continue reading “How to unlike all Facebook pages from your profile and Clean your newsfeed”

Start a magento instance programmatically

This Code:

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//your mage code here

Inserting into SQL without specifying primary column

If Primary key is set to Auto-increment, there are chances that you would not want to provide its value in insert query.

 

Here is how to do it in MySQL:
INSERT INTO table_name VALUES (NULL, 'column b', 'col c');

Assumption^: The first column is the primary key set to AI

Similarly you can skip columns for other non-required data:
INSERT INTO table_name(col b,col c) VALUES ('column b', 'col c');

How to root Xiaomi Redmi 2 Prime without flashing custom recovery

In this article, I am going to explain rooting procedure of your MI REDMI 2 PRIME. Applies to redmi 2 also. Jump to Requirements -> Downloads -> Pre Root Checks -> Root Procedure

Requirements:

Downloads from shared folder contain:
  1. adb and fastboot drivers as adb.zip
  2. twrp recovery image as twrp.zip
  3. SuperSU update package as UPDATE-SuperSU-v2.46.zip

Final folder view looks like:
work folder layout

Pre – Root Checks

  1. USB Debugging is on. If not, go to developer settings and then turn “Device’s USB Debugging” Onusb debugging check
  2. Device drivers are configured correctly and your system detects the device. If not, install MI PC SUITE and restart your system.
    device driver check
  3. ADB recognizes your phone as an active device with some random name. If not, kill adb server and then check againadb connection check

 

Procedure to root Xiaomi Redmi 2 Prime

  1. Copy SuperSU update package (.zip) to your device and remember the location.update file in explorer
  2. Check ADB connection using command – adb devices . If this command shows an attached device as above, use command adb reboot bootloader to restart phone in fastboot modefastboot mode
  3. Enter command fastboot boot twrp.img. twrp.img is the name of your recovery file which is in the same folder as adb.exe and fastboot.exeadb commands for bootloader
  4. You’ll see the phone booting to recovery mode using TWRP recovery. Select install option to flash supersu packageteamwin logorecovery install
  5. Choose that zip file to be flashed in the file explorer. Tap on “Select Storage” to browse SD card or Internal Memorysupersu select
  6. Swipe the big dot below to install the packageswipe to install supersu
  7. Reboot system to finish. No need to wipe cacheinstall successful
  8. Done! Simply use any root app to check your phone is rooted.

    successfully rooted redmi prime successfully rooted redmi prime

 

Fully tested root procedure for Xiaomi Redmi 2 Prime running MIUI version 6.7.1 (Model HM2LTE-IN)

Commonly used regular expressions (regex) for developers in PHP

Commonly used regular expressions (regex) for developers in PHP

Regex are used or can be used almost everywhere strings are involved. If you are dealing with text strings, you would often find patterns in them and you might be required to filter few of them based on some similarities and properties. For example: a currency or money is often written in this form –
[Currency symbol] [Digits] ([.] [Digits])maybe

Now, in order to filter any such things programmatically using a script, few of really helpful regular expressions are mentioned below:

1. Match 4 characters

.{4} 
or ....

2. Match first 4 characters

^.{4}

3. Match last 3 characters

.{3}$ 
or
 ...$

4. Match a digit

[0-9]

5. Match an alphabet

[a-zA-Z]

6. Match a digit occurring 0 or more times

[0-9]*

7. Match a lowercase alphabet occurring 1 or more times

[a-z]+

8. Match an uppercase alphabet either NOT occurring or occurring once ( 0 or 1 time)

[A-Z]?

9. Match a character occurring exactly once
write the character itself in regex; similar to #4 and #5

10. Match a character literally (used to match meta-characters)
use \ before the character to be matched
If you want to find the occurrence of question mark(s) in a string
use \? (remember ? is used to find occurrence of at most 1 time but \? with find occurrence of ? itself exactly once)

Pro things

Match an e-Mail address
a regular expression to match an email address with 100% efficiency is really tough to be learnt here because according to RFC 0822
https://www.ietf.org/rfc/rfc0822.txt
, an email address can have letters like { } # $ @ \ / – _ . alphabets numbers and more.

So, a quick regex for matching emails can be

^[a-zA-Z0-9\._%\-^#\{\}][email protected]([a-zA-Z0-9.-]+\.)+[a-zA-Z]{2,9}$

this will match {^}#@technacy.net which is an actual email address and is totally valid.

However this won’t work all the times, a more detailed regex would be something like this: (email addresses can end with IP addresses too)

/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

So, what should be the ideal solution because you won’t like to check this^ regex all the time
Use PHP’s inbuilt filter – FILTER_VALIDATE_EMAIL
http://php.net/manual/en/filter.filters.validate.php

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {   $emailErr = "Invalid email format";  }

For security, w3schools mentioned passing and sanitizing all the data first with a function:

function test_input($data) {   $data = trim($data);   $data = stripslashes($data);   $data = htmlspecialchars($data);   return $data; }

Matching a URL
A URL can have letters, digits, any character as a parameter or in host details. A simple version of regex to match http urls is

^(http|https):\/\/((([a-z0-9.-]+\.)+[a-z]{2,4})|([0-9\.]{1,4}){4})(\/([a-zA-Z?-?0-9-_\?\:%\.\?\!\=\+\&\/\#\~\;\,\@]+)?)?$

A detailed and more efficient regex:

+// _^(?:(?:https?|ftp)://)(?:\S+(?::\S*)[email protected])?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$_iuS

Diego Perini
https://gist.github.com/dperini/729294

However PHP’s inbuilt filter can also be used as the most ideal
use FILTER_VALIDATE_URL as we used FILTER_VALIDATE_EMAIL earlier

Match a Phone number
Regex for a phone number is easy if you want to match only MOBILE NUMBERS which must be of 10 digits and can include a country code like +91, 091, (91), (+91) or 0

^(091|\+91|91|\(091\)|\(\+91\)|\(91\)|0)? ?[7-9][0-9]{9}$

https://regex101.com/r/kA6oD0/6

Match a Name
A name is supposed to have alphabets only but the length of first names and last names is not fixed or general at all. These lengths may vary thus the regex sounds funny at times.
^[a-zA-Z’ -]+$

expression, match, php, regex