Categories
General

How to onboard new developer/programmer in your team?

Well let’s start by having them

#1 – writing functional test. They should be able to write functional test that can cover the knowledge transfer explained

#2 – Writing phpdoccs to document the code. They could as well document existing swagger documentation via phpdocs with Zircote for API platform

https://github.com/zircote/swagger-php

#3 – Initiate their work through a git pull request
this will trigger a code Review policy

CI/CD contiuous integration
code review continuous integration continuous deployment

Continuous integration implementation click here

Categories
General

How to One-on-Ones – Part 2 ? (Hall Of Fame Guidance)

What is the structure to have with your one on one ?

  1. 10 minutes for direct
    • Start with the sentence -> How is it going ?
  • 10 minutes for manager
    • feedback
  • 10 minutes to talk about :
    – The future
    – Individual Performance
    – Group Performance
    – Employee’s vacation coming up
close up.business partners discussing business document.

from the https://www.manager-tools.com/manager-tools-basics

Categories
General Interview Interview questions PHP

How to PHP/ LAMP light screen interview ?

Overview

45 to 60 minutes format interview – Screen Interview

5 minutesIntroduction – Interview
25 minutesTechnical (6 questions)
5 minutesBehavorial (2 questions)
5 minutesPersonality (2 questions)
5 minutesQuestions for us
15 min buffer

Assessment Grid

TechnicalGrade
PHP
Database
Linux
Front end
readable code
Optimal code
reusable code
passionated ? up to date with latest ?
Behavorial
perseverance / determination
problem solver
collaboration team
work ethic
Personality
Openness
Conscientiousness
Extraversion
Agreeableness
Neuroticism
Universality

Behavorial Question

tell us about your latest ‘coding’ project ?
Tell me about a stressful situation at work and how you handled it.
Describe a time when you disagreed with your supervisor on how to accomplish something.
Have you ever had to convince your team to do a job they were reluctant to do?
Have you ever had a deadline you were not able to meet? What happened? What did you do?
Tell me about a time your co-workers had a conflict. How did you handle it?
How have you prioritized being assigned multiple projects?
Tell me about a difficult work challenge you’ve had.
Talk about a time when you had to adapt to big changes at work.
How have you dealt with an angry or upset customer?
Have you ever gone above and beyond to help a customer? What did you do?
Tell me about a time when you had to fight for an idea at work.
Talk about a time where you had to make an important decision quickly. What did you decide? What were the results?
Have you ever been in a business situation that was ethically questionable? What did you do?
Have you ever had a project that had to change drastically while it was in progress? Why? How did you do it?
Talk about a time when a co-worker was not doing their share on a project. How did you handle it?
Tell me about a major setback you’ve had. How did you deal with it?
What have you done when colleagues have been stressed out by a project?
Talk about a difficult problem you’ve had to solve. How did you solve it?
Have you ever had to defend a customer’s point of view? What did you do? Why?
Talk about a time when you’ve had to sell an idea to your colleagues.
Tell me about a problem you solved in a creative way.

Personality Question

If you could change one thing about your personality, what would it be and why?
What are your sports and hobbies outside of work?
Do you prefer working on your own or in a team? Why?
What are you most passionate about?
Can you tell me about a time when you went above and beyond in your job?
How would your best friend describe you?
What makes you unique?
Tell me about a time when you came up with a creative solution to a challenging task. What was the result?
How do you handle stress at work?
How do you feel when someone interrupts you during a task?
Tell me about a time when you disagreed with a manager or colleague about a decision. How did you handle it?
What is your favorite book and why?
Can you name one professional achievement and one personal achievement?
Which superhero would you want to be and why?
What is your greatest fear?

PHP Questions

What is difference between abstract class and interface ?
What is difference between PUT and PATCH ?
tell us about your latest ‘coding’ project ?
What are the steps to create a new database using MySQL and PHP?
30. How to create API in PHP?
Explain type hinting in PHP
Explain the main types of errors.
Do they follow any PHP convention standard of programming ?
Are you familiar with CodeSniffer
Are you familiar with PHPUnit
Do you use Composer? If yes, what benefits have you found in it?
What does MVC stand for and what does each component do?
do you know some design pattern ?
factory pattern ?
interface ?
Factory ?
singleton ?
How do you handle PHP upgrades ?

Javascript Questions

what is nodeJS
Have you used any JS framework ? is yes what are they ?

Database Questions

Q #7) Explain Normalization and De-Normalization.

Answer:

Normalization is the process of removing redundant data from the database by splitting the table in a well-defined manner in order to maintain data integrity. This process saves much of the storage space.

De-normalization is the process of adding up redundant data on the table in order to speed up the complex queries and thus achieve better performance.
8) What are the different types of Normalization?

Answer: Different types of Normalization are:

First Normal Form (1NF): A relation is said to be in 1NF only when all the entities of the table contain unique or atomic values.
Second Normal Form (2NF): A relation is said to be in 2NF only if it is in 1NF and all the non-key attribute of the table is fully dependent on the primary key.
Third Normal Form (3NF): A relation is said to be in 3NF only if it is in 2NF and every non-key attribute of the table is not transitively dependent on the primary key.

API Question

What restful api method would be appropriate for an upsert ?

Linux Question

Do you know how toi use vim / vi ?
What experience have you had with nginx ? apache ?
What is netstat command?
Explain working of env command.
44. What is pipe?

Deployment Question

Are you familiar with CI ?
Are you familiar with CD ?
Are you familiar with jenkins?
Are you familiar with Git Pull request
are you familiar with GIT branch
Categories
General

How to window sliding ? How to find the greatest sum of 4 elements in array ?

<?php 
function maxSum( $arr, $n, $k)
{
    // n must be greater
    if ($n < $k)
    {
        echo "Invalid";
        return -1;
    }
 
    // Compute sum of first
    // window of size k
    $max_sum = 0;
    for($i = 0; $i < $k; $i++)
    $max_sum += $arr[$i];
 
    // Compute sums of remaining windows by
    // removing first element of previous
    // window and adding last element of
    // current window.
    $window_sum = $max_sum;
    for ($i = $k; $i < $n; $i++)
    {
        echo "(window_sum) $window_sum \n\r";
        $window_sum += $arr[$i] - $arr[$i - $k];
        echo "(arr[$i])". $arr[$i]." - (arr[$i - $k])".$arr[$i - $k]."\n\r";
        echo "$i (window_sum) $window_sum \n\r";
        
        $max_sum = max($max_sum, $window_sum);
    }
 
    return $max_sum;
}
 
    // Driver code
    $arr = array(1, 4, 2, 10, 2, 3, 1, 0, 20);
    $k = 4;
    $n = count($arr);
    echo maxSum($arr, $n, $k);
 
// This code is contributed by anuj_67
Categories
General

How to resolve 3 sums alternative to O(n^3) in PHP

Complexity Analysis: 

  • Time Complexity : O(n2). 
    Only two nested loops are required, so the time complexity is O(n2).
  • Auxiliary Space : O(1), no extra space is required, so the time complexity is constant.
<?php
// PHP program to find
// triplets in a given
// array whose sum is zero
 
// function to print
// triplets with 0 sum
function findTriplets($arr, $n)
{
    $found = false;
 
    // sort array elements
    sort($arr);
 
    for ($i = 0; $i < $n - 1; $i++)
    {
        // initialize left
        // and right
        $l = $i + 1;
        $r = $n - 1;
        $x = $arr[$i];
        while ($l < $r)
        {
            if ($x + $arr[$l] +
                     $arr[$r] == 0)
            {
                // print elements if
                // it's sum is zero
                echo $x," ", $arr[$l],
                        " ", $arr[$r], "\n";
                $l++;
                $r--;
                $found = true;
            }
 
            // If sum of three elements
            // is less than zero then
            // increment in left
            else if ($x + $arr[$l] +
                          $arr[$r] < 0)
                $l++;
 
            // if sum is greater than
            // zero than decrement
            // in right side
            else
                $r--;
        }
    }
 
    if ($found == false)
        echo " No Triplet Found" ,"\n";
}
 
// Driver Code
$arr = array (0, -1, 2, -3, 1);
$n = sizeof($arr);
findTriplets($arr, $n);
 
// This code is contributed by ajit
?>

Complexity Analysis: 

  • Time Complexity: O(n2). 
    Since two nested loops are required, so the time complexity is O(n2).
  • Auxiliary Space: O(n). 
    Since a hashmap is required, so the space complexity is linear.

<?php
 
// function to print triplets with 0 sum
function findTriplets($arr, $n)
{
    $found = false;
 
    for ( $i=0; $i<$n-1; $i++)
    {
        // Find all pairs with sum equals to
        // "-arr[i]"
       $s = array();
        for ( $j=$i+1; $j<$n; $j++)
        {
            $x = -($arr[$i] + $arr[$j]);
            if (in_array($x, $s))
            {
                echo "FOUND => $x, $arr[$i], $arr[$j] \n\r";
                $found = true;
            }
            else
                $s[] = $arr[$j];
        }
    }
 
    if ($found == false)
        echo " No Triplet Found" ;
}
 
// Driver code
function main()
{
    $arr = array(0, -1, 2, -3, 1);

    $n = count($arr);
    findTriplets($arr, $n);
    return 0;
}

main();
Categories
Interview Interview questions

How to fibonacci with PHP ? Recursively

This function runs in O(2 exponent N)

function fibonacci(int $n) {
    if ($n == 0) {
        return 0; 
        
    }
    if ($n == 1) {
        return 1;
    }
    
    
    return fibonacci($n-1) + fibonacci($n-2);
}

echo 'FINAL ' . fibonacci(9);
Categories
Interview Interview questions

How to Fibonacci Bottom-Up Memoization PHP ? Dynamic Programming

This function runs in O(n) time

<?php
function fibonacci(int $n) {
    if ($n == 0) {
        return 0; 
        
    }    else if ($n == 1) {
        return 1;
    }
    
    $memo = array_fill(0, $n, 0);
    $memo[0] = 0;
    $memo[1] = 1;
    
    for ($i = 2; $i < $n; $i++) {
        
        $memo[$i] = $memo[$i - 1] + $memo[$i - 2] ;   
        echo    "memo[$i] ($memo[$i]) = memo[$i - 1] + memo[$i - 2] \n\r";   
        
    }
    return $memo[$n - 1] + $memo[$n - 2];
}

OR

function fibonacci(int $n) {
    if ($n == 0) {
        return 0; 
        
    }    else if ($n == 1) {
        return 1;
    }
    
    $memo = array_fill(0, $n, 0);
    $a = 0;
    $b = 1;
    
    for ($i = 2; $i < $n; $i++) {
        
       $c = $a + $b ;   
        $a = $b;
        $b = $c;
        echo    "c ($c) = a ($a) + b ($b)  \n\r";   
        
    }
    return $a + $b;
Categories
Interview Interview questions

How to Fibonacci Top-Down Memoization PHP ?

Top-Down Memoization PHP Fibonacci Problem

function fibonacci1(int $n) {
    
    $result = array_fill(0, $n + 1, 0);
<?php
function fibonacci1(int $n) {
    
    $result = array_fill(0, $n + 1, 0);
    return fibonacci($n,$result );
}

function fibonacci(int $i, $memo) { 
    
    if ($i == 0 || $i == 1) return $i;
    
    if ($memo[$i] == 0) {
        $memo[$i] = fibonacci($i - 1, $memo) + fibonacci($i - 2, $memo);
    }
    
    echo " memo[$i] ".$memo[$i]."\n\r";
    
    return $memo[$i];
}

echo 'FINAL ' . fibonacci1(9);

Categories
General

How to get Git deploy key

Step 1

Step 2

(from MAC)

$ pbcopy < ~/.ssh/id_rsa.pub

Step 3

Categories
General

How to fix Laravel Trailing Data Exception ?

Setting timestamps to false means you are going to lose both created_at and updated_at whereas you could set both of the keys in your model.

Case 1:

You have created_at column but not update_at you could simply set updated_at to false in your model

class ABC extends Model {

const UPDATED_AT = null;

Case 2:

You have both created_at and updated_at columns but with different column names

You could simply do:

class ABC extends Model {

const CREATED_AT = 'name_of_created_at_column';
const UPDATED_AT = 'name_of_updated_at_column';

Finally ignoring timestamps completely:

class ABC extends Model {

public $timestamps = false;

Trailing data is a Carbon error, it’s because you probably use Postgres and your date returns milliseconds.

“created_at” => “2018-04-19 07:01:19.929554”

You can add the following method to your (base) model.

public function getDateFormat()
{
     return 'Y-m-d H:i:s.u';
}

source : https://stackoverflow.com/questions/50210435/laravel-trailing-data-exception-when-model-save-or-update