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

Categories
General

Happy Friday Everyone!

Categories
Git

GIT : How to discard all local changes within a branch ?

RESET BRANCH/FILE

-- force discard —
git reset --hard origin/<davidBranch_name>

example with the master branch


git reset --hard origin/master
Categories
PHPUnit

What do you verify before deploying your code ?

vendor/bin/phpcs --standard=PSR2 --colors -p src/ && vendor/bin/phpunit --stop-on-failure  

PSR-2 Code Styling

This command returns all PSR-2 (code styling errors)

vendor/bin/phpcs --standard=PSR2 ~/directory_to_scan

vendor/bin/phpcs –standard=PSR2 –colors -pv src/ApiBundle

with more information

This command fix all fixable PSR-2 (code styling errors) issues

vendor/bin/phpcbf --standard=PSR2 --report=json ~/directory_to_scan

Run the Functional and Unit Tests

vendor/bin/phpunit –stop-on-failure

Categories
Technical

What are Twitter Card ideal dimension ? 800px by 418px

  • The ideal image size for Twitter Cards is 800px by 418px, a 1.91:1 ratio. For App Cards, you can go with 800px by 800px for a 1:1 ratio.
  • Videos can also be used in Twitter Cards. The recommended size for Website Card videos is 1200px by 1200px, or 1:1 aspect ratioFor App Card and Direct Message Card, the recommended size is 640px by 360px for a 16:9 ratio, or 360px by 360px for a 1:1 ratio.
  • Twitter supports images that are JPEG or PNG format; no GIFs are allowed here.
  • For best results, make sure your image is no larger than 3 MB.
  • The approved file types are MP4 or MOV, ideally less than 30 MB in size, and no more than 1 GB when it comes to videos.
  • Twitter advises a short video for these cards, so aim to keep it less than 15 seconds.
  • For videos, place your logo in the upper left-hand corner.
  • All Website Card videos are required to have closed captioning or text overlays.

source : https://www.adobe.com/express/discover/sizes/twitter

Categories
General

PHPUnit, how to stop on failure ?

Find below the command that exit out phpunit ghracefully when a first error pop out=

phpunit --stop-on-failure
phpunit David Raleche
phpunit David Raleche
Categories
General

How to get the exponent symbol (^) ?

well just copy it below :

^

Categories
Technical

How to story point your project ? Fibonacci Sequence

0, 1, 2, 3, 5, 8, 13, 21, 34

This is the Fibonacci Sequence to use when updating your story points

1 – Easy (1-2 days)

2 – Medium (1-2 days)

3 – Hard (3-5 days)

5- Very hard (3-8 days)

8 – Difficult (8-12 days)

13 – Very difficult (8-15 days)