Send Data from Disabled HTML Input Field

If you want to disable an input field and but still post it’s data to a database via a back end programming language like PHP, give it the readonly attribute i.e.

<input name="Percentage" readonly="readonly" type="textbox" value="100" />

If assigned the disabled attribute, then it will not be able to post data.

What if you are working with a <textarea> element?

<textarea id="description-text" class="form-control" name="description_change" rows="5" required readonly><?php echo set_value('description_change');?></textarea>

Ref:

Install Any pip Package Globally – Linux

Instead of the package installing in:

/home/username/.local/bin

and install it globally and have it accessed from any Linux user, install it with sudo -H flag. For example:

sudo -H pip3 install seaborn

The above installs it in /usr/local/lib/python3.5/dist-packages and is accessible globally by any user or Python application.

This issue arose when I was trying to run a Jupyter notebook. There was a missing seaborn Python package but it was only installed in the .local folder of the logged in user (/home/user/.local).

Set Local Time on Ubuntu Server

To set an Ubuntu server instance to local time, simply type this command:
sudo dpkg-reconfigure tzdata

You’ll be greeted by a similar screen to this one (as of this post, I’m running Linux ubuntu-xenial 4.4.0-93-generic/ Ubuntu 16.04.2 LTS):

Linux Timezone Setting
Linux Timezone Setting

Select your geographic region and then your city/region corresponding to your timezone.

 

Python Unicode Encode Errors

It’s sometimes stressful when working with string conversion in Python while coming across encoding errors. An example is the following error that was generated when I converted a JSON file into CSV so that I can analyze the data using pandas:

‘ascii’ codec can’t encode character u’\xe9′ in position 2

The JSON file was generated from an Influx DB instance via cURL. These links from Stack Overflow really helped. Please read the first two answers from each question. The second question’s most voted answer gives a detailed description on why you should not do a system wide change to utf-8 encoding as opposed to the first question’s most voted answer.

Further reading: Getting unicode right in Python

Python UUIDs

An interesting article I read on generating UUIDs using Python:

http://www.minvolai.com/blog/2009/10/Creating-Universally-Unique-ID-in-Python/creating-universally-unique-id-in-python/

I’m currently exploring the use of UUIDs to create unique identification for IoT sensor devices.

Will post more later here on what I find out and how I’ll implement it. I’m currently implementing a virtual sensor since I don’t have the actual devices. My host device for the sensor is a *NIX based system. e.g. Raspberry Pi Raspbian (for testing), MacOS (for development).

Add JS to Drupal 8 website

For the last two months I’ve been working on my first Drupal 8 website. Its quite a huge leap from version 7 but the new features and methodology of working with a Drupal CMS is way better.

One bit I struggled with was inserting a custom Javascript file that made use of jQuery functions. This is how I managed to do it (I assume you know how to develop a Drupal 8 theme and how to develop with Drupal 8 in general):

In the theme_name.libraries.yml file, define you library and add the js file i.e.

custom-js:
 js:
  js/main.js: { every_page: true }
   dependencies:
    - core/jquery
    - core/drupal.ajax
    - core/drupal
    - core/drupalSettings
    - core/jquery.once

Save the file. Next, edit the theme_name.info.yml to add the library i.e.

libraries:
 - 'theme_name/custom-js'

Save the file. Open your custom Javascript file e.g. main.js and add you code in the following format. The code demo below ensures Drupal’s no-conflict policy for Javascript libraries. We want to ensure that the different libraries you use function independently. This example caters for jQuery:

jQuery(document).ready(function($){// insert your code here

});

Save your file and you should be good to go.

Create Drupal 8 Custom Page Template

Simply place the following code in the .theme (theme_name.theme) file that is located inside your theme folder. Replace theme_name with the actual name of your Drupal theme.

function theme_name_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// Add content type suggestions.
if ($node = \Drupal::request()->attributes->get('node')) {
array_splice($suggestions, 1, 0, 'page__' . $node->getType());
}
}

Then create a file under the template folder and name it according to your node content type e.g.

page--page.html.twig

Then add your custom code for that particular page.