Skip to main content

Posts

Running a Web Server Built with Rust in Debian

Running a Rust web server as a service behind a proxy is the sane way to go. Part 1:  Using Rust to build a bare-bone web server.  Let's assume this part is done because programming is easy.  Part 2:  Configuring the web server to run in the background as a service . Last part:  Further configuring the web server to run behind a proxy so that to keep it safe from the Internet, and to utilize many features which have already been built with the proxy. Running a service is operating-system dependent. Different operating system has a different configuration for running a service. In fact, some operating systems has a couple of ways to run a service. Yet, some may prefer to run a web server in a container like Docker. However, a container requires much more resources than a service. There is no point in building a full-blown web server using Rust especially for a narrow business purpose, even though it can. Just like any web server, a Rust web server...

Sending Emails via SMTP

msmtp  requires a minimal setup for sending emails via SMTP compared to sendmail. Here is a configuration for you to send emails from a web host to an external SMTP server. Prior to doing that, you must check whether there is a clear communication channel between your web host and the SMTP server. You can use Telnet . Set up msmtp You are going to set msmtp as an MTA . Hence, you need to remove all other MTAs such as postfix and sendmail: $ sudo apt-get --purge autoremove postfix sendmail Install msmtp and related utilities: $ sudo apt-get install msmtp msmtp-mta mailutils Configure msmtp: $ sudo nano /etc/msmtprc # Set default values for all following accounts. defaults # Use the mail submission port 587 instead of the SMTP port 25. port 587 # Always use TLS. tls on # Set a list of trusted CAs for TLS. The default is to use system settings, but # you can select your own file. tls_trust_file /etc/ssl/certs/ca-certificates.crt # The SMTP server account mx host mail.mx.exam...

Sending SMTP Email via Telnet

You want your webhost to be able to send emails through an external SMTP server. The first thing to do is to check whether your webhost provider allows this to happen. Some concerned providers block outgoing SMTP ports to prevent you from doing email spamming. Let's try to connect with the SMTP server via Telnet from within your webhost. You may need to SSH into your webhost first. And then issue the following command: $ telnet -4 mail.example.com 587 The above command will connect to the mail.example.com SMTP server via port 587 and force Telnet to use IPv4. If the connection fails then your webhost provider may have blocked the outgoing SMTP port 587. You may need to politely ask your webhost provider to open the port for you. You can't do it yourself. Note: Telnet will resolve to IPv6 by default. If the SMTP port is not open on IPv6 then Telnet will appear hung until all trials via IPv6 connections are timed out. If IPv6 failed then it will resolve to IPv4.  Telnet should h...

JQuery-UI Viewfinder

Users want to select a rectangular area. There are many ways to do it but we are going to use JQuery-UI . We will create a transparent JQuery-UI dialog box which users can drag and resize like a viewfinder. Around the dialog box's empty and see-through content area we will attach a rectangular frame which will resize as the dialog box resizes. We will measure the frame while a user is viewfinding a rectangular area with it. Here is the trick to make a JQuery-UI dialog box transparent. There is a dialogClass property which we can use to assign customized CSS classes to a JQuery-UI dialog box. We just need to add a class that set the background color with a transparent alpha value. Not the entire dialog box will be transparent but the content area will. That is just perfect for a viewfinder. We create a rectangular frame as a viewfinder using a div with a solid border, which we also set to resize itself whenever the dialog box resizes. We capture the current size and position of ...

The Software Stack for The Arduino CNC Controller

  Computer Numerical Control ( CNC ) is very much software driven. Yet, the architecture of the CNC software is obscured from the general software world. It has evolved separately with its own paradigm and nomenclature. At the heart of a CNC is the G-Code which is an old programming language that resembles an assembly language . A G-Code keyword is a combination of a letter and digits such as G0, G2, M2, M30, etc. All letters in the alphabet are fully used in G-Code. It is all about moving a tool onto a certain path in a work coordinate system with certain speed, duration, distance, and anything related to it. They call it jogging  and inching the tool. It may involves multiple tools simultaneously. The tools need to move accordingly to make, to assemble or to move products. Understanding how G-Code works is the precursor to understand how CNC works. In a CNC controller as depicted above, the Arduino Nano becomes the G-Code interpreter to control 3 stepper motors simultaneou...

Get Current User of Drupal 9 Externally

You have a stand-alone application that is not a Drupal module but resides in a Drupal sub-folder . And you want Drupal to manage your users. You want to access the currently logged-in Drupal user from your application. The following function will give you the current  user id, name, email and roles: use Drupal\Core\DrupalKernel; use Symfony\Component\HttpFoundation\Request; /** * Get Drupal current session user details. * Passing Drupal folder, or its relative folder such as '..' * when it is called from a Drupal sub-folder. * Return ['id', 'name', 'email', 'roles'] */ function get_drupal_current_user($drupal_dir) { // Change the directory to the Drupal root. chdir($drupal_dir); $drupal_root = getcwd(); if ($drupal_root === false) return []; $autoloader = require_once 'autoload.php'; $kernel = new DrupalKernel('prod', $autoloader); $request = Request::createFromGlobals(); // Emulate Drupal /index.php to get ...

How to Create a Tiny Gnome Panel Application

On every  Gnome Shell desktop there is a main panel at the top of the screen. Usually, the panel shows the current time, the WiFi signal, the speaker volume, the power button, and the activity startup button. There can be many other things on the panel as individual user penchants. The panel will not be covered by anything, and will be there at all time except when there is a full-screen application running. The Gnome community has decided that the whole humanity needs the panel. What little things of texts and icons on the panel are called Gnome Shell extensions. Each of them is a kind of a desktop application which always run through out a user session. They can be personalized. We are going to create a simple and useless application that shows a running counter, something like the one that shows '1473' on the panel image above. It can be a starting point for a bigger and productive application. But before we begin let's get familiar with a collection of handy Gnome too...

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing va...

Welcome to the Era of Living Cell Programming

I was reading Understanding mRNA COVID-19 Vaccines by the United States Centers of Disease Control and Prevention when it stunned me that living cell can be programmed in vivo . mRNA COVID-19 vaccines are produced by Pfizer and Moderna . I already knew what Ribonucleic acid (RNA) is. RNA is almost a half part of DNA the super-intelligent organic codes that manifest us. But I didn't know that they can produce messenger RNA (mRNA) which can instruct cells to do whatever they wanted. This is my understanding so far. mRNA vaccines instruct our cells to make a protein and then triggers antibodies to kill the protein. In the case of mRNA COVID-19 vaccines it will instruct our cells to make a part of the virus proteins which is harmless to our body but sufficient enough to trigger the antibodies. Later when the real virus enters our body the trained antibodies will kill it. mRNA is a new kind of medicinal system. An mRNA can be sequenced or programmed to instruct a cell to make all sort...

Sub-Domain Pointing into a Drupal Sub-Folder

You will get the Forbidden error message when you try to access a folder which is not a part of Drupal. I got that error message when I created a subdomain which was pointing to a folder inside a Drupal installation. At first, I wasn't thinking about Drupal and I was looking for a solution in a wrong direction until I realized the Drupal's strict .htaccess . Then, I came across a Drupal Answer -  Make a folder inside the drupal installation public . The solution is that you need to configure Drupal .htaccess to ignore the sub-folder for the sub-domain. Add a rewrite condition to ignore the sub-folder somewhere near the rewrite rule for index.php : RewriteCond %{REQUEST_URI} !^/your-sub-folder/ ... RewriteRule ^ index.php [L] And since the sub-folder is being influenced by the Drupal rewrite rules so the sub-folder needs to have its own rewrite rules. Add the following .htaccess file to the sub-folder: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /your-sub...

The Essence of Blockchain

A blockchain is a chronicle of signatures . Everyone can see the signatures but no one can afford to alter them. As a new block of signatures joins in as time passes the blockchain security as a whole becomes stronger. Blockchain is protected by public cryptography with no need of a central supervision. By design, altering any of the signature will be a very expensive undertaking. So expensive as comparable to the cost of breaking a vault of gold, which act of breaking in is much more expensive than the gold itself. All signatures are well-verified prior to being kept secured into a blockchain. Hence, all signatures in a blockchain can be trusted without requiring any third party verification. The principle of blockchain was made popular through the Bitcoin  whitepaper  by an illusive Satoshi Nakamoto . Even though the two words block and chain were never mentioned as one word in the whitepaper the essence of blockchain was described through out the document. The Bitcoin b...

Everything has a Signature

Every data has a signature  which can be derived mathematically. All data of any size can be digested into fixed-size signatures. The signatures can be used to identify the data. Unique data has unique signature. Cryptographic hashing is a mathematical technique to hash or digest a data to reveal its signature. Digesting the same data always produce the same signature. Any minor change on the data will produce significantly different signature. A changed data is a different data. Data signature, hashing or digesting makes it possible for the data to be represented by its signature into a subsequent signing by combining it with one or more data signatures to produce a new signature representing a larger data set. Eventually, all data can be digested in chunks to produce a single signature. A signature can be verified by hashing the same data again which will produce the same signature. This introduces data signing-verification concept. In a communication between two parties, ...

The Eternal Wall of Grafittis

Hackers have emotion. People says the Bitcoin blockchain is hacker-proof. No hacker has ever managed to hack even a bit of the Bitcoin blockchain since its inception in 2009. The cryptographic process was designed to be very expensive to reverse. So expensive that the total world wealth is not enough to pay for the work to reverse the process. Thus, hackers express their frustration by plaguing the Bitcoin blockchain with grafittis. They creates fake transactions embedded with grafittis. It is so fake that even miners cannot differentiate. Fake transactions do not compromise on the integrity of the blockchain. However, each of them adds long term memory cost to the miners machines. Fake transactions soothe hackers frustration against so many failed attempts to hack the blockchain. Graffiti in Transaction What is a fake transaction? Before we answer that question let us understand what a real transaction is. A real transaction produces new coins to addresses. The new coins may com...

Domain Name Resolves to A Wrong IP Address

I registered a new domain name. While in the process of registration I checked on the new domain name that showed a default page. I should have not done it in the first place checking on a site with incomplete domain name registration. Once the registration was completed I pointed the new domain name to my web server. And I created a new "Hello World" page. However, the new page didn't show up on a browser on my laptop. However, it showed up on my smartphone. And it showed up on my son's smartphone. It just didn't show up on my laptop. It showed the original default page instead. After a few trials the default page became very suspicious to me. Searches on the Internet pointed to a potential browser malware. And I spent a few hours hunting for the malware that eventually never existed. I looked up using a different browser and I made a query using curl . All responded with the same suspicious default page. Thus, it had nothing to do with the browsers or their...

Separation of Front-end and Back-end Concerns

Separation of concerns is the cornerstone of MVC framework. Model, view and controller are three broad concerns of web-based software development. On its early days MVC was implemented on server side. The server renders views for clients. Nowadays, most clients render views themselves. Even the terminology of client-server has already morphed into front-end and back-end . The need for back-end to handle views is diminishing. View concerns have became increasingly complex with two big sub-concerns of aesthetic and dynamics. Front-end evolves into bigger MVC concerns of itself. While back-end evolves into larger modeling concerns. Now, front-end and back-end are two separate concerns. Front-end and back-end are handled by two different teams of software developers with different specialties. Back-end evolves into something like "dinner can be served even without plates, forks and spoons, without table and chairs, and without a dinning room." Front-end is serving the withouts....

Model-Action Framework

Let  front-ends handle views. This is the time we break up MVC and make it more practical. We are going to focus on back-end without view concerns . There are deeper issues regarding the broader concerns of the model, view and controller. The three-point idea cannot be so simple. The reality is more complicated. Now without view, we are going to slice model and controller into smaller applicable concerns. Views should not be handled from the back-end. We are threshing the view concern from the back-end altogether. First of all, look at the plethora of front-end frameworks concerning views. Why do model and controller not catching up? Because model and controller are invisible to the naked eyes. Because users can decide on the looks and feels of an application. Because users have no idea and do not care on how data are being handled. Thus, due to the absence of users at the back-end, there is no pressure at all for developers to really pursue on improving model and control...

Using React in Foundation for Sites

This post was the precursor to the Foundation-React Template . React and Foundation are two different web UI frameworks addressing different needs. They evolve differently. Both of them are powerful on their own accord. Fusing them together may create superpower. We will walk through the process of adding React into Foundation. We will start by installing both Foundation and React through command line interface (CLI). Then we will create a simple Todo web app. Along the way we will highlight the development process. But before all that, let us summarize React and Foundation. The details can be found at their respective websites. Both of them are well documented. React is a run-time UI rendering engine. It renders dynamic UI elements in its own fast virtual DOM, and only update necessary changes to the slow browser DOM. This behaves like a  double buffering DOM which makes any UI update feels fast. React wraps a UI rendering script in a component. A React component can ...

Debugging PHP using Apache Error Log

PHP runs on the server side and behaves like a function that return a value against the given arguments. A remote client may call this function and expect a specified return value and nothing else. So how do we debug this function ? It must not return debugging messages since the client is never designed to handle them. We must never burden any client to handle debugging messages. If we run PHP through Apache server then we can use the error log to keep our debugging messages. It may not be the best way to do it. But we only want to talk about this approach now. Error Logs The Apache error log files generally can be found in the following directory: var/log/apache2 We issue the following command from within the directory to read the latest error messages: # tail error.log The tail command reads the last few lines from the error.log file and prints them on the terminal. If we need to read a specific number of lines from the end of the file then we can specify the -n opti...

ESP8266_RTOS_SDK and Debian

If you search the Internet for ESP8266 you will get Arduino related results. It seems that the world see ESP8266 as a part of Arduino. This may change in the future. I prefer not to use Arduino for ESP8266 development because that approach was technically a work-a-round. Arduino IDE was designed for its own devices. I don't want to use an IDE which generally comes with unnecessary dependencies and constraints. I want to have the full control of the device that I'm working on. That's why I started my earlier ESP8266 developments with esp-open-sdk . I'm okay with the command line approach and a simple text editor. Now I want to utilize the real time operating system and explore its potentials. ESP8266 is powerful enough for RTOS. I searched the Internet for ESP8266 and RTOS, and I found many paradigms. ESP8266 is in a constant development. People were trying all sorts of approaches because in the beginning they were left alone . And now Espressif seems to take over ...