Wednesday, December 7, 2022

Build settings - for React in Amplify

 version: 1

frontend:

  phases:

    preBuild:

      commands:

        - npm ci

    build:

      commands:

        - npm run build

  artifacts:

    # IMPORTANT - Please verify your build output directory

    baseDirectory: build

    files:

      - '**/*'

  cache:

    paths:

      - node_modules/**/*

Monday, December 5, 2022

React Native - Build Apk without metro

 To build APK without Metro server, use below command:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle 
--assets-dest android/app/src/main/res/

Do create folder: android/app/src/main/assets/index.android.bundle 

Thursday, December 1, 2022

Java annotations - Lombok

 Use Lombok to avoid boilerplate code:

https://projectlombok.org/


@Builder
@Data
@AllArgsConstructor
public class AddCouponRequest {

Saturday, November 19, 2022

Reactor Java - use of FlatMap

 TO convert stream of stream to only stream...use flatMap


Mono.zip().flatMap(s1->s1)

Tuesday, November 8, 2022

How to auto upgrade package.json dependency version

 

How to auto upgrade package.json dependency version

Use below trick:

Simply change every dependency's version to *, then run npm update --save

Friday, October 7, 2022

Starting multiple Byobu process through shell script

 How to Start multiple Byobu process through shell script:


Below is sample code:

byobu new-session -d -s "onreboot"

byobu new-window -t "onreboot":1 -n "web app" "sh ./webapp-build.sh" >/home/ubuntu/scripts/web_launch.log 2>&1

byobu new-window -t "onreboot":2 -n "api app" "sh ./api-build.sh" >/home/ubuntu/scripts/api_launch.log 2>&1

Wednesday, October 5, 2022

Text contrast checker tool

 Very useful tool for keeping right contrast in text:


https://dequeuniversity.com/rules/axe/4.4/color-contrast?utm_source=lighthouse&utm_medium=devtools

Sunday, August 7, 2022

Div Tag mapper tool

 Below is very good div tag mapper tool:

https://www.tormus.com/tools/div_checker#show_div_map

Wednesday, August 3, 2022

Spoken English Pages on Namaste English Website

 Dear Users,

   We have provided way to practice Spoken English via website now. You will get 73 days of English Conversations. This helps  in start talking in English. Similarly , four levels of daily life conversations (Starter, Basic, Intermediate and Advance) sentences are provided. 

For information , checkout our Spoken English page at Spoken English



Saturday, July 23, 2022

Example, Working with multiple Reactive MongoDB reactive having different Databases

 Sample code for: Working with multiple Reactive MongoDB reactive having different Databases


package com.hk.webapp.config;


import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;

import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;

import java.util.Collection;
import java.util.Collections;

@Configuration
@EnableReactiveMongoRepositories(basePackages = "com.xy.dao",reactiveMongoTemplateRef = "xdbReactiveMongoTemplate")
public class XDbConfig extends AbstractReactiveMongoConfiguration
{

@Value("${mongo.connection_uri}")
private String connectionUri;

private String dbName="x_db";

@Override
public MongoClient reactiveMongoClient() {
return MongoClients.create(connectionUri);
}

@Override
protected String getDatabaseName() {
return dbName;
}


@Bean(name="xdbReactiveMongoTemplate")
public ReactiveMongoTemplate xdbReactiveMongoTemplate()
{

return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
}
}

Friday, July 15, 2022

Responsive Youtube Embed Example

 Follow below example for Embedded youtube video:

<div style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"><iframe style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" title="YouTube video player" src="https://www.youtube.com/embed/Svxm-tBOI9s" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>

Sunday, July 3, 2022

Install Custom Maven version on Ubuntu

 Use below steps to install custom maven on Ubuntu:

wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P tmp


sudo tar xf tmp/apache-maven-*.tar.gz -C /opt

sudo ln -s /opt/apache-maven-3.6.3 /opt/maven

sudo nano /etc/profile.d/maven.sh

add below to maven.sh file

export JAVA_HOME=/usr/lib/jvm/default-java

export M2_HOME=/opt/maven

export MAVEN_HOME=/opt/maven

export PATH=${M2_HOME}/bin:${PATH}

sudo chmod +x /etc/profile.d/maven.sh

source /etc/profile.d/maven.sh

Saturday, June 4, 2022

Monday, May 30, 2022

How to create MS Word file using Java

Use Maven to add dependency:


  <dependency>

<groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency>


public class CreateDocumentSimple { public static void main(String[] args) throws IOException { String fileName = "c:\\test\\hello.docx"; try (XWPFDocument doc = new XWPFDocument()) { // create a paragraph XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); // set font XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setItalic(true); r1.setFontSize(22); r1.setFontFamily("New Roman"); r1.setText("I am first paragraph."); // save it to .docx file try (FileOutputStream out = new FileOutputStream(fileName)) { doc.write(out); } } } }

Tuesday, May 3, 2022

Javascript display Date with format

module.exports={
getDisplayDate,
}

function getDisplayDate(dateObj){
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
let monthNumber=dateObj.getMonth()
return dateObj.getDate()+"/"+months[monthNumber]+"/"+dateObj.getFullYear();
}

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options));

date. toLocaleDateString("en-US", options)



Option # 2

Use the date.format library:

var dateFormat = require('dateformat');
var now = new Date();
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");


Using Moment.js

var moment = require('moment'); // require
moment().format();

For Node.js


var format = require('date-format');
format.asString(); // defaults to ISO8601 format and current date
format.asString(new Date()); // defaults to ISO8601 format
format.asString('hh:mm:ss.SSS', new Date()); 

Sunday, May 1, 2022

getting started with PM2

a)  Install:

 sudo npm install pm2 -g

b) Start Node api in cluster mode

pm2 --name <apiname> start index.js -i 2

c) Save Pm2 job

pm2 save


d) auto start at reboot

pm2 startup


e) reload without downtime

pm2 reload all




Thursday, March 31, 2022

byobu launch on reboot

 byobu new-session -d -s "onreboot"

byobu new-window -t "onreboot" "sudo sh ./build.sh" >/home/ubuntu/logs/api_launch.log 2>&1


Better approach at:

https://bholameena.blogspot.com/2022/10/starting-multiple-byobu-process-through.html

Ubuntu - choosing among JAVA versions

 sudo update-alternatives --config java


JDK 8

apt install openjdk-8-jdk

Thursday, March 24, 2022

remove unused css in html

 This is very useful code to remove unused css in HTML


https://uncss-online.com/