Skip to main content

Posts

Showing posts from 2021

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 simultaneously. G-Co

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