Proxy Design Pattern

Proxy Design Pattern First, some definitions. Wikipedia: In computer programming, the proxy pattern is a software design pattern. A proxy, in its most general form, is a class functioning as an interface to something else Design Patterns. Elements of Reusable Object-Oriented Software: Provide a surrogate or placeholder for another object to control access to it. There are a few reasons to use Proxy pattern and control access to the underlying object: ...

June 8, 2019 · 2 min · 294 words

How to send request to UNIX socket

This is one of those notes to myself, so I can remmber it better or find it later more easy. I was recently strugging with permission problem for the unix socket, the mistake was quite silly - I did not turn permission bit on for the folder with socket file. And before I found the solution I tried to debug socket and I found that you can curl socket with ...

May 12, 2019 · 1 min · 204 words

Stream redirection tl;dr

I love terminal, it is so simple and so reliable. When I’m in doubt, when I’m not sure the GUI I’m working with gives me correct representation I always turn to the terminal as an ultimate source of truth. Every process has at least three communication channels a.k.a. streams attached to it: STDIN. Standard input with file descriptor 0 STDOUT. Standard output with file decriptor 1 STDERR. Standard error with file descriptor 2 Usually when we work with streams we use file descriptor numbers. ...

April 30, 2019 · 2 min · 290 words

Composition vs. Inheritance in PHP, tl;dr version

After reading a numerous resources on what is composition in terms of OOP and how it plays versus inheritance, I came up with following understanding: So inheritance is awesome way to reuse code between objects but it comes at cost. When class inherit from parent class there is no way to not implement methods/reduce parent’s code. You have to implement everything according to parent class You need to make sure you are compatible with parent’s class in case override something Child class may know about parent’s methods implementation, in case they are not private, which breaks incapsulation Inheritance means deep coupling between parent and child classes Composition is just another way to inherit other classes Basically you do not inherit class directly but get it injected into the constructor or via setter method. For instance: ...

April 13, 2019 · 2 min · 280 words

HTTP versions difference

Here is the differences between HTTP versions with comments in plain english. HTTP 1.0 capabilities: Request may consist of multiple newline separated header fields. Response object is prefixed with a response status line. Response object has its own set of newline separated header fields. Response object is not limited to hypertext. So basically since this version it is not hypertext but hypermedia protocol. The connection between server and client is closed after every request. One of the main drawbacks of this protocol version. ...

March 15, 2019 · 3 min · 560 words

Visitor Design Pattern

Visitor design pattern is one of many patterns that fall under category “Behavioral patterns” Allows to move part of the logic/algorithm from one class to another, so you can extend/add new behavior to the initial class without changing its code. One of the ways to follow “open/closed” principle. Here is an example: interface Visitor { // quite reasonable to a visitor to be able to "visit" other classes public function visit(Person $person); } interface Person { public function accept(Visitor $visitor); } // so these two interfaces know about each other class RealVisitor implements Visitor { public function visit(Person $person) { // this sequence of "operations" is quite naive // but you can implement here whatever you want // instance of Person interface can be changed however you want // no need to update/change class itself $person->name = 'Mr. Whiskers'; print $person->name . PHP_EOL; print $person->surname . PHP_EOL; print $person->address . PHP_EOL; } } class RealPerson implements Person { public function accept(Visitor $visitor) { $visitor->visit($this); } } // camera, action! $realVisitor = new RealVisitor; $realPerson = new RealPerson; $realPerson->name = 'David'; $realPerson->surname = 'Hamster'; $realPerson->address = 'Holland'; $realPerson->accept($realVisitor); // output: // Mr. Whiskers // Hamster // Holland Hope it helps. Thanks! ...

February 17, 2019 · 1 min · 203 words

tcpdump tiny cheat sheet

tcpdump is such an amazing tool, even knowing just basic parameters you can do a lot. show list of available interfaces sudo tcpdump -D show packets with X argument. Use A in case you want to see only textual info and skip binary in hex sudo tcpdump -X track only specific port sudo tcpdump 'port 8888' do not resolve host names, lets you see IP addresses sudo tcpdump -nn With all those arguments combined you can track connection to the program opened on local machine on port 8888 and see the following: ...

November 10, 2018 · 5 min · 1018 words

Mutation testing in PHP

Today at my job I did an internal presentation on mutation testing in PHP. Here is the presentation: What it lacks is the live example of how it is done. So I’m going to just short list here an example. For this code intro I’m going to use PHP7.2. The only PHP class we have is this one below, and it is pretty much naive but is usefull for our example: ...

August 2, 2018 · 3 min · 592 words

Amazing GIT for seasoned developer.

At first, like so many others I didn’t use git to full extent, the tool belt of git add, git commit, git push, git pull allowed me to survive through the day. At some point I realized that I need to enforce my GIT knowledge. In short GIT has an insanely rich eco system of different tools designed to do only one thing but do it very good. This is not a post but rather a set of things I would like to remember about GIT. ...

June 13, 2018 · 5 min · 1023 words

How to sign your commit with GPG

First step - creating the key itself. Note that I’m using Fedora and for some rason I have to use gpg2 though gpg is available also for some reason. Generate your key: gpg2 --full-gen-key First two questions - choose default answers, but for key expiration date it is up to you, I chose ‘0 = key does not expire’ option. To view fingerprint for the newly created key use: gpg2 --fingerprint <[email protected]> ...

May 20, 2018 · 2 min · 271 words