Skip to main content

Posts

PHP Issue - A non-numeric value encountered

This error is encountered when we are going to do addition with different types of variables. See following example $a = ""; $b = 3; try{ $c = $a + $b; }catch(\Exception $e){ var_dump($e->getMessage()); } Exception is occurred. Error is " A non-numeric value encountered " There are two solutions  Solution 1 Change the value of variable $a into zero (0). So, both variables are getting the same type of value now.  $a = 0; $b = 3; try{        $c = $a + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Solution 2  You can simply cast $a when doing addition $a = ""; $b = 3; try{         $c =  (int) $a  + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Enjoy..

Simple Email validation regular Expression for Javascript

Following regular expression will validate emails.   var re = /^ [ A-Z0-9a-z \. _+ ] +@ [ A-Za-z0-9 \. - ] + \.([ A-Za-z ]{2,4}) $/ ; re . test ( value ); We will discuss above regular expression part by part. Examples - part1@part2.part3 1. abcd+ef@bbb.com 2. cccc_efg@bbb.lk 3. cccc.efg@bbb.net ^ ==> Start of the expression Part1 [ A-Z0-9a-z \. _+ ] +  ==> There can be many of  A-Z upper case characters, a-z lower case characters, 0-9 numbers, dots and plus signs. @ ==> There must be @ sign after first part of the email Part2 [ A-Za-z0-9 \. - ] + ==> After @ sign there can be same kind of character sets as part 1 (part 2 of email) \. ==> There must be dot character before 3rd part of the email. It should be properly escaped. That is why we use backslash (\) Part3 ([ A-Za-z ]{2,4}) ==> There are must be two to four characters({2,4})including  A-Z upper case characters or a-z lower case characters.  Curly brackets specify the range of characters. So, 2 is minimum num

Mysql Concat() function

Usage 1 SELECT CONCAT("This  ", "is  ", "test ", "concatenation") AS testConcatenation; Syntax concat(exp1, exp2, exp3, ..) - exp1 is required Usage 2 Concat table field and text together SELECT CONCAT(NAME, " is creted at  ", created_at, " ") AS Address FROM province; Enjoy...

Import csv file to MySQL in Windows

LOAD DATA INFILE "C:/Users/USER/Desktop/test.csv" INTO TABLE test COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; Change the file name accordingly.   There may be some issues. 1. SQL Error (1290): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement You need to add LOCAL modifier LOAD DATA statement. Otherwise the following error occurred. So it looks as follows. LOAD DATA LOCAL INFILE "C:/Users/USER/Desktop/test.csv" INTO TABLE test COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; 2. Even if we add LOCAL modifier, there will be another issue as follows. SQL Error (3948): Loading local data is disabled; this must be enabled on both the client and server sides.   3. So you need to enable following SET @ @GLOBAL .local

GIT :: Switch branch without discarding local changes

Sometimes you modified files in a branch and you need to switch current branch into different branch without committing them. You need to stash them first. $ git checkout develop error: Your local changes to the following files would be overwritten ... Run git stash save, or just plain git stash which is short for save $ git stash save Those are safely stored in the repository. After switch branch and you want will apply them. $ git checkout develop Switched to branch 'develop' $ git stash apply If it is successful you need to delete references to the commits.  $ git stash drop    But if you apply option does a merge stashed changes. $ git stash apply   There may be merge conflicts. All went successfully you can drop stash $ git stash drop git stash pop is short-hand for git stash apply && git stash drop

GIT Error: The following untracked working tree files would be overwritten by merge:

Recently I renamed following file names(changed only captal to simple) and added to branch(abc) and commited them. I pushed the branch as well.  app/SocialMedia/EmailShare.php --> app/SocialMedia/Emailshare.php         app/SocialMedia/EmailShareFactory.php ---> app/SocialMedia/EmailshareFactory.php After that I tried to checkout a different branch(beta). Accidently git throws following error. $ git checkout beta error: The following untracked working tree files would be overwritten by checkout:         app/SocialMedia/EmailShare.php         app/SocialMedia/EmailShareFactory.php Please move or remove them before you can switch branches. Aborting But when applying git status command no files to commit $ git status On branch abc nothing to commit, working directory clean Finally I checkout master branch. It was succefull. I think, because those files are still not in the master branch. After that I was able to checkout beta branch as well. Now that error happens again when I'm

Magento 2 : Less variable issue

If you get variable issue when running  grunt exec:themename  or when deploying theme using php bin/magento setup:static-content:deploy First delete var/*  Then run following commands php bin/magento setup:upgrade php bin/magento setup:static-content:deploy If doesn't solve your problem check your parent theme name in your theme.xml. If it is not luma then change back to luma and run following commands again. php bin/magento setup:upgrade php bin/magento setup:static-content:deploy