30 Jun

Hadoop yarn distributed shell example on MAC

I have installed hadoop via HomeBrew.

Command:

hadoop org.apache.hadoop.yarn.applications.distributedshell.Client -jar /usr/local/Cellar/hadoop/2.7.0/libexec/share/hadoop/yarn/hadoop-yarn-applications-distributedshell-2.7.0.jar -num_containers 1 -shell_command ls

check output from:

less /usr/local/Cellar/hadoop/2.7.0/libexec/logs/userlogs/application_<jobid>/container_<jobid>_01_000002/stdout

 

 

27 Nov

PHP Gotcha – foreach with pass by reference

We can pass by reference the values in an array to modify the array. But in the following code snippet, the output will be somewhat erratic.  

$someArray = array(1,2,3);
foreach($someArray as &$value) {
   $value++;
}

$value++;
print_r($value);

The output is

array(2,3,5)

As you noticed the last value is incremented twice, because the reference is not lost after the loop ends. The increment $value++ outside the loop will update the last reference viz the last element. To avoid this one must unset your last used reference

$someArray = array(1,2,3);
foreach($someArray as &$value) {
   $value++;
}

unset($value);
$value++;
print_r($value);

Now the output will be

array(2,3,4)