Sample transactional stored procedure

 
CREATE DEFINER=`root`@`localhost` PROCEDURE `Sample`(IN inParameterID VARCHAR(10))
Sample:BEGIN
 
DECLARE httpStatus INT DEFAULT 500;
DECLARE errorCode INT DEFAULT NULL;
DECLARE errorDetails TEXT DEFAULT NULL;
 
DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
BEGIN
    ROLLBACK;
    SELECT 500 AS statusCode, 'Failed' AS statusMessage;
END;
 
SET @variableID = 0;
 
SELECT  TableA.ID INTO @variableID
FROM TableA  
WHERE TableA.ParameterID = inParameterID;
 
IF @variableID = 0 THEN
    	SELECT 500 AS errorCode, 'Transaction failed' AS errorMessage;
	LEAVE T2activatePersonStandby;
END IF;
 
START TRANSACTION;
 
UPDATE TableA;
 
UPDATE TableB;
 
UPDATE TableC;
 
END IF;
 
COMMIT;
 
SELECT 200 AS statusCode, 'Success' AS statusMessage;
 
END

PHP PSR-4 and Namespaces

How-to add namespaces to old php project

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

Simple project with namespaces
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

Bitbucket is good for free private repos
Github is good for free public repos, for demonstration of your work

Difference between Strategy and Factory design patterns

A Strategy pattern is an operational pattern. Strategy pattern allows you to polymorphically change behavior of a class. Strategy pattern is to avoid conditionals switching in favor of polymorphism.
So, Strategy pattern = polymorphism.

A Factory pattern is a creational pattern. Factory pattern allows you to encapsulate object creation.
Factory pattern = encapsulation.

A difference between Simple Factory and Abstract Factory. Simple Factory – you only have one class which acts as a factory for object creation. Abstract Factory – you connect to an interface and then call the different factories that implement this interface which are supposed to have different implementations of the same method based on some criteria.

Abstract Factory looks like a strategy pattern, but it differs from it semantically because it is used for OBJECT CREATION rather than operations. So, basically you have object creation using different strategies.

PHP PSR-1 Explained

      Class names MUST be declared in StudlyCaps.
      Class constants MUST be declared in all UPPER_CASE with underscore separators.
      Method names MUST be declared in camelCase.

Ubuntu Skype enable group chat

/msnp24

simply need to cope and past to someone that is not online
in the chat then restart the skype and you are done

Swiftmailer sending email via gmail.com

 
<?php
 
    $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465)
        ->setUsername('yourusername@yourdomain.com')
        ->setPassword('yourpassword')
        ->setEncryption('ssl')
        ->setAuthMode('login');
 
    $mailer = \Swift_Mailer::newInstance($transport);
 
    $message = \Swift_Message::newInstance()
        ->setSubject('Welcome')
        ->setFrom(array('yourusername@yourdomain.com'))
        ->setTo(array('to@to.com'))
        ->setBody('hello world')
        ->setContentType("text/plain");
 
    $mailer->send($message);

Git restore local branch deleted by mistake

 
1. git reflog | grep pp-auth-r1.1 
response: 592b75b
2. git branch 2.7.4-69179 592b75b

Silex Microframework structure points

1. A bootstrap (app/bootstrap.php) and application file (app/app.php) which could be used by my frontend controller, as well as by PHPUnit/Codeception

2. A web directory that is accessible for the world, containing only index.php and possibly some resources web/index.php

Ubuntu using Lxrandr to position second monitor

lxrandr

saves configuration to: /home/imran/.config/autostart/lxrandr.desktop
sample:

[Desktop Entry]
Type=Application
Exec=xrandr --output HDMI1 --mode 1920x1080 --rate 60.00 --output eDP1 --mode 1920x1080 --rate 60.00 --left-of HDMI1
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_GB]=LXRandR
Name=LXRandR
Comment[en_GB]=To keep laptop on the left handside with monitor in the center
Comment=To keep laptop on the left handside with monitor in the center
imran@imran-Lenovo-Z51-70:~/.config/autostart$