Runbook: Upgrade NodeJS on Ubuntu

Here are the steps you can follow to upgrade NodeJS on an Ubuntu system.

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*

sudo apt-get purge nodejs npm
sudo apt autoremove

Download the latest installable archive for your OS from https://nodejs.org/en/download/

tar -xf your-archiveFile
sudo mv extracted-archiveFolder-name/bin/* /usr/local/bin/
sudo mv extracted-archiveFolder-name/lib/node_modules/ /usr/local/lib/
node -v
#should display the latest version of node

Convert ReactJS App to Android App on Ubuntu

Install Cordova

npm install cordova -g

Create a Cordova project

cordova create ReactBasedPhoneApp

Open package.json of the existing ReactJS App.
Copy the sections – scripts, dependencies, browserList from the above package.json and paste it into the ReactBasedPhoneApp/package.json

Build the existing ReactJS App

npm run build

After the build completes successfully, copy the contents inside the build folder of the existing reactJS app to ReactBasedPhoneApp/www folder

Set Android Home

export ANDROID_SDK_ROOT=/home/{username}/Android/Sdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Add Android plugin

cordova platform add android

#in case you use phone camera in the application
cordova plugin add cordova-plugin-camera

Build the APK

cordova build android

#if you want to debug the app in a running simulator or USB connected android phone
cordova run android

Fix: Cordova App on Android shows blank screen with ERR_CONNECTION_REFUSED

Problem: The Cordova App when run on Android give a Connection refused error on https://localhost/* URLs.

Fix: Follow these steps:

  • Edit package.json
  • Set homepage from “./” to “https://10.0.2.2/”
  • Save, build and run the App.

Probable Reason: Localhost seems to get routed to the host while the emulator runs the App within a virtual container (assumption).
10.0.2.2 is a special IP mapped to the “localhost” of the emulated environment.

Upgrade NodeJS on Ubuntu

Here are the steps you can follow to upgrade NodeJS on an Ubuntu system.

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*

sudo apt-get purge nodejs npm
sudo apt autoremove

Download the latest installable archive for your OS from https://nodejs.org/en/download/

tar -xf your-archiveFile
sudo mv extracted-archiveFolder-name/bin/* /usr/local/bin/
sudo mv extracted-archiveFolder-name/lib/node_modules/ /usr/local/lib/
node -v
#should display the latest version of node

Easy Engine – change domain on WordPress website.

I had recently lost my domain codemarvels.com; the warning emails from my domain provider was reaching a currently unused inbox, and thus had to spawn up the same website on codemarvels.in (the one that you are currently on).

The only command that worked for me on my EasyEngine deployment (for my ssl enabled website) was:

#upgrade to ee4 with this command
wget -qO ee https://rt.cx/ee4 && sudo bash ee

#clone existing website to new one.
ee site clone codemarvels.com codemarvels.in --ssl=le

If your new domain is mapped to this server, it should be ready for serving.

Clear Maven Cache: Solution to transitive dependencies not updating on clean install

Follow these steps when maven clean install just doesn’t update the transitive dependencies in nested projects.

rm -rf .m2/repository/path-to-your-library
cd your-project-folder
find . -maxdepth 2 -name "pom.xml"  -exec mvn clean -f '{}' \;
mvn clean install -DskipTests=true
#confirm if the versions are as you wanted
mvn dependency:tree | grep -B 75 the-bugging-library

If the above method doesn’t work, you might have missed to add the required version in the dependency management.

Lets assume BL is the library which has been bugging you with these version issues 😉

cd your-mvn-parent-project
vi pom.xml
#add
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>BL-group</groupId>
                <artifactId>BL-artefact</artifactId>
                <version>required-version-of-the-BL</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

Let me know if these steps helped.

Fix the error: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags during maven builds

Problem: Maven package gives this compile time error when using Open JDK.

Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags -> [Help 1]

Reason: Lombok version included in the project seemingly had a dependency on Oracle JDK, which is fixed in 1.18.2

Fix: Upgrade lombok to 1.18.2 in the POM file.

		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.2</version>
			<scope>provided</scope>
		</dependency>

  

Tat Kim Bot : A twitter bot to transliterate Sanskrit

Glad to write about a twitter bot I had written and launched during the last Independence day – Tat Kim. For those who are not in the know, Tat Kim means “What’s that?” in Sanskrit – a very apt name for a Bot and allied service which answers questions of Sanskrit enthusiasts.

What does the Tat Kim Bot do?

Currently Tat Kim bot can be used to read Sanskrit tweets in your own script (Eg, Malayalam or Kannada) – there by taking away the need to know how to read Hindi (or Devanagari) to be able to consume these tweets.

Why?

Sanskrit is a pan-Indian language and it should be free from the constraints of a regional Lipi like Devanagari. Also, it helps to remember that some of the seminal works in Sanskrit were recorded not in Devanagari, but in Grantha Lipi (more or less Malayalam of our times)

Usage

If you happen to find a Sanskrit tweet from your favourite Sanskrit tweeple, comment on that tweet in the below format

@TatKimBot {languageCode}

Where language could be one from:
en, hi, bn, gu, kn, ml, or, pa, te, ta, mr

Details of Language codes:

Codescript
enEnglish
hiDevanagari (Kept to support translations to Hindi at a later point of time)
bnBengali
guGujarati
knKannada
mlMalayalam
orOriya
paPunjabi
teTelugu
taTamizh (The transliterations will be lossful due to Tamil script not being elaborate enough to represent all sounds of Sanskrit)
mrMarathi (Kept to support translations to Marathi at a later point of time)

Example:

@TatKimBot ml
And the bot responds in 15 seconds as in the below screenshot:

Archives of the transliterations

The archives of the transliterations done by Tat Kim Bot will be available at the web portal https://tat.kim

(A sample screenshot below)

Look forward to people finding and using it during the next few months!

Migrate data from one Cassandra server to another using medusa

Here are the steps I followed to get my dev instance of cassandra copied to a new server (both single node instances)

I’ve used medusa tool for the same. You can read more about it here

Installation

Install medusa on both source and destination cassandra-servers, by running the following commands on both –

curl -1sLf   'https://dl.cloudsmith.io/public/thelastpickle/medusa/setup.deb.sh'   | sudo -E bash

sudo apt update
sudo apt-get install cassandra-medusa

Export Data from Source DB

#ssh into source server and do these

mkdir ~/cassandra-bkup
sudo cp /etc/medusa/medusa-example.ini /etc/medusa/medusa.ini
sudo vi /etc/medusa/medusa.ini

# Search for, and set these values in the ini file
storage_provider = local
base_path = /home/{username}/cassandra-bkup
# Save and Exit

medusa backup --backup-name=dev-db-data --mode=full

#compress output folder
tar -czf dev-db-bkup-tar ~/cassandra-bkup

# SCP the backup directory to destination server
scp -r -i <key-file> dev-deb-bkup-tar {dest-user}@{dest-server}:~/

Import data in Target DB

# ssh into target serer and do these
tar -xzf dev-deb-bkup-tar

ls ls /home/{username}/cassandra-bkup/cassandra_backups/
#note down the folder name parallel to the folder index, let it be {sourceHostLocalName}
sudo /etc/hosts
#add an entry with local nodes IP and host name as {sourceHostLocalName}. 
#You can remove this later
# save /etc/hosts and Exit Vim.
sudo medusa restore-node --keyspace={keyspace of intereset} --backup-name=dev-db-data

Verify Imported data

cqlsh {targetNodeIp}
desc keyspaces #verify you have the source keyspace created
use {keyspaceOfInterest}
desc tables; #verify all your tables in the source are recreated here.

That’s it. You should now be able to work with your new Cassandra node!