Coding

Ever since I advanced beyond the “hello worlds” of Java, I had never stopped coding. This section is for documenting code usages that I had employed while solving the technological problems that I had encountered.

How to send an HTTP request to a HTTP Basic Authentication endpoint in Java without using any external libraries

One common task for Java developers is to write codes that communicate with API endpoints. Chances are these endpoints could use HTTP Basic Authentication for authenticating the HTTP request sender.

Although there are good libraries to help us craft and send HTTP requests to a web server in Java, I prefer to use the Java core library so as to keep my Java program lightweight.

Referencing my earlier post on how to construct a HTTP request to an endpoint with HTTP basic authentication, this post documents how to send an HTTP request to a HTTP Basic Authentication endpoint in Java without using any external libraries.

How to construct a HTTP request to an endpoint with HTTP Basic Authentication

The HTTP basic authentication is a mechanism commonly used by web servers to authenticate the sender of a HTTP request. Such a mechanism is usually used to guard server endpoints that are meant to be accessed programmatically.

Almost every new project that I got my hands on required me to create client side coding for accessing server endpoints that use HTTP basic authentication for authenticating the HTTP request sender.

To have a quick reference on how to construct a HTTP request to an endpoint with HTTP basic authentication, I created this post to as a documentation. The steps are agnostic to any programming languages.

How to reflect cart count at the cart icon as and when products are added or removed from the cart in WooCommerce

Although there is a hassle free option of using WooCommerce.com as your e-commerce store, you may prefer to host your own.

If you are familiar with WordPress and wish to host your e-commerce website, WooCommerce is also available as a WordPress plugin that augments WordPress with e-commerce website features.

Although more work needs to be done for self-hosted WordPress sites, we have the option of creating our own themes without having to pay additional charges on top of the web hosting fees.

When it comes to creating our own WooCommerce themes, one feature that we may want to implement would be to show the number of products that had been added to our WooCommerce cart near the shopping cart icon as and when products are added or removed from the cart.

This post documents how we can reflect cart count at the cart icon as and when products are added or removed from the WooCommerce shopping cart.

How to host your Python 3 Flask MVP with Supervisor on Ubuntu Server 16.04

Due to its minimalistic design, the Python Flask framework is ideal for building the web server layer of minimal viable products (MVP) to validate customers’ needs. However, development work is just one part of the user validation efforts. To ensure that our customer can access our Flask MVP and provide feedback as and when they are available, we will need to get it running with as a server daemon.

Supervisor is a convenient tool for running applications as a server daemon.

This post documents the steps that I took to host a Python 3 Flask MVP with Supervisor on an Ubuntu Server 16.04 instance.

How to serve static files with Python 3 + Flask

Python Flask is a good microframework for building a minimal viable product to validate our ideas on the Internet. A modern web application encompasses documents that tell the web browser how to build the visuals of our web application and communicate with our server backend. Such documents are usually static in nature and are served as they are to the web browser without any processing from the server end.

Comparing setting up an instance of the Nginx server with adding code in our Flask application, the latter can be a more convenient way for us to realise our minimal viable product. This post documents the proof of concept that I did to serve static files with Python 3 and Flask.

Things about the Object class in Java that programmers ought to know about

After getting started with Java development, getting to know the Object class well is one of the next steps that programmers should undertake to be proficient with the Java programming language. This post lists some points about the Object class in Java that programmers ought to know about in order to code well in the Java programming language.

A platform independent way to set your Python Path for your Python applications

In a software development house where desktop computers run Microsoft Windows while servers run Linux, software developers will have to ensure that the Python code that they wrote on their Windows machine can run on the deployment servers which are running Linux.

One unavoidable task for Python application developers is the importing of functionalities that are contained in other Python scripts. In order for the Python interpreter to find the Python scripts that are referenced by Python import statements, the Python Path will need to contain the URLs of the directories that contain the Python scripts to be imported.

How to sort a python dictionary by keys

I am a fan of hash tables when I need to implement logic that augments computation results to a common data structure that need to be used across several function bodies. The ability of the hash table in providing constant access by key helps me in keeping my logic from taking too much time to complete.

Python’s version of hash tables are known as a dictionaries or associative arrays. Apart from augmenting computation results to values of my Python dictionaries, one common task that I often perform is sorting the results by the dictionary keys. In this post, I document how I can sort my Python dictionary by its keys.