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.

Implementing Google Custom Search as a WordPress page without using any plugin

Creating a search engine to search content across a polyglot website is not an easy task. In order to do that, you need to either:

  • take a search query and match it across data repositories from different application processes, or
  • have a process that will maintain an index of content from the different applications and search within that content.

Since Google had indexed most of the content in the Internet, Google Custom Search can be the easiest way for us to implement site-wide search. In addition to fast searching, Google Custom Search also comes with AdSense monetization.

In case you need it, this is how you can implement Google Custom Search as a WordPress page without using any plugin.

How to create a custom page template in WordPress

We use pages in WordPress to hold content of our website that are not specifically time-dependent.

Examples of such content at Techcoil include the about page, disclaimer page and Raspbian Stretch Lite project ideas.

When you want to show content in different page layouts, you can create different customized page templates to show content in different ways.

In case you need a reference, this post describes how to create a custom page template in WordPress.

How to make a HTML search box with the input text field and search button within the same enclosing box

Since Google had indexed most of the content from my website, Google Custom Search is the easiest way for me to implement site-wide search. In addition to fast searching, Google Custom Search also comes with AdSense monetization.

Given these points and some time on hand, I had recently implemented site-wide search with Google Custom Search.

In addition to building the search page to display the search result, there is a need for a HTML search box beside the top navigation links:

Techcoil search box as at 20180616

Since I had spent quite a bit of time on building the search box, I decided to document the steps in this post for future references.

With this intention, this is how to make a HTML search box with the input text field and search button within the same enclosing box.

How to send a HTTP GET request to an API endpoint and add the response as HTML elements to the DOM with jQuery

jQuery is a JavaScript library that simplify client-side scripting of HTML.

In case you want to augment your webpage with data from an API endpoint, you may want to look at jQuery.

With this purpose in mind, this post discusses how to send a HTTP GET request to an API endpoint and add the response as HTML elements to the DOM with jQuery.

How to paginate MongoEngine records in your Python 3 Flask application

Flask and MongoEngine help makes development work easier.

One common task in the development of backend applications is the pagination of database records. Without pagination, the application server can run out of memory while generating a response from the database records.

This post discusses a way to paginate MongoEngine records in your Python 3 Flask application using the facilities provided by the Flask-MongoEngine extension.

How to deploy Python 3 Flask application on Raspberry Pi 3 with Raspbian Stretch Lite, Nginx, Supervisor, Virtualenv and Gunicorn

Raspberry Pi 3 Model B boards make good gifts for programmers and if someone had gifted you with one, you may want to use it as a control center for interacting with various IoT sensors and devices at home.

In such a situation, you may want to build a Python 3 Flask application to present the web interface for accessing the control center.

After you had built that Python 3 Flask application, the next step will be to deploy it on your Raspberry Pi 3 for serving HTTP requests.

This post discusses how you can deploy a Python 3 Flask application on Raspberry Pi 3 with Raspbian Stretch Lite, Nginx, Virtualenv and Gunicorn.

How to enable authenticated MongoDB access for Flask-MongoEngine applications

After having a first look at MongoDB more than 5 years back, I told myself that I will use MongoDB to realise the next functionality of Techcoil.

With exposure to Python 3, Flask and MongoEngine in 2017, I had acquired the skills to build a microsite to recommend gift ideas. This microsite uses MongoDB to store the gift recommendation data.

With Flask and MongoEngine, development of this microsite did not take too much leisure time. With MongoDB not enforcing authentication, there were not much hindrance in setting up the development environment for this microsite.

However, this free-for-all mode of accessing MongoDB is not recommended for production environments. Without authentication, it is easier for ill-intentioned people to mess up the backend database.

To ensure that I have a go-to post for implementing authenticated access to MongoDB backed projects in the future, I document the steps needed for Flask-MongoEngine applications to access MongoDB instances with access control turned on.