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 allow arbitrary Widget content to be added to sections of your WordPress theme

When you use WordPress to house your thoughts, you get the flexibility to update sections of your WordPress site through the WordPress dashboard.

For example, I can change the content within the sticky portion of my sidebar as and when I need to. Such content can be provided through the various WordPress Widgets that are available in my WordPress installation.

So how can we mark sections of our WordPress themes for displaying Widget content?

With this in mind, let us look at how we can allow arbitrary Widget content to be added to sections of our WordPress theme via the WordPress dashboard.

How to make a portion of your sidebar sticky as you scroll till the footer of your web page with jQuery and some CSS styles

You want a portion of your sidebar to stick as you scroll down your web page.

When you reach the footer of your web page, you want that portion to stop just above the footer of your web page.

In this case, you can use jQuery to help you achieve this behaviour.

Given that, this post shows how to make a portion of your sidebar sticky as you scroll till the footer of your web page with jQuery and some CSS styles.

How to send a HTTP request with client certificate + private key + password/secret in Python 3

When we need to create a HTTP client that communicates with a HTTP server through certificate-based authentication, we will typically have to download a certificate, in .pem format, from the server.

After we had downloaded the .pem file, the HTTP client will use the private key and certificate to authenticate itself with the HTTP server. Sometimes, the HTTP client will need to decrypt the private key with a password/secret first.

So with a .pem file and a password/secret, how can you create a HTTP client in Python 3 to send a HTTP request to the HTTP server?

In case you need it, this post shows how to send a HTTP request with client certificate + private key + password/secret in Python 3.

How to solve “No API definition provided” error for Flask-RESTPlus app on Cloud Foundry

When you create an API endpoint that generates a QRCode with Flask-RESTPlus, you may want to deploy it onto Cloud Foundry.

However, when I first tried to do so, I was greeted with a No API definition provided when I accessed the Swagger Api portal page.

qrcodeapp showing No API definition provided

So why is there a “No API definition provided” error for Flask-RESTPlus app on Cloud Foundry?

In case you are facing such a problem, this post discuss how I had managed to solve the “No API definition provided” error for my Flask-RESTPlus app on Cloud Foundry.

How to write a C# program to communicate with an ESP32 development board via Bluetooth Serial

Coupled with Bluetooth Serial and GPIO pins, ESP32 can augment a Windows machine with the ability to read from sensors.

So with an ESP32 development board, you can turn your old Windows machine into an IOT gateway that can sense its operating environment.

Given these points, let us look at how we can write a C# program to communicate with an ESP32 development board via Bluetooth Serial.

How to use C# to read sensor data from Arduino or ESPx via serial connection

When you have an old Windows machine, you can convert it into an IOT gateway.

So how can we read sensor data with our windows machine? Since our windows machine probably do not have GPIO pins, we can read sensor data via an intermediary device.

For example, we can first attach an Arduino Uno or ESP32 development board as the intermediary device to our windows machine via USB. Given that connection, the intermediary device will read the sensor data and send those values via serial. On our Windows machine, we can then run a program to read those values from serial.

So how can we read sensor data from Arduino or ESPx via serial connection on our Windows machine? Since C# is a programming language for creating windows application, we can use C# to read those data from serial.

How to create an API endpoint that generates a QR Code image, with Python 3 Flask-RESTPlus and python-qrcode

When you have an API endpoint that generates a QR Code image, another device with a QR Code scanner will be able to get the encoded value to perform some action. For example, WhatsApp web generates a QR Code image that encodes a code for WhatsApp app to sign in the user.

So how can you create an API endpoint that generates a QR Code image? With this in mind, let’s look at how we can do so with Python 3 Flask-RESTPlus and python-qrcode.