Getting A+ SSL on ssllabs.com

Just follow this tutorial

https://stackoverflow.com/questions/41930060/how-do-you-score-a-with-100-on-all-categories-on-ssl-labs-test-with-lets-encry

If having problems creating ssl, refer to

https://www.digicert.com/ssl-support/pem-ssl-creation.htm

Drop all mysql tables without permission to delete and create new database

In mysql, the simplest way to flush all tables is to delete the db and create a new one. However, one might not have permission to do that. So we need a script to list all tables and delete it.

#!/bin/bash

USER=xxx
PASS=xxx
HOST=localhost
DB=xxx

mysqldump -u$USER -p$PASS -h$HOST --no-data --add-drop-table $DB | grep ^DROP | mysql -v -u$USER -p$PASS -h$HOST $DB

How to check if ssl is installed correctly

To check ssl is installed correctly, run in command line

openssl s_client -debug -connect yourwebsite.comhistory:443

or

https://cryptoreport.rapidssl.com/checker/

If you are getting any errors, ssl installation is wrong.

Normally you would get the crt from the intermediate CA. convert it to pem

openssl x509 -inform DER -outform PEM -in server.crt -out server.crt.pem

remember to nginx -t before restarting.

Sample Test for Backend Developer

This is a question that I came up with based on real hands-on project and experience. The question is not really testing on someone’s ability to know the code syntax. but rather the approach to solving a common day-to-day technical problem. The questions do require backend knowledge and the open ended questions will allow candidates to show off their object oriented skills if they want.

Objectives

1. Test candidate’s ability to understand complex and vague briefs which happens a lot.
2. Test candidate’s analytical and problem solving skills
3. Test candidate’s attention to details.
4. Test candidate’s understanding of web standards.
5. Test candidate’s proactiveness to suggest ideas and think out of the box.

The Brief:

A client approached us to create a social media campaign for the launch of their new energy drink. Let’s call the drink “powerhouse”. The client also advised they are on a limited budget.

The creatives met up with the client and came up with an idea.

The idea is to build a really simple competition webpage within the client’s website that encourages people to spread the news about the new product. Users arrive at the page and sign up a form. After a successful sign up, they get one entry for the competition. At that point, they also have an option to share the sign up link. Every successful sign up referred via the link will give extra competition entries to the original link poster. There is no limit to the number of entries that a person can enter. So the idea is: The more entries you have, the higher your chance to win the prize.

The prize is 100 bottles of powerhouse drink.

The top 10 person with the most entries will win the prize.

Requirements:

1. The new webpage is to be launched 3 months from today.
2. The duration of the competition will be 1 month from the day it is launched. After that, the webpage will be removed.
3. The webpage will consists of text, graphical elements and a sign up form.
4. The sign up form will consists of the following compulsory fields: First name, Last name, Mobile Number and Email Address.
5. When the form is submitted, the user will receive an EDM (Electronic Direct Mail) with an option to post a special link to the competition page from his/her facebook or twitter account.
6. When people arrive to the competition page via the special link and signs up the form. The original poster will get one more extra entry for the competition.
7. After the competition has expired, provide a list of winners to the client.

An Example:

1. Bob goes to the competition page and signs up the form. Bob gets 1 entry to the competition.
2. Bob receives an EDM encouraging him to share to his friends. Bob posts the news in facebook via a link from the edm.
3. Jane sees the news in facebook and clicks on the competition link.
4. Jane arrives at the competition page and signs up the form.
5. Now, Bob gets 2 entries and Jane gets 1 entry to the competition.

Question:

As a backend developer, write down your thoughts and/or provide pseudocode/diagrams if necessary.

1. What are your considerations to implement a secure form.
2. How would you trigger an EDM upon a successful form submit?
3. How would you track referrer form submissions as described in the requirements?
4. How would you provide a list of winners to the client at the end of the competition?
5. Describe how you would implement the form and all the backend logic associated with it. Feel free to suggest any tools or services that would help you to achieve that.
6. Do you foresee any problems with this competition prior launch? Do you think if there is anything in the requirements that deserves clarification?
7. Can you provide a rough estimate on how much time you will need to implement a workable backend solution based on the requirements?

phpstorm useful plugins and shortcuts

Useful Shortcuts

1. to open up preferences, “command + ,”

2. show file in project tree or anywhere, “fn + shift + f1”

3. code completion, “ctrl + space”

4. search everything, “shift + shift”

5. search class, “command + o”

6. navigate to line, “command + l”

7. generate getters and setters, “command + n”

Useful plugins

1. symfony plugin, php annotation, markdown viewer, liveedit, ideavim

Drupal 8 quickstart using composer

There are benefits of using installing drupal via composer.

composer create-project drupal-composer/drupal-project:8.x-dev myproj
cd myproj
# you can now add the required plugins eg
composer require drupal drupal/devel:8.*

Forget about drush, let us use the drupal console to install the site. This is the symfony way.

# let us configure the drupal command line
ln -s /path_to_myproj/vendor/drupal/console/bin/drupal /usr/local/bin/drupal
cd web
drupal site:install

Docker Cheatsheet

Docker helps a lot in the dev process.

If using windows or mac, need to use a vagrant vm that allows nfs.

https://github.com/blinkreaction/boot2docker-vagrant

this will help u setup the vagrant. Once vagrant is up, shell in and run docker commands.

Remember to port follow all the relevant application port in virtualbox.

Here are some commonly used commands:

1. To build a new image from a Dockerfile

cd folder_containing_dockerfile
docker build -t username/app_name .

# if behind proxy
docker build -t username/app_name --build-arg http_proxy=x.x.x.x:port --build-arg https_proxy=x.x.x.x:port

2. View all docker images

docker images

2. View all containers

docker ps -a

3. Create a new container

cd website
docker run -d -p 8080:80 -p 8036:3306 -v `pwd`:/var/www/dir image_name
# if you use the --name option, you can specify the exact name of the container, else it will use some random cool name

4. Stop and start a container

docker stop containerid_or_name
docker start containerid_or_name

5. Remove an image

docker rmi image_name

6. Remove a container

docker rm containerid_or_name

7. Shell into a container

docker exec -it containerid_or_name /bin/bash

8. Use docker-compose now to manage docker installations

eg https://github.com/naga3/docker-lamp

9. In your dockerfile, When you pull from docker library, you are running its dockerfile first before running yours

eg FROM php:5.6-apache

Good resource:

kickstart docker lamp setup
https://github.com/docker-library
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

Delaying until condition is fulfilled

In javascript, we can use setTimeout to do call itself recursively until a condition is met.

Here, we want to check the html content with an interval of 300ms until it is populated, then we will do something.

function checkPostCode() {
	
	if ($('#my_postcode').html() == '') {
		setTimeout(function() {
			checkPostCode();
		}, 300);
	}
	else {
		$('#nearest_store').html('some content');
		return;
	}
}
checkPostCode();