Tuesday, April 30, 2019

isPalindrome Implementation in Scala

The palindrome function will check the Given Number/ String is Palindrome or In case of List of Items It will test individual items in list can contribute to a Palindrome or Not.

def isPalindrome[A](item:A):Boolean = item match {
  case head :: Nil => isPalindrome(head)
  case ls:List[A] => ls.head == ls.last &&  isPalindrome(ls.drop(1).dropRight(1))// Checks the Head and Tail, and recursively check for the remaining
  case ls:String => ls.reverse == ls
  case e => e.toString.reverse == e.toString
}

println("IS Palindrome :"+isPalindrome(1234454321))  // Result false
println("IS Palindrome :"+isPalindrome(List(1,2,3,4,3,2,1)))  // Result true
println("IS Palindrome :"+isPalindrome("ABCDCBA"))  // Result true

Monday, April 22, 2019

Shortcut in Visual Code for ReactJs

1. Type rfc and press TAB key, It will create a Rect Functional Component skeleton

Example:
import React from 'react'

export default function Launch() {
return (
<div>
</div>
)
}

If you type rcf: the Auto suggestion will point to rfc ;)
2. Type rcc and press TAB key, It will create a Rect Class Component skeleton

import React, { Component } from 'react'

export default class Launch extends Component {
render() {
return (
<div>
</div>
)
}
}


Tuesday, April 9, 2019

How to run docker-compose in windows 10 Home - kitematic

As Windows-10 Home doesnt support Hyper-V, While running docker-compose in windows 10 Home, You cannot map the current directory in windows to the docker volume,

I did the following solution:

  1. Connect Kitematic VM using WinSCP
    1. IP Address : 192.168.99.100
    2. UserName: docker
    3. Password : tcuser
  2. Upload all files for the docker container to the VM
    1. Example /home/docker/nginx
  3. Map the Volume to the folder in docker-compose.yml [Where the docker-compose.yml is still in the Windows machine, while all the container file is uploaded to the Kitematic VM -192.168.99.100 ]

version: '3'

services:
proxy:
image: nginx:1.13 # this will use the latest version of 1.13.x
ports:
- '80:80' # expose 80 on host and sent to 80 in container
volumes:
- /home/docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
  1. From windows Command prompt run docker-compose up

The above steps helped to run docker-compose. 
If you have any other thoughts please share in comments.

Monday, April 8, 2019

Map windows directory to docker container in windows Kitematic

By default the directory mapped to docker container inside Kitematic will be mapped to VM of the kitematic, not the windows directory,

So the solution is as follows.

  1. Make a directory inside kitematic VM and map it.
  2. Map a Windows directory to the VM through VirtualBox manager and map to the docker.

Using localhost for to access running docker container in windows

In Windows, The docker is run through Kitematic which is basically a VM.

The VM will have an IP address associated with it, So to access from windows you need to specify the IP address of teh Kitematic VM IP instead of localhost for the deployed docker file access.

Refer : https://forums.docker.com/t/using-localhost-for-to-access-running-container/3148

Monday, March 18, 2019

Stack Implementation using Queue - Java Code

Get Implementation below:
     
import java.util.ArrayDeque;
import java.util.Queue;

public class StackUsingQueue {
 Queue q1=new ArrayDeque<>();
 Queue q2=new ArrayDeque<>();
 
 public void push(Integer item) {
  if(!q1.isEmpty())
   q1.add(item);
  else
   q2.add(item);
  System.out.println("PUSH "+item+": Q1: "+q1+"   Q2"+q2);
 }
 public void pop() {
  Integer item ;
  if(!q1.isEmpty()) {
   transfer(q1, q2);
   item = q1.poll();
  }else {
   transfer(q2, q1);
   item = q2.poll();
  }
  System.out.println("POP : Q1: "+q1+"   Q2"+q2+"  -  Poped Item:"+item);
 }
 
 private void transfer(Queue q1, Queue q2) {
  Integer size = q1.size();
  for(int i=0; i< size - 1; i++)
   q2.add(q1.poll());
 }
 public static void main(String[] args) {
  StackUsingQueue stack = new StackUsingQueue();
  stack.push(1);
  stack.push(2);
  stack.pop();
  stack.push(3);
  stack.push(4);
  stack.pop();
  stack.pop();
 }
  }

Result


PUSH 1: Q1: []   Q2[1]
PUSH 2: Q1: []   Q2[1, 2]
POP : Q1: [1]   Q2[]  -  Poped Item:2
PUSH 3: Q1: [1, 3]   Q2[]
PUSH 4: Q1: [1, 3, 4]   Q2[]
POP : Q1: []   Q2[1, 3]  -  Poped Item:4
POP : Q1: [1]   Q2[]  -  Poped Item:3


Wednesday, March 6, 2019

Why Crontab Scripts are not running ?

Sometimes The bash scripts runs good at the Terminal, But doesnt execute while running from cromtab.

I faced same issue with multiple commands chained in a crontab,

Solution: Issue behind the command is, while executing crontab everu command should have have the complete path.

You can find the command path as follows:
for example xargs

  • Execute "which xargs" which will give the complete path as /usr/bin/xargs
So I formated my cronjob as follows:

  • Before Path : 44 * * * * echo $(service MyService status | xargs -n 1 lsof -p | wc -l) 
  • After Path : 44 * * * * echo $(/sbin/service MyService status | /usr/bin/xargs -n 1 /usr/bin/lsof -p | /usr/bin/wc -l) 

Keep Exploring.......