Posts

Showing posts from February, 2021

PHP preg_match Regular Expression Cheatsheet

  [abc] A single character: a, b or c [^abc] Any single character but a, b, or c [a-z] Any single character in the range a-z [a-zA-Z] Any single character in the range a-z or A-Z ^ Start of line $ End of line \A Start of string \z End of string . Any single character \s Any whitespace character \S Any non-whitespace character \d Any digit \D Any non-digit \w Any word character (letter, number, underscore) \W Any non-word character \b Any word boundary character (...) Capture everything enclosed (a|b) a or b a? Zero or one of a a* Zero or more of a a+ One or more of a a{3} Exactly 3 of a a{3,} 3 or more of a a{3,6} Between 3 and 6 of a options: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{...} substitutions only once

What’s New in PHP 8 ?

Union types public function foo(Foo|Bar $input): int|float; The nullsafe operator $dateAsString = $startDate ? $startDate->asDateTimeString() : null;   $dateAsString = $booking->getStartDate()?->asDateTimeString(); New mixed type function bar(): ?mixed {} Throw expression $triggerError = fn () => throw new MyError(); $foo = $bar[‘offset’] ?? throw new OffsetDoesNotExist(‘offset’); READ -> https://stitcher.io/blog/new-in-php-8

Amazon Principles

  — This is great for other companies to be inspired — Leadership Principles We use our Leadership Principles every day, whether we’re discussing ideas for new projects or deciding on the best approach to solving a problem. It is just one of the things that makes Amazon peculiar. Customer Obsession Leaders start with the customer and work backwards. They work vigorously to earn and keep customer trust. Although leaders pay attention to competitors, they obsess over customers. Ownership Leaders are owners. They think long term and don’t sacrifice long-term value for short-term results. They act on behalf of the entire company, beyond just their own team. They never say “that’s not my job.” Invent and Simplify Leaders expect and require innovation and invention from their teams and always find ways to simplify. They are externally aware, look for new ideas from everywhere, and are not limited by “not invented here.” As we do new things, we accept that we may be misunderstood for long per

Code Review by David Raleche

Image
4 Principles are guiding this methodology - Readability - Quality Assurance - Logic - Reusable code 1 — Readability PSR-2 code styling Function no longer than 50 lines PHP doc Block TypeHint your functions Details: For better code readability we suggest PSR-2 code styling to be applied We consider a function bigger than 25 lines is not an efficient function. For engaging this methodology we recommend 50 lines maximum per function. DocBloc are essentials. Swagger in a case of API writing is essential to be present. A developer should be able to explain his work easily and quickly and should use materials to do so 2 — Quality Insurance No PHP error message No PHP Warning messages No PHP Notices No hardcore credentials Unit Testing Details: When executing the code we expect the quality assurance team to verify that no PHP errors, warnings, notices are produced. We also expect the QA team to go throughout the code to verify that no hardcore credentials are present within the code. Unit Te

Laravel BackPack – Tutorial

  Linux  commands history 745 composer require backpack/crud:"4.0.*" 746 composer require backpack/generators --dev 747 composer require laracasts/generators --dev 748 php artisan backpack:install 749 php artisan make:migration:schema create_tags_table --model=0 --schema="name:string:unique" 750 php artisan migrate 751 php artisan backpack:crud tag 752 valet park 753 valet link 754 valet links 755 hisory 756 history 757 vim .env 758 php artisan backpack:crud building 759 php artisan backpack:crud apartment 760 php artisan backpack:crud apartment Additional Feature 830 composer require backpack/permissionmanager 831 php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations" 832 php artisan migrate 833 php artisan migrate 834 php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag=

How to Laravel Nova? Postgres

  Create Resource php artisan nova:resource DirectMailing Create Model php artisan make:model DirectMailing -m Postgres How to deal multiple schema ? Connection variable is critical protected $connection = 'pgsql-api'; How to deal with Schema and uuids ? file location : app/LoyaltyLevels.php class LoyaltyLevels extends Model { // protected $connection = 'pgsql-api'; protected $table = 'api.loyalty_levels'; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = 'loyalty_level_uuid'; protected $keyType = 'string'; } File location app/Nova/LoyaltyLevels.php public function fields(Request $request) { return [ Text::make('loyalty_level')->sortable(), Text::make('loyalty_level_description')->sortable(), ]; }

Install Laravel Nova

  1 - composer create-project --prefer-dist laravel/laravel admin "5.8.*" 2 - add/update in composer.json the following item "repositories": [ { "type": "composer", "url": "https://nova.laravel.com" } ], Next, you may add laravel/nova to your list of required packages in your composer.json file: "require": { "php": "^7.1.3", "fideloper/proxy": "^4.0", "laravel/framework": "5.8.*", "laravel/nova": "~2.0" }, 3 - php artisan nova:install 4 - php artisan migrate

How to resolve The Mix manifest does not exist. ? LARAVEL NOVA Facade\Ignition\Exceptions\ViewException

  ERROR Facade\Ignition\Exceptions\ViewException The Mix manifest does not exist. Solution php artisan vendor:publish --all

How to force Laravel to return SSL connection calls ?

Image
  It has been a pretty long day as I was struggling to get a Laravel application to return SSL or HTTPS connections. I was put in this situation because the SysOp team of my company placed the laravel app behind a loadbalancer accepting SSL connections but converting these connection to HTTP. It seems trivial but it did mess with the laravel application that relies on the incoming protocol to define login/logout url pages for instances After messing up and discovering  TrustProxies  I found an easy solution with Here is my solution , open the file  app/Providers/AppServiceProvider.php And add the following line  URL::forceScheme('https'); <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\URL; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application

How to Force/change default homepage of Laravel Nova ?

Image
  To Force the redirect of Laravel Nova I proceeded with modifications #1 – Remove the default route definition routes/web.php #2 – Address the ‘/nova’ path to just ‘/’ config/nova.php

Customize your error pages with Laravel

Easy commands to generate template error pages that Laravel is using, see below php artisan vendor:publish –tag=laravel-errors

Laravel Generate Authentication Page

  It is very easy to generate authentication page with laravel. All you have to do is to execute the following commands composer require laravel/ui php artisan ui vue --auth And you will find all the view blade files within this directory resources/views/auth

Laravel redirect with message

Image
  Redirecting With Flashed Session Data Redirecting to a new URL and  flashing data to the session  are usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create a  RedirectResponse  instance and flash data to the session in a single, fluent method chain: Route::post('user/profile', function () { // Update the user's profile... return redirect('dashboard')->with('status', 'Profile updated!'); }); After the user is redirected, you may display the flashed message from the  session . For example, using  Blade syntax : @if (session('status')) <div class="alert alert-success"> {{ session('status') }} </div>

How to send email via Laravel ?

  Create Mailgun account https://app.mailgun.com/app/dashboard Update .env MAIL_DRIVER=smtp MAIL_HOST=smtp.mailgun.org MAIL_PORT=587 MAIL_USERNAME=XXXXXXXXXXXXXXXXXXXXX MAIL_PASSWORD=XXXXXXXXXXXXXXXXXXXXX Clear Cache php artisan config:cache

Past experience High5games, New York World Trade center - Technical Lead Full Stack

Image
  High5games, New York - Technical Lead Full Stack May 2013 - July 2017 I Lead peers with php and implement Laravel framework the VIP program, while supporting legacy web applications, weigh-in on database schema design, Develop web applications using PHP & JS, Follow and enforce coding standards and best practices. I flew to Facebook headquarter to innovate social products. Laravel Experience Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern.Find information about the framework on  Laravel , as well as  Laracast . Facebook API Faceboop Api, Faceboop Payment, Facebook Authentication View of the office

How to quickly parse XML in PHP ?

Introduction Parsing XML with PHP It is often quite essential to be able to parse a XML. Fin below the snippet code in php that allows you to quickly parse a XML in php

Docker helper command list

Magento Community edition username password Magento default user pa the password is ‘bitnami1‘ Docker helper command list docker-compose up -d docker-compose start docker-compose stop docker-sync start docker-compose run deploy bash docker-compose --verbose run deploy bash docker-compose ps setup:di:compile docker exec -ti f28sad7asduasd bash docker inspect fdwerwer docker ps fdwerwer docker ps -a docker volume prune Restart from scratch docker-compose down -v composer install vendor\bin\ece-tools docker:build docker-compose up -d docker-compose run build cloud-build docker-compose run deploy cloud-deploy Clean Docker environment Clean fully docker-compose down -v docker volume prune docker container prune docker image prune docker-compose start Creating module Php bin/magento module:enable –all php magento setup:upgrade Creating page php bin/magento module:enable –all Php bin/magento setup:upgrade php bin/magento module:status php bin/magento module:enable Php bin/magento module:dis

SQL HELPER

  RDS AUTHENTICATION mysql -h xxxxxxxxxta.us-east-1.rds.amazonaws.com -u admin -p SELECT User,Host FROM mysql.user; SHOW GRANTS FOR 'drupal'@'%'; SQL Client Recommendation TablePlus(Mac) DBeaver Mysql Workbench SequelPro Import database #1 mysql h xxxxx.com -u username -p dbname < dbexport.sql OR #1 mysql h xxxxx.com -u username -p #2 use database-name; #3 source file.sql Export all Databases sudo mysqldump --all-databases -udxxxx -p > oct-16-2019-database.sql Export Specific Database mysqldump --databases xxxxxx-name -udxxxx -p > oct-16-2019-database-david-raleche.sql NOT A ROOT USER mysqldump –all-databases> database.sql mysqldump -all-databases -uuser -ppassword> database.sql mysqldump –all-databases –skip-lock-tables -u user-ppassword > Sept2018database.sql Long Queries Explain SQL TABLE SIZE select table_schema, sum((data_length+index_length)/1024/1024) AS MB from information_schema.tables group by 1; CRON NACKUP DATABSECron Back

GIT command Helper/Cheatsheet

  Successful Git Connection ssh -Tvvv git@github.com Copy Shh key from Macbook pbcopy < ~/.ssh/id_rsa.pub Generate SSH Key Github $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" $ eval "$(ssh-agent -s)" $ ssh-add ~/.ssh/id_rsa (regular unix system) $ ssh-add -K ~/.ssh/id_rsa (for macbook) $ pbcopy < ~/.ssh/id_rsa.pub (for macbook) Paste key into github $ git remote add origin git@github.com:xxxxxx/xxxxxxx.git   $ git remote -v $ git push -u origin master SETUP REMOTE GIT git init  git add .  git status  git commit -m "First commit"  git remote add origin git@github.com:xxxxxx/xxxxxxx.git  git remote -v  git push -u origin master Add Key to github cat ~/.ssh/authorized_keys cat ~/.ssh/known_hosts SYNC GIT git remote update git fetch  Downloads the latest from remote without trying to merge or rebase anything. git fetch -- all REMOVE untracked files git clean -f -d RESET BRANCH/FILE git reset --hard origin/master  -- force discard loca

How to fix git pull origin master returns fatal: invalid refspec ?

Image
remove lines below from  .git/config[remote “origin”]         url = git@github.com:dxxxx/xxxxxxxx.git         fetch = +refs/heads/*:refs/remotes/origin/* Type following commands  git remote add origin git@github.com:xxxxxx/xxx.git  git remote -v

How to fix pgDump dbeaver ?

Image
  DBeaver Configuration : Postgres and MacOs 1 . Install postgres 2. Find path to pg_dump /Applications/Postgres.app/Contents/Versions/latest/bin 3. configure client (Dbeaver) to add hidden files -> command + shift + G paste  /Applications/Postgres.app/Contents/Versions/latest/bin and select the folder 4. Voila !

How to fix – DBeaver Native client is not specified for connection ?

Image
  Native client is not specified for connection Download Mysql or Postgres or (appropriate database ) Server Do the step of DBEAVER client configuration Find bib files for mysql – open terminal and execute followin command which mysql --> /usr/local/bin/mysql if using a mac to allocate mysql server bin files location command + shift + G Paste the path in there such as /usr/local/mysql-5.7.28-macos10.14-x86_64/bin/ Voila you can enjoy most amazing feature of DBeaver  !

How to find text in a Unix file ?

  find . -type f -name "*.*" -exec grep -il "YOUR TEXT" {} \;

How to send an email with php ?

  yum install php7-pear.noarch Pear Install Mail – David Raleche – pear7 install mail – pear7 install net_smtp <?php $email_from = "test@gmail.com"; $email_subject = 'test subject '; $email_message= 'test message '; // Pear Mail Library require_once "Mail.php"; $from = '<test@test.com>'; $to = '<test@gmail.com>'; $subject = 'Hi!'; $body = "Hi,\n\nHow are you?"; $headers = array( 'From' => $from, 'To' => $to, 'Subject' => $subject ); $smtp = Mail::factory('smtp', array( 'host' => 'ssl://smtp.gmail.com', 'port' => '465', 'auth' => true, 'username' => 'test@test.com', 'password' => 'test!' )); echo "DAVID<br>"; echo $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo('<p>' . $mail-