Tuesday, 13 February 2018

Explain Regular expression concepts



It is also expressed as regex. Regular expression is the backbone of form validation. We can validate any form elements using it. Both client side and server side elements can be validated using it. It is used in various programming or scripting language like PHP, JAVASCRIPT, PYTHON, PERL, etc.
It starts with carat(^) and end with dollor($) sign. E.g.
  1. /^[0-9]/ means starts with digit ie. 0 to 9, but end can be any thing.
  2. /[0-9]$/ means starting can be any character but it should end with digits.
  3. /^[0-9]$/ means starting with digit and end with digits.
Some characters are given special meaning within a regular expression, which we can not use directly, we have to use backslash if we have to use it literally. They are:
 .  *  ?  [  ]  (  )  {  }  ^  $  |  \ 
E.g. /^[a-z]+\?[a-z]+$/ Means starts with characters, separated by question mark(?), ends with characters. E.g. fb?chandra

Some shortcuts used in regular expression
We have to use digits, alphanumeric and space in many places during validation. So, we need some shortcuts which help to prevent our time.
ShortcutExpansionDescription
\d[0-9]Digits 0 to 9
\w[0-9A-Za-z_]A word character or alphanumeric
\s[ \t\n\r]White space character ie. Space, tab, newline or return


Shortcuts For Negative Or Inverse
ShortcutExpansionDescription
\D[^0-9]Non digits that not between 0 to 9
\W[^0-9A-Za-z_]Non word character or non alphanumeric ie. not contain digit, alphabet and underscore
\S[^ \t\n\r]Non white space character


Character class: [abc]
Characters surrounded by square bracket is known as character class. Any characters inclosed in square bracket is valid for that words. E.g. For regular expression Te[xs]t, both Text and Test is valid


OR Operator
Sometimes we have to use or operator in regex. We can use bitwise 'or' operator ie '|'. E.g. If we have to match either 'yes' or 'maybe', we can use the regex 'yes|maybe';


Qualifiers
Regex has three qualifiers symbols. They are
      + Means One or more characters. E.g. fb+chandra will matches fbchandra, fbbchandra, fbbbchandra, ....
      * Means No or any characters. E.g. fb*chandra will matches fchandra, fbchandra, fbbchandra, fbbbchandra, ....
      ? Means Yes or no characters. E.g. fb?chandra will matches either fchandra or fbchandra


Quantifiers
You have option to validate number of characters used.
[0-9]{1,4} -> Minimum 1 letter and maximum 4 letters
[0-9]{4} -> Only 4 letters
[0-9]{4,} -> Minimum 4 letters
[0-9]{,4} -> Maximum 4 letters


Examples
  1. Allow only digit. One or more digit
    Pattern: /^[0-9]+$/
  2. Allow both small and capital characters along with digits
    Pattern: /^[a-zA-Z0-9]+$/
  3. Allow both small and capital characters along with digits and some special characters like $%^&*
    Pattern: /^[a-zA-Z0-9%&\$\^\*]+$/

Visit for details
http://www.fbchandra.com/developers/regular-expression-concepts/

Sunday, 28 May 2017

Facebook Grace Hopper Scholarship for women

Facebook Grace Hopper Scholarship for women



Application open for Facebook Grace Hopper Scholarship
Facebook always tries to empower woman in technology. To empower woman, facebook is very excited to announce the 2017 Facebook Grace Hopper Women in Computing Scholarship.
Thousands of remarkable women in technology will join facebook at Orlando from October 4-6, 2017 for its tenth year at the Grace Hopper Celebration of Women in Computing. This unique scholarship program will be awarded to 50 women excelling in Computer Science. Each recipient will have the opportunity not only to attend the Celebration, but to spend valuable days before the conference with Facebook engineers learning, collaborating, and preparing for the conference.
Eligibility
  1. The scholarship is open to all women excelling in Computer Science globally (open for any woman all over the world).
  2. You have to currently be enrolled at an educational institution in order to qualify for the scholarship (high school through post-doc students are eligible).
Highlights of award
  1. Facebook will pay registration fees for Grace Hopper Celebration
  2. Paid travel and lodging, including a pre-Grace Hopper Celebration program in Orlando that includes tech talks, mentoring sessions and networking events from October 1-7, 2017.
  3. Additional meal stipend.
  4. An invitation to a private reception with Facebook's Engineering Team during the Grace Hopper Celebration.
  5. For international applicants: If you are selected, you would be responsible for your own travel visa. Facebook would cover travel expenses.
Important dates
  1. Wednesday, June 15th, 11:59pm PST - Applications for the Facebook Grace Hopper Celebration Scholarship must be submitted in full. If you made any mistake in application, you can edit it till last last of submission.
  2. Friday, July 15th - Award recipients will be notified by email of their acceptance by midnight PST.
  3. Sunday, October 1st - Saturday October 7th - Dates scholarship recipients must be available.
If you have any questions, you can contact facebook gracehopper team to gracehopper@fb.com
You can apply for this scholarship at https://www.facebook.com/careers/program/gracehopper2017/apply/
As per feedback from many women who get this scholarship last year, they got opportunity to placed in several gaint MNC. They feel lucky to meet the person about whom they heard in media. So you have lots of opportunity, if you able to get this scholarship.

See more information at http://www.fbchandra.com

Tuesday, 23 May 2017

Facebook Executives

Facebook Executives


Facebook is a social networking company where people connect to their family, friends and to whom they want. It was founded in 2004. Its headquarters is at 1 Hacker Way, Menlo Park, California 94025. It has around 18,770 employees working by March 31, 2017. Its office is located in several places in US and outside US. In India, it is located in Hyderabad, Mumbai and New Delhi.
Mark Zuckerberg

He is founder, chairman and CEO (Chief Executive Officer) of facebook. He studied computer science at Harvard University later on moved started his own company facebook. He is very dynamic in nature and is responsible for setting the overall direction and product strategy for the company. He leads facebook design and core technology.

Sheryl Sandberg

She is COO (Chief Operating Officer) of facebook. Prior to Facebook, Sheryl was vice president of Global Online Sales and Operations at Google, chief of staff for the United States Treasury Department under President Clinton, a management consultant with McKinsey & Company, and an economist with the World Bank.
Sheryl received a BA summa cum laude from Harvard University and an MBA with highest distinction from Harvard Business School.
Sheryl serves on the boards of Facebook, the Walt Disney Company, Women for Women International, ONE, and SurveyMonkey.

Mike Schroepfer

He is CTO (Chief Technology Officer) and Vice President of Engineering in facebook. He leads technology team which works very hard to connect people to their relatives and friends. Prior to Facebook, he was vice president of engineering at Mozilla Corporation, where he led the global and open product development process behind Firefox. Mike was formerly a distinguished engineer at Sun Microsystems, which acquired his company, CenterRun. He began his career working at various startups, including a digital effects software startup where he developed software that has been used in several major motion pictures. Mike holds a bachelor's degree and a master's degree in computer science from Stanford University and has filed two US patents.

Chris Cox

He is CPO (Chief Product Officer) in facebook. Chris joined Facebook in 2005 as a software engineer and helped build the first versions of key Facebook features, including News Feed. He then became director of human resources, where he set the tone for Facebook's culture and drove the development of its mission, values and people strategy.
Chris holds a bachelor's degree in symbolic systems with a concentration in artificial intelligence from Stanford University.

David Wehner

He is CFO (Chief Finance Officer), Vice President, Corporate Finance and Business Planning in facebook. He is responsible for core facebook product. Prior to becoming CFO in June 2014, Dave served as Facebook's vice president of Corporate Finance and Business Planning. From 2010 through 2012, Dave served as Chief Financial Officer of Zynga Inc. Before Zynga, Dave was a Managing Director at Allen & Company, an investment bank focused on media and technology, which he joined in 2001.
Dave holds a B.S. in Chemistry from Georgetown University, and a M.S. in Applied Physics from Stanford University.
 Find more post at http://www.fbchandra.com

Friday, 5 May 2017

Monkey man algorithm in PHP, who jumps and slip on wall

 

A monkey man caught inside a jail. He can jumps across the wall. He can jump 'X' meters, but due to slippery walls he falls 'Y' meters after each jump. To escape from jail, he has to cross 'N' number of walls, where height of each wall is given in an array.
Write a program to find total number of jumps, he has to make, to escape
Input Format
Your function will take three arguments, where:
Argument 1: An integer depicting X, which he can jump
Argument 2: An integer depicting Y, which he falls
Argument 3: An array of N integers having the height of each wall.
Constraints
1<=X<=109
1<=Y<=105
Output Format
Your program should return total number of jumps required to escape.

Sample Test Case
Test case 1
Sample Input 10 1 1 10
Sample Output 1
Explanation
Here monkey man can jump 10 meters high, but slides down by 1 meter. He has 1 wall to jump and the height of the wall is 10 meters. Since he jumps 10 meters in the first attempt he cross the wall easily in the first attempt only.
Test case 2
Sample Input 5 1 2 9 10
Sample Output 5
Explanation
Here, the monkey man can jump 5 meters high, but slides down by 1 meters. He has 2 walls to jump and the walls are 9 and 10 meters hight respectively.
While crossing the first wall, he takes 2 attempts, because during the first attempt he jumps 5 meters but slides down by 1 meters since he didn't cross the wall. In the next attempt he jumps 5 more meters from that position and this time he doesn't slide because he crossed the wall in this attempt because 4+5=9 and 9 meters is the actual height of the wall.
Similarly, while crossing the second wall, he takes 3 attempts because during his second attempt on this wall, he silides down by 1 meters since 4+5=9 and the height of the wall is 10 meters. During his third attempt, he was able to escape.


Solution
<?php
$x=5;
$y=1;
$z=array(9,10);
function jump($x,$y,$z) {
 $cnt=count($z);
 $cntjump=0;
 for($i=0;$i<$cnt;$i++) {
  $height=$z[$i];
  while($height>$x) {
   $height=$height-($x-$y);
   $cntjump++;   
  }
  $cntjump++;
 }
 return $cntjump;
}
$cnt = jump($x,$y,$z);
echo $cnt;
?>
Find more on http://www.fbchandra.com 







How to upload file using AJAX and PHP?

 

 

Simplest way to upload file is by using FormData. It is used in key/value pairs to send XMLHttpRequest. Initially FormData used to send all form elements data in key/value pair, but it can be used to send keyed data also. Data sent by FormData is in same format as used in form's submit() method. It sends upload data also, if we use multipart/form-data in form's encoding
index.html
<!Doctype HTML>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<form name="frmUpdload" id="frmUpdload" method="POST" enctype="multipart/form-data">
 <input type="file" name="txtFile" class="txtFile" />
 <input type="submit" name="btnSubmit" value="Submit" />
</form>
</body>
</html>

main.js
$(document).ready(function() {
 $("form#frmUpdload").submit(function() {
  //Image validation start
  var file_name=$('.txtFile').val();
  var index_dot=file_name.lastIndexOf(".")+1;
  var ext=file_name.substr(index_dot);
  if(file_name=='') {
   alert('Please upload image');
  }
  else if(!(ext=='png' || ext=='jpg' || ext=='jpeg')) {
   alert('Please upload jpg or png image only');
  } //Image validation end
  else {
   //formdata object to send file upload data
   var formData = new FormData();
   formData.append('fileupload',$( '.txtFile' )[0].files[0], file_name);
   
   $.ajax({
    url: 'upload.php',
     data: formData,
     processData: false,
     contentType: false,
     type: 'POST',
     success: function(data){
     alert(data);
     }
   });
  }
  $('#frmUpdload')[0].reset();
  return false;
 });
});

upload.php
<?php
//print_r($_FILES); //Check all $_FILES variables
$files=$_FILES['fileupload'];
$tmp_name=$files['tmp_name'];
$name=$files['name'];
$destination=$name;
$res=move_uploaded_file($tmp_name, $destination);
if($res) {
 $msg='Uploaded successfully';
}
else {
 $msg='Error';
}
echo $msg;
?>
Find more post on http://www.fbchandra.com 

Monday, 10 April 2017

Tidy Numbers - Display all positive integers in ascending order

Tidy Numbers - Display all positive integers in ascending order


Ananya likes to keep things tidy. Her toys are sorted from smallest to largest and pencils are sorted from shortest to longest. One day, when practicing her counting skills, she noticed that some integers, have their digits sorted in non-decreasing order. She calls 8, 123, 555, and 224488 as numbers tidy. Numbers that do not have this property, like 20, 321, 495 and 999990, are not tidy.
She just finished counting all positive integers in ascending order from 1 to N. What was the last tidy number she counted?
Input
The first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with a single integer N, the last number counted by Ananya.
Output
For each test case, output is the last tidy number counted by Ananya.
1 ≤ T ≤ 100.
Sample Input:
5
132
1000
7
621
489
Sample Output:
129
999
7
599
489


Solutions :

<?php
$path="input.txt"; //File containing Input elements
$fh=fopen($path,"r");

function tidynum($fh) {
 $res='';
 fscanf($fh,"%d",$case); //$case gives no. of test cases
 for($j=0;$j<$case;$j++) { //Loop moves for total number of cases
  $no=fgets($fh); //Read each remaining element one by one
  $arr=str_split(trim($no)); //split number in array. 
  $cnt=count($arr); //Total number of elements in array
  if($cnt>1) { //If count is greater than one
   for($i=1;$i<$cnt;$i++) { //Loop until finishes the number
    $prev=$i-1; //Previous key
    if($arr[$prev]>$arr[$i]) { //Compare current key to previous key
     $no=$no-1;  //If previous key is greater than current. Substract given number by one
     $arr=str_split($no); //Again split the remaining number, and do same until number donot set in ascending order
     $cnt=count($arr);
     $i=0;
    }
   }
  }
  $res .=$no;
  $res .=PHP_EOL; //Used as end of line
 }
 return $res;
}
$res = tidynum($fh);
echo $res;
?>
Content in input.txt
5
132
1000
7
621
489

Find more algorithm solution in PHP at http://www.fbchandra.com

Wednesday, 5 April 2017

Apps of the year award by facebook

Apps of the year award by facebook


Happy news for mobile apps developers.
Facebook has started a global program FbStart to motivate mobile app startups. Facebook jury will give 'Apps of the Year Awards' to most successful startup for native mobile apps. Startup will get $160,000 in prize.
FbStart helps startup to grow their business through various tool and money. They give prize every year to motivate mobile app startups.
FbStart consider apps under following categories on the basis of performance of apps.
Track Basis
Bootstarp: When an app launched recently and it does not have lots of traffic.
Accelerate: When an app is working very good and fast but looking to scale it.
Package
Social Good Apps: Apps used for Non-profits and NGOs who cares people.
Games: Apps used for games

Prizes
  1. Apps of the Year Awards (Five winners): $160,000 in prizes to five companies worldwide.
  2. Global App of the Year (One winner): $100,000 ($50,000 in cash and $50,000 in Facebook advertising credit). It also include mentorship from facebook team to grow business.
  3. Regional App of the Year (three winners): $15,000 per winner ($7,500 in cash and $7,500 in Facebook advertising credit).
  4. Social Good App of the Year (One winner): $15,000 ($7,500 in cash and $7,500 in Facebook advertising credit).
Eligibility
  1. Only FbStart member is eligible to participate in this competition. If you are not a FbStart member you can apply at https://developers.facebook.com/fbstart/apply
  2. All apps must have used Facebook's developer tools, otherwise it will not be considered.
  3. Only native IOS and andriod mobile apps can apply for it.
  4. Regional finalist has to submit a video of 60-90 seconds for judges to review.
Jury Member
Each and every entries will be judged by esteemed panel of mobile development experts, investors, startup founders, and Facebook.
They judge entries on the following criteria:
  1. Growth and engagement: Is the app growing quickly? Has the app entered new markets, or done a good job retaining new users? Does the app demonstrate potential for growth?
  2. Experience and design: Is the design optimized for the best user experience? Does it have a streamlined look and feel?
  3. Efficiency at scale: How does the app use Facebook or other third-party tools to make app development and iteration efficient?
  4. Leveraging Facebook Platform: Are Facebook Developer products an integral part of the app? Do they improve any of the above three areas?
Deadline
  1. Submisstion starts on March 30, 2017
  2. If you are not a FbStart member, you must apply for FbStart by April 15, 2017 in order to be considered.
  3. When you became FbStart member, you can submit an application for Apps of the year . Submission deadline is on May 1, 2017 at 12:00 PM PST.
For more details go to http://fbchandra.com