Template literals, where were you?

Ever since I started work at a new company 4 weeks ago, I’ve been challenged to learn the new paradigms of the Javascript programming language.

Think of me as an OG Javascript programmer who’s still stuck in pre-ES2015 era. I’ve been stuck with jQuery and vanilla JS pre ES6 as my front-end tools for the last 8 years and I’m learning of the awesome tricks that comes with ES6 and any versions beyond it. Part of the reasons I’ve not advanceD is my focus on developing backend solutions using Python and PHP.

One thing that has struck me today is template literals which can achieve the following:

  • Using variables as text placeholders e.g. `Hello ${name}. Are you ok?`
  • No need to concatenate using the plus operator (+)
  • No need to use the plus operator for multi-lined strings. You can write HTML code as is within the back ticks ()
  • Add Javascript expressions such as addition calculations etc
  • CLEANER CODE

I’m definitely enjoying ES6/ ES2015 and looking forward to tackle ReactJS and VueJS soon.

Change Drupal 8 User Password

Changing the password of Drupal 8 user is easily done using drush. As of this post, the Drush version I’m using is version 9.5.2 and was installed in the project’s directory using composer (composer require drush/drush).

The syntax is:

drush upwd [user]  [password]

OR

drush user:password [user]  [password]

For example, to change the admin user password:

drush upwd admin "another_password"

How to merge Excel Sheets Vertically?

This can be achieved in Pandas using the concat() function. The data frames generated from the read_excel() function are added as a list to the concat() function:

import pandas as pd

df = pd.read_excel('file-2.xlsx')
df1 = pd.read_excel('file-3.xlsx')
df2 = pd.read_excel('file-4.xlsx')
df3 = pd.read_excel('file-5.xlsx')

df_combined = pd.concat([df, df1, df2, df3])
df_combined.to_excel('combined_files.xlsx')

Then finally use to_excel() function to generate the new combined Excel file.

Merge Dictionary in Python

There are two methods but I’ll focus on one that is a trick which merges two dictionaries and creates a new one using the ** character to pass multiple arguments using the dictionary:

x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = {**x, **y}
print(z)

Results:

{'a': 1, 'b': 3, 'c': 4}

Since both keys have the same b key, the last dictionary is considered and added to the resulting merge. In other words, if there are duplicates, the duplicate in the first dictionary is replaced by the duplicate in the second one.