Daniel Gafitescu Freelance web developer focused on open source solutions

23Jul/160

Docker

I switched from using Vagrant boxes to Docker .

There are few reasons why I did that :

- starts very fast

- low memory & disk usage

- there is no need to use Virtualbox anymore

- can deploy to AWS , DigitalOcean and Rackspace  same server configuration as on your local

- scale easier

I watched a couple of training videos :

1. Learning Docker from O'Reilly

2. Real World Docker from O'Reilly

Tagged as: No Comments
30Jun/160

Send SMS using AWS SNS

Usually I go with Twillio for sending SMS but AWS has a cheaper and easier solution for this.
Here is the code to send a sms using AWS SNS

First thing install aws/aws-sdk-php package

require __DIR__.'/../vendor/autoload.php';

use Aws\Sns\SnsClient;
$client = SnsClient::factory([
    'credentials' => [
            'key'    => 'your key',
            'secret' => 'your secret',
        ],
    'region'  => 'us-west-2',
    'version' => "latest"
]);

$sent = $client->publish(
    [
        'Message' => 'This is the message',
        'PhoneNumber' => '+123344545',
        'MessageAttributes' => [
            'AWS.SNS.SMS.SenderID' => [
                'DataType' => 'String',
                'StringValue' =>  'The sender'
            ]
        ]
    ]
);

 

Tagged as: , , No Comments
19Jan/160

Collectd

I wanted to see more statistics on my server over a period of time and one of the open source solutions was Collectd .

In order to view the graphics I installed Collectd-web which comes with a stand along python server that I can start when I want and just start ssh tunnel to see web page.

collectd

4Jan/160

“Build APIs You Won’t Hate” & “Modern PHP: New Features and Good Practices”

Finish 2 books this holiday that I really like:


1. Modern PHP: New Features and Good Practices
If you are uncertain which programming language you like to learn and you are not sure if PHP is the right way this book will certainly change your mind.

 

 

 

 

 

 

 

 

2. Build APIs You Won't Hate

Last year most of my work evolved around API and specially building  REST API. This book gave me confidence that I am on the right track and also what I can improve when moving forward.

While driving I also listen to Rework which was a interesting as well.

19Dec/150

​ O’Reilly – Up to Speed with PHP 7

Recently I had updated my VPS Php version to 7. It was easy and pretty smooth. I only had to add a single file so that WordPress would work with mysqli extension instead of old mysql extension which was deprecated.
I wanted to see what's new in Php 7 and I saw that O'Reilly had a course about it so I went and what it. Here is a short review of the course.


Php 7
- first major version release since PHP5 in 2004 after Php6 was abandoned in 2010
- is powered by a new engine PHPNG ( Php new generation)

Changes :

Internal changes
- according to Rasmus Lerdorf 100%+ performance on the most real-world apps
- lower memory usage
on Wodpress 4.1.1 PHP7 is slightly slower than HHVM 3.6.1
- simplifies creating add-on tools
- yield doesn’t require parentheses
- empty list() now allowed
- 64-bit integer support in Windows
- support for strings >= 2^31 on 64-bit builds ( video file conversion as string )
- very few breaks in backward compatibility
- most fatal errors now catchable ( Exception being thrown)
- mysql extension has been deprecated
- new json extension
- assert controller by configuration settings
- posix regex has been removed
- alternative php tags have been removed
- assign of new by reference has been removed

New operators:
- Spaceship operator ( already in Perl & Ruby )

$a = 6;
$b = $c = 10;
echo ($a <=> $b); ==> -1
echo ($b <=> $c ); ==> 0
echo ($c <=> $a) ==> 1

- Null coalesce operator

$variable = $non_existent ?? ‘default’ ;
also can be used in cascade
$var = $non_existent ?? $name ?? ‘default’;

Unicode escape syntax

$name = “Caf\u{00e9}” => Café

Functions
- random_bytes(20) ( Usage bin2hex(random_bytes(20));
- random_int(1,6) ==> generate a number between 1 and 6

Return type declaration
- is optional
prevent unintended return values
- forces sub classes to return expected data type

function convertor($string) : array {
……
return $array;
}

- Scalar type hinting
used for boolean (bool ), integer(int), float & string
- optional
- have 2 modes week & strong ( is done by declare(strict_types=1);
and needs to be first statement in the file

function multiply(int $a, int $b): int {
return $a*$b;
}

Anonymous classes
-can be assign to a variable
-return from a function
-pass as argument to a function
-extend a class , implement interface & use traits
- can’t be serialised

$testClass = new class() extends SplHeap {
protect function test($data1,$date2)
{
return ($data1 <=> $data2);
}
}

Generators return expressions


function generate() {
$total = 0;
for($i=1; $i<10;$i++) {
yield $i;
$total += $i;
}
return $total;
}
$counter = generate();
foreach($counter as $number)
{
echo $number;
}
echo “total = “. $counter->getReturn();

Generator delegation;
Binding to closures at call time;
Grouping Use Declarations

use SomeNamesSpace\SomePackage\SomeClass;
use SomeNamesSpace\SomePackage\SomeOtherClass;
use SomeNamesSpace\SomePackage\SomeDifferentClass;

Some as

use SomeNamesSpace\SomePackage\ {SomeClass, SomeOtherClass , SomeDifferentClass};

- Can be used for constants a function as well & even mix and match;

Errors
-catching fatal errors using Error class
-errors and expectations belong to different classes
-both implement the Throwable interface
-errors/exception can be catch in block

Other improvements
-improve security of unserialize;
-preserve 0 fraction when encoding as JSON

Tagged as: , , No Comments
9Nov/150

The Martian by Andy Weir

A month ago I went with a friend of mine an saw at the cinema "The Martian" and I loved it.

Then I look over Youtube and are a bunch of interview with Andy Weir about the book.

After I seeing those videos I decided to read the book as well. In just a week, for a couple of hour a day, I manage to finish it. I kindly recommend it.

Here a few quotes from the book I love:

Me: “This is obviously a clog. How about I take the it apart and check the internal tubing?” NASA: (After 5 hours of deliberation) “No. You’l fuck it up and die.” So I took it apart.

NASA, however, is absolutely shitting itself. They see the Water Reclaimer as a critical survival element. There’s no backup, and they think I’l die instantly without it. To them, equipment failure is terrifying. To me, it’s “Tuesday.”

Most of the book NASA is "shitting bricks" ... fun read for sure.

29Jul/150

CSS3 In-Depth from pluralsight.com

Watched CSS3 In-Depth just to see what's new in CSS3. Turns out there a lot of stuff but still some of them are not available in all browsers.

It's definitely a good watch if you are a front end developer.

22Apr/150

Change field using migration on Laravel 4.2

If you have to change the type or in my case to add more options to the a ENUM field you need first to drop it and then to create it again (this will destroy the information in those field)


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UpdateTableNameStatus extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('table_name',function(Blueprint $table)
{
$table->dropColumn('status');
});

Schema::table('table_name',function(Blueprint $table)
{
$table->enum('status', array('PENDING','IN PROGRESS','COMPLETE'));

});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('table_name',function(Blueprint $table)
{
$table->dropColumn('status');

});

Schema::table('table_name',function(Blueprint $table)
{
$table->enum('status', array('PENDING'));
});
}

}

28Mar/140

Became a Zend Certified Php Engineer

Introduction

At the begging of 2013 I have read the article Become a ZCE in 2013 so I have set myself the goal that by the end of the year I should do be a Zend Certified Engineer. For the next 11 month I have totally forgot about it and in December I saw a tweet that said that Zend has upgraded the certification from Php 5.3 to Php 5.5 & rebranded from Zend Certified Engineer to Zend Certified Php Enginner so I bought a voucher.

The voucher is available for a year long so it gives you plenty of time to prepare for it, but I chosen the second to last day of the year to take it which was in fact the last day that I could schedule that exam. Ever since I have finished the university in 2008 I haven't taken an exam and I missed the thrill of going to one and even if I wasn't 100% sure I'll pass I went anyway. After the first 15-20 questions I was pretty confident that I was going to take it and in the end I wasn't sure on 4 questions , 2 of them were theory questions and the other 2 were code samples.

Advantages of being ZCE

  1. Proof that you are senior developer
  2. your future employ will be easier pursued into hiring you, and you can demand a raise on the current one
  3. looks good on your resume
  4. You will get to put a nice icon on your website ZCE logo to prove that you are certified and link it to Zend Yellow Pages.
  5. fill in the gaps in your Php knowledge and learn new stuff so you can use later

Testing system

I quite liked the testing system which was quite simple and intuitive. You have to answer 70 questions in 90 minutes , so you have around a minute and 30 seconds per question which is quite enought. Most of the time the question that are theoretic can be answer just in few second and you should take the time left to focus on the code sample ones.

If you are not sure of an answer you have the option to mark it for review and go back to it whenever you like, and even if you forget about it when you finish the exam you are asked to check again the marked for review questions. I was given 2 sheets of plastic paper that can be easily erased and 2 markers if you need to write something down other than that you can have anything with you.

As far as I recall around 15-20 question are from the new material starting with Php 5.4. Even if there are 70 questions in one question you are required to know the theory from several topics so they will cover the whole spectrum.

If you fail the exam they give you a report on specific topics that you lack knowledge so that you can improve on them next time but they don't give you the specific questions that you failed.

In order to find a test center you can access Zend Technologies Certification Testing from Pearson Vue but most likely you'll find one if you live in a big city.

Type of questions

There are 3 types of questions:

  1. Single answer. You are given 4 options in which just one is correct. Most of the question are like this type
  2. Multiple answers. You are given at least 4 options in which at least 2 of them are correct.This type of question are marked as multiple and you can easily figure it out because you get checkboxes instead of radio buttons.
  3. Fill in the blanks. You are given a sentence that you have to word or a phrase. In one of the questions I was given it was require to give the name of a function (func_num_args). There are only 2 or 3 questions like this one.

Where to study from ?

  1. The main source is obviously is the official website: php.net
  2. Video training
  1. Books
  1. Blogs that you can find by googling ZCE

Miscellaneous

  1. Don't pay the full price for a voucher

There is always a coupon code that you can use and get at least 10% of the Zend PHP Certification Voucher and you can get it just by doing a simple search on google. I have used the coupon code CJ4ZEND which is around $15 off the total of 195 and the coupon still work today. Also if you fail the exam for the first time, the second time you want to buy the voucher you will have a discount.

  1. Zend Certification Study Guide

You get a pdf file to down in email once you buy the voucher but seems like the file is not there any more http://static.zend.com/topics/PHP-5-3-Study-Guide-v1.pdf . In this draft pdf file you got sample questions devided per chapter but from my point of view they were easier than the one from the actual exam

  1. Read the php docs on the ebook reader/table device

In my case I have download the the php documentation fromhttp://doc.php.net/downloads/epub/php_manual_en.epub as epub format and read it on my kindle where I can make notes with ease.

  1. Test Prep: Zend PHP Certification online course

There is a very expensive test preparation from Zend which cost $1000 including the examn voucher which from my point of view is quite expensive.

  1. Upgrade from PHP 5.3 Certified

In October 2013 at a Zend Conference in Paris the new certification has been announce and it included PHP 5.4 and 5.5 and keeping a lot of the question from the previous exam but you can easily apply for an upgrade if you are allready PHP 5.4 Certified. In my case I have waiting for the new Php 5.5 certification for quite a while and everytime I email Zend they replied that it was a working in progress and they didn't have a release date. The chapters has been upgraded as well and you can found them in Exam information section.

Preparation

They way I prepared was quite simple: I allocated 4 hours per each chapter and I have started with the part that was most familiar with and increase the time on the chapters that wasn't that good at like regular expressions, SPL and Traits in my case. In order to pass the exam you should be flawless on the Php Basics and you must treat all the question here as a trap. Don't always go for the obvious answer especially that you have code that you need to check. In my mind come the example with the strpos function.

if (strpos('abcdefg','abc')){
    echo "found it!";
}else{
    echo "didn't find it..";
} 

At first glance you would say that it will echo "found it" but if you pay closer attension the strpos will return 0 which will be cased to a false boolean so in fact it will show "didn't find it..".

For the SPL which I never used before I study from the php|architect's Mastering the SPL Library and was just frustrated that I didn't used this before but after looking and studying it now everything that I can do with SPL I am using it. Regular expressions were another chapter that I wasn't that familiar with and I payed more attention to it and to the php functions.

All the function regarding strings, array & file management you need to lean by heart if you don't know them by now and also the operator priority list is another part that you need to be familiar with.

For the XML chapter you got to deal with SimpleXml , DOM and for this the best aproach was to get a xml file and play with all the function and methods so you can get more familiar with it. I have got 5 question involving XML so practicing was very importing on this matter.

Where to go next

Working in our field where thing change with such a pace and new technologies and framework emerge so often it's hard to settle for a certain version or framework. You always have to learn & research so you be up to date, and this sort of certification prove that you do that and you are always trying to improve and move forward.

There are a lot of other test/certification that you can take. The most appealing for me right now it's the Sensio Labs's Symfony certification specially if you are working with Symfony 2. There is also the Zend Framework 2 certification that you can take also from Zend. There is also ThePHP Curriculum which look really promising and the fact that Sebastian Bergmann ( the PhpUnit creator) is behind the project.

Anyway if you are looking forward to take the exam good luck with it and if you allready have passed it please share your experience in the comments below.

27Oct/130

The Healthy Programmer: Get Fit, Feel Better, and Keep Coding – book review

healthyFor the past few month I've been having back problems and I saw someone mention on tweeter about a book dedicated for programmers on health & well being. It's The Healthy Programmer: Get Fit, Feel Better, and Keep Coding written by Joe Kutner .

Even if I was reluctant at first once I have start reading it and I have finish it within a week.

On my case to prevent back problems it offered exercises that were even recommended to JFK which couldn't  keep his child in his arm because of it.

Here is a list of quick things that I pick up from it:

- we need to do at least 10 000 steps per day ...and they are gadgets to help you keep track of that NIKE+ SPORTBAND

- staying indoor every day can weaken your immune system so is better to stay out in the sun for 10 minutes ...hunt for D vitamin.

- weight is a factor that you need to watch on a daily basis, heart pressure once a month.

- a day a week don't each meat ...it will try to do that twice a week starting next year.

 

These are just a few tip that I pick up from the book and there are plenty there backed up by a lot of research links.

I recommend the book to all people who  work every day at a desk and with a computer.