Coding trivia 1

Random interesting stuff that I learned last week

ER diagrams

Entity Relationship diagrams are important concept in database design. They help to conceptualize the relationship between tables in a database. I was looking for a quick refresher on the ER diagrams. These two videos did the job: Part 1 and Part 2

Unix sockets

You know when you’re trying to connect to MySQL and an error shows up that the socket file is missing? That’s because in MySQL the socket connection is enabled by default on localhost. What are UNIX socket files? These are files that enable two application to communicate with each other on the same machine, without the need for networking.
Here is an in-depth explanation of how they work:
www.techdeviancy.com/uds.html
And here’s a quick video explanation:
www.youtube.com/watch?v=uXve8WYiGts
More on the details of sockets:
stackoverflow.com/questions/14919441/principle-of-unix-domain-socket-how-does-it-work

read more →

Creating a custom keyboard layout in Linux

Sometimes you might want to modify the keyboard layout, for example to add non standard characters that you’re often using or if you’re writing in 2 different languages you might combine all their special characters in one keyboard layout. In my case I bought a keyboard that had the escape key mapped by default to the Home Page special key and I found irritating having to press the Fn key every time I needed to use the escape button.

read more →

Setting up the fixture in PHPUnit

When running our tests we should begin with a know stage, called the fixture, and for that we might need to initialize variables etc. And after we finish the tests we might have some cleaning up to do.

If you need to have custom code run before you execute them. PHPUnit allows you to configure a specific file to be run before the test execution.

This directive in your phpunit.xml configuration file will execute the bootstrap.php fiel before the tests: :

read more →

Setting up WordPress development environment with Docker

One of the biggest challenges in web development is to have a stable development environment and assuring that the website works when deploying on different servers.

Docker helps us build isolated containers that give a this stable and predictable environment and saves many headaches when debugging our website. Thanks to the preconfigured images available on Docker Hub and the Docker compose it’s a breeze to set up a development environment.

read more →

Downloading and installing custom Linux kernels

You might want to install a different kernel to which you have supplied with your current version of Linux. This might be because another version might work better with your hardware.

The Linux kernel is the core of the operating system that facilitates interaction between the hardware components and software.

You can install a different version of the kernel with the apt command:

sudo apt install linux-image

The command will present you with several options and you need to type the specific one you would like to install.

read more →

Setting custom PHP code sniffing rules

Code sniffing is the practice of checking the code for compliance with some pre-determined standards. It’s very important to run your code through a sniffer because it helps with maintenance and ensures better code quality.

The most common standards in PHP are PSR-0, PSR-1, PSR2 and PEAR. These rules might specify details such as depth and type of indentation, placement of braces, spacing, variables names etc. Depending on the standard, they might go into a lot of detail about how the structure of your code should look like.

read more →

How to deploy a React app in a subdirectory on a WordPress site

The case here is pretty specific, but maybe somebody will be in the situation like me. I have a WordPress site and I wanted to deploy a React app to include in my portfolio and serve it from a subdirectory.

When deploying a React app in a website subdirectory there are some hurdles to overcome. First of all, WordPress redirects most requests to the main index.php file, so when you’re trying to load the app the server might direct the request there and you will get an error. To resolve this you need to edit the .htaccess file so that the requests are correctly routed. Below is the code that you should add in your access file , before the rewrite conditions of WordPress:

read more →

What are .htaccess files?

If you were working with WordPress you probably noticed that the installation includes a .htaccess file in its main directory.

Whate are these files?

The .htaccess file set specific directives for the server that should be executed when an Apache server is handling requests. In the default case of WordPress it makes the server point most of the requests to the main index.php file, which then loads all the necessary scripts. The server needs to be configured to look for and honor the directives included there. That can be achieved using the AllowOverride directive that is specified by by directory. Access files allow you to set different directives per directory without the need to touch the main server configuration.

read more →

Docker volumes vs bind mounts

By default a docker container won’t store any persistent data, so anything that we write to its writable layer won’t be available once we stop it.When running Docker containers we might be interested in persisting certain data. This can be achieved by using either volumes or bind mounts. Below I’m describing main differences between the two.

Bind mounts are directories on the host filesystem mounted onto a Docker container. These can be modified outside of Docker.

read more →

Different ways of running PHP on an Apache server

When the server receives a request from the user it can serve the file directly, but sometimes it needs to translate the code using the appropriate application. Otherwise it would be showing the users the source code of the website. A server like Apache needs to be configured to handle specific content with an appropriate application like PHP.

A common set of rules of passing the information between the server and the application is the Common Gateway Interface. This standard lets programmers write applications in different languages that can plug into the server and interact with it. The interface guarantees consistency of data passed between the server and the application. An alternative to a CGI application is Microsoft’s Active Server Page (ASP).

read more →