Programming Blog

Programming related articles.

Use python as a Simple HTTP Server

The other day, I needed to share files with a Windows based computer. I did not have any ftp nor samba server installed on my machine. For some reason ssh did not work either. As a quick solution, I decided to use a trick I saw some time ago. I started a python process which works as a simple HTTP server. Next, I opened a browser on remote machine and connected to my HTTP server and downloaded the files through HTTP.

curl tutorial with examples of usage

Curl is a linux utility that is used to make HTTP requests to a given url. It outputs HTTP response to standard output and is actually very easy to use. Here are some examples to show its usage...

Pretty printing JSON output in terminal

If you need to pretty print the json output of a terminal command (so you can inspect it more easily), you can use python's json module. I usually use it to pretty print the output of curl command. Here is an example

    :::bash
    curl http://somesite.com/my/json/ | python -m json.tool

This utility can also be used to pretty print json files like following

    :::bash
    python -m json.tool minified.json > prettyprint.json