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