Chapter 5. Developers' Treasure

In this very chapter, we will kick start by building a web server using Python. We will then see how to process all our images automatically using ImageMagick. Then, we will look at the git flow branching model and how it will help you. Furthermore, we will see how meld command line can help merge our git conflicts. We will then focus on the working of ngrok tool and see how it saves the day by proxying requests coming from the internet to our laptop. We will also explore the versatile query capabilities of jq, the Swiss army knife of JSON! Towards the end, we will explore ways in which one can manage and kill Linux processes.

In this chapter, we will cover the following:

We have prepared a basic demo html file that contains a button, a div, a jquery function (for helping us do some ajax calls), and a script that will try to load static content from our server and put the content inside the div tag. The script is trying to load a simple text file on the disk, /file:

The spot webserver

If we open this file inside our browser, we can see the page content:

The spot webserver

Clicking on the button generates a javascript error. It is telling us that we want to do a cross-origin request, which is not allowed by default by the browser. This is to prevent cross-site scripting attacks. What we need to do in order to test our javascript code is to serve this file in an HTTP server.

In order to start an HTTP server in the same folder as the file, we type the following command:

The spot webserver

This is a basic Python module that opens port 8000 on localhost, serving only static content (so, no, you can't use it for php). Let's open the address in the browser:

Click on the Click me! button. We see that our file content was loaded in the div beneath the button, which means the browser is no longer blocking us, because we are issuing requests to the same host using the same protocol. Looking at the output from our Python server, we can see all the requests that the browser has made to the server. We can see it's requesting by default a favicon.ico file that doesn't exist and it's giving back a 404 status code:

The spot webserver

You can find the files used in this project on the GitHub project page.

Also, if we stop the server and go one level up and fire it up again, we can use it as a webdav server, with the possibility of navigating through the files in the current directory. We could, for example, give access to a folder on our local machine to a remote user and allow them to access it through a page in the browser, eliminating the need to install a file server.