Tuesday, June 16, 2020

AWS pem file "permission too open" error on Windows

Go to the file directory and issue this command

$path = ".\thewowbuys_aws_server.pem"
# Reset to remove explicit permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r

Sunday, May 24, 2020

AWS XAMPP Virtual Host configuration

First need to make sure AWS instance is up and running. Then need to assign an elastic IP to the Instance. Because of this elastic IP, services can access the instance directly.

First, need to edit httpd.conf

Sudo vi /opt/lampp/etc/httpd.conf

Around line 487 need to remove the comment and allow httpd-vhosts.conf

# Virtual hosts
Include etc/extra/httpd-vhosts.conf

Then need to create a custom domain in the hosts file.

sudo vi /etc/hosts

127.0.0.1 localhost
127.0.0.5 kingalawaka.com <new line >
#don't touch other existent values
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

This file is used to locate the host.

Then need to create vitual host

sudo vi /opt/lampp/etc/extra/httpd-vhosts.conf

file should look like this

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/opt/lampp/htdocs"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    <Directory "/opt/lampp/htdocs">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin 123pasindumanisha@gmail.com
    DocumentRoot "/opt/lampp/htdocs/mysite"
    ServerName kingalawaka.com
    ServerAlias www.kingalawaka.com
    DirectoryIndex index.html
    <Directory "/opt/lampp/htdocs/mysite">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>
</virtualHost>

After saving the file

sudo /opt/lampp/lampp restart

if in case Apache service not stopped

sudo netstat -nap | grep :80

this will list down all the processes using port 80. Then from that, using process ID can kill the process.

sudo kill 980

then try to restart the lampp server.

Thursday, March 29, 2018

Open-CV migrating from Windows(Visual Studio) to Ubuntu

Depends on the scenario, it may be required you to change the development environment. After the change, the system never is expected to execute the code smoothly. for this errors, sometimes no errors in the compilation and when you run its simply exit no output will be visible.  I faced this issue and this is my findings of this problem. 


  • Case sensitiveness, if your images have .jpg and in your code, you mentioned as .JPG this may throw and assertation error. In some cases, it's not. Check carefully the case of your code. Linux is case sensitive. 
  • Never called executable code (method calling) outside the main method or any other method. 
This code segment is in outside the main method and not belong to any other method. This is more like a global declaration so I don't need to pass parameters to methods. This is going to fail in Linux environment. this should be inside a method.

This is Linux, and I insert that code segment inside the main method and worked fine. 
I don't know to explain why it's not working but I believe visual studio going to handle lots of things for us. But g++ compiler cant.

  • Always use pass by reference for parameter passing because then we can update the same variable.  
This is it for now and I will update this article with other problems I faced in future. 

Thursday, March 22, 2018

Install drivers in ubuntu using command line

First, you need to get superuser permission.
sudo passwd root
this will prompt you to enter your normal login password

then the system will ask for new set of the password to assign as the sudo password.
Done...

In order to install wifi drivers type, this commands.

this will prompt all the required drivers' list.

sudo ubuntu-drivers list
Will show all the driver packages which apply to your current system. You can then
sudo ubuntu-drivers autoinstall 
to install all the packages you need, or you can do:
sudo ubuntu-drivers devices
to show you which devices need drivers and their corresponding package names.
after identifying the required drivers you can issue the 
sudo apt-get install <driver name>
This will do the trick. Enjoy.

Tuesday, December 12, 2017

Install Packages in Anaconda

Power up the Anaconda prompt with Administrator privileges.

Activate the environment you need to install the package.

activate <your environment name>

then check in the anaconda repo that package is available or not

https://anaconda.org/anaconda/repo

most of the cases you can find the package and on that page, it will mention what is the command that you need to use to install. 

conda install --channel "anaconda" package

cheers enjoy ;)

Saturday, October 7, 2017

Anconda Basics (Tensorflow keras installation in Windows)

Data science is one of the biggest buzz word in tech arena. "Tensorflow" is getting lots of interest and lots of people talking about it. This is simple stepping stone for your data science world exploration. 

First download the Anaconda 
https://www.anaconda.com/download/

select what ever the platform you like to get your hands dirty. 

open Anaconda prompt  as Administrator.


By default there is only one environment is created. "root". Anaconda allows us to create multiple environments with different python or R versions. That is one of the reasons Anaconda is being popular. 

put following command to create a new environment 

conda create -n testing python=3.5



This will install bunch of packages and python as we specified. When I am writing this Tensorflor has some problems with python 3.6 so better to install 3.5. after installation you will get some help about how to activate and deactivate environments. 


There are two ways of installing packages in Anaconda. first method is using command prompt and other one is Anaconda Navigator. 

Open Anaconda Navigator as administrator.


hit refresh button to see whether our newly created environment is created or not. 


select our newly created environment and click Environments in left hand side panel. 




Then you can see all the installed packages in that environment. select "All" from the drop down and search whatever the package that you want to install. 

Installing Tensorflow 

search Tensorflow in the search box. In this particular case Tensorflow have that green check box. That means that, Tensorflow is already installed in the environment. 













 search Tensorflow package and click Tensorflow. This will be indicated by little down side arrow.


click apply button at the bottom of the window. this will install all the required things for Tensorflow.

Testing Tensorflow

In Anaconda there are many editor options. "Spider" is one of the main editors in Anaconda. press install and then you can launch "Spider" by Anaconda.


type following command to test Tensorflow


import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

if you get the print statement. You are successfully install Tensorflow.  


Install Keras

Since we did Tensorflow installation in Anaconda Navigator, lets install Keras using command prompt. 

first run the Anaconda prompt as administrator and activate the environment. Otherwise it will installed in root environment. 


activate testing
 conda install mingw libpython


 conda install theano

 conda install --channel https://conda.anaconda.org/conda-forge keras

if you didn't get any errors you are good to go. 
open the spider editor and issue following command.


import tensorflow as tf
from keras import backend
print(backend._BACKEND)
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))


or you can use command prompt to test keras. 


python -c "from keras import backend; print(backend._BACKEND)"


Done ;) enjoy 

Tuesday, September 19, 2017

Visual Studio Not starting correctly

If you experience visual studio is not loading correctly and notify you about a package installation error or package load error

Please open an administrative CMD window and navigate to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE and run these commands:

1.devenv.exe  /safemode

2.devenv.exe  /resetskippkgs

3.devenv.exe  /installvstemplates

4.devenv.exe  /resetsettings

5.devenv.exe  /resetuserdata

these commands are not related to each other so you can issue one command and check is the problem is solved or not. For my case

devenv.exe  /resetuserdata  This command restart the whole visual studio environment and you need to login to the developer account.

Reference :
link

Sunday, February 28, 2016

Apache Virtual host for hosting a website

First you need to install the Apache server in your server.

Then navigate to /var/www folder and create 

sudo mkdir -p /var/www/example.com/

This will create a folder for our site example.com. Next we have to grant the permission to created folder.

sudo chown -R $USER:$USER /var/www/example.com/
sudo chmod -R 755 /var/www

Then we need to put our website files in that created example.com folder. After that we need to create a configuration file for that. 

sudo cp /etc/apache2/sites-available/000-default.conf   /etc/apache2/sites-available/example.com.conf

Inside the cofiguration file we need to create something like this. 

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Some of the parts may already created so you don't need to create everything. Just make sure you will have a configuration file like this. 

To enable the created configuration file you need to enter following command.

sudo a2ensite example.com.conf

After that you need to enter this command to activate.

sudo service apache2 restart

Wednesday, February 24, 2016

Read File as a Stream and Lookup for some Data and Write the Results to a file.

This topic may feel bit difficult to understand. Following diagram will help to understand the concept behind this project.

Using a simple java application continuous file write program is executing. This will act like a continuous data stream to the flink. Lookup file contain some data that we need to check are there any matching records in both files and those records to be written to the output file.

In this scenario first we will look into the source code of continuous file write application. This application is writes some data to this file in every second.

This is the complete java program code.





import java.io.File;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;




/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
   new Timer().scheduleAtFixedRate(new TimerTask()
   {
       public void run()
       {
        try
        {
         long Mobilenumber = (long) Math.floor(Math.random()*9000000000L) + 1000000000L;
         int cellID = (int) Math.floor(Math.random()*99)+10;
         
         File file = new File("/home/hadoop/lookup_example/data.txt");
         FileWriter outFile = new FileWriter(file,true);
      
      final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
      final Date date = new Date();
         PrintWriter out = new PrintWriter(outFile);
         
            out.println(Mobilenumber+"\t"+cellID);//+"\t"+(dateFormat.format(date)));
            out.close();
            
            if(Mobilenumber>5000000000L && Mobilenumber<6000000000L)
            {
             File lookupFile = new File("/home/hadoop/lookup_example/lookupfile.txt");
             FileWriter lookupOutFile = new FileWriter(lookupFile,true);
       
          PrintWriter lookupOut = new PrintWriter(lookupOutFile);
          
          lookupOut.println(Mobilenumber);
          lookupOut.close();
             
            }
        }
        catch(Exception e)
     {
      
     }    
       }
   },new Date(), 1000);   
    }   
    
}
In this program write data to data.txt and lookupfile.txt data.txt file is the file that contain our main data stream while lookupfile.txt will update time to time when a value go beyond the specified limit because we need some data in the lookup.txt file as well.

Next we will move to flink project.
To create a flink project using command line just type the following code. 

mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=0.10.1

This also prompt you those groupId and artifactId parameters to fill. After Successful project creation build a program like this.


import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.functions.KeySelector;

import java.util.concurrent.TimeUnit;

import javax.xml.soap.Node;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.FlatJoinFunction;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.JoinFunction;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.IterativeStream;
import org.apache.flink.streaming.api.datastream.JoinedStreams;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileMonitoringFunction.WatchType;
import org.apache.flink.streaming.api.windowing.assigners.TumblingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.types.Key;
import org.apache.flink.util.Collector;

import pacl.WordCount.LineSplitter;

class class1 {
 String val1;
 String val2;
 
 class1(String v1,String v2)
 {
  val1=v1;
  val2=v2;
 }
}

class class2{
 String val1;
 String val2;
 
 class2(String v1,String v2)
 {
  val1=v1;
  val2=v2;
 }
 
 public String toString()
 {
  return val1+","+val2;
 }
}

class MyKeySelector implements KeySelector{

 @Override
 public String getKey(class2 arg0) throws Exception {
  // TODO Auto-generated method stub
  return arg0.val1;
 }
 
 
 
}

class MyKeySelector2 implements KeySelector{

 @Override
 public String getKey(class1 arg0) throws Exception {
  // TODO Auto-generated method stub
  return arg0.val1;
 }
 
}

public class lookup {
 
 public static void main(String[] args) throws Exception {

  StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  
  DataStream lookupData = env
    .readFileStream("/home/hadoop/lookup_example/lookupfile.txt",1000,WatchType.PROCESS_ONLY_APPENDED)
    .flatMap(new SplitterLookup());
  
  lookupData.writeAsText("/home/hadoop/lookup_example/out_1.txt",FileSystem.WriteMode.OVERWRITE);
  
  DataStream dataStream = env
    .readFileStream("/home/hadoop/lookup_example/data.txt",1000,WatchType.PROCESS_ONLY_APPENDED)
    .flatMap(new Splitter());
  
  DataStream d1 = 
    dataStream.join(lookupData).where(new MyKeySelector()).
    equalTo(new MyKeySelector2())
    .window(TumblingTimeWindows.of(Time.of(1, TimeUnit.SECONDS)))
    .apply(new MyFlatJoinFunction());
 
  d1.writeAsText("/home/hadoop/lookup_example/out.txt",FileSystem.WriteMode.OVERWRITE);
  env.execute("Window Wordcount");
 }
 
 public static class MyFlatJoinFunction implements JoinFunction{
  
  public void join(class2 arg0, class1 arg1, Collector arg2) throws Exception {
   // TODO Auto-generated method stub
   arg2.collect(arg0.val1+","+arg0.val2+","+arg1.val1+","+arg1.val2);
  }

  @Override
  public String join(class2 arg0, class1 arg1) throws Exception {
   // TODO Auto-generated method stub
   return arg0.val1+","+arg0.val2+","+arg1.val1+","+arg1.val2;
  }
 }
 
 public static class SplitterLookup implements FlatMapFunction{
  
  @Override
  public void flatMap(String sentence,Collector out) throws Exception{
   for (String word: sentence.split(" ")){
    out.collect(new class1(word," "));
   }
  }
 }
 
 public static class Splitter implements FlatMapFunction{
  
  @Override
  public void flatMap(String sentence, Collector out) throws Exception{
    String[] values = sentence.split("\t");
     out.collect(new class2(values[0],values[1]));
  }
 }
}
    In main Flink documentation there is mention normal flat file can be used in DataStreams but that is not correct. you have to use readFileStream in order to achieve continuous read from the file.


  • It is advisable to create a classes to store the file read outcomes. This will also give easy access the values.
  • You need to create keySelector that will use to match two keys together and decide both are same and write to the file.
  • Also need to use a window to aggregate data together and process.
  • Tuesday, February 23, 2016

    Flink installation

    Download the flink files (http://www.apache.org/dyn/closer.cgi/flink/flink-0.8.1/flink-0.8.1-bin-hadoop1.tgz) to the local home directory and assign the /bin path in .bashrc file. 

    $ tar xzf flink-*.tgz   # Unpack the downloaded archive
    $ cd flink-0.8.1
    $ bin/start-local.sh    # Start Flink

    Check the JobManager’s web front end at http://localhost:8081 and make sure everything is up and running.

    That's it.

    To run  check flink we can use the wordcount example. 

    Download test data:

    $ wget -O hamlet.txt http://www.gutenberg.org/cache/epub/1787/pg1787.txt

    You now have a text file called hamlet.txt in your working directory.
    Start the example program:

    $ bin/flink run ./examples/flink-java-examples-0.8.1-WordCount.jar file://`pwd`/hamlet.txt file://`pwd`/wordcount-result.txt

    You will find a file called wordcount-result.txt in your current directory.

    no you have the working copy of flink in your local machine. 


    Creating a Java project using maven using command line

    First you need to have a install and properly configured maven instance. To check your installation copy issue this command  and check you are getting proper version details. 

    mvn -version

    if you are having difficulties in this please go through the steps mention in this link.

    http://kingalawakatech.blogspot.com/2016/02/install-maven-in-cent-os.html

    If all sounds great then we can jump in to creation of a project. 

    Type following command to get started the project creation. Please make sure that you connected to the internet because in this maven project creation sometimes need to download some files from the internet. 

    Before creating a project navigate to the location that you want to create this project.


    mvn archetype:generate

    This will prompt the type of projects that you can build from the maven and then you can select the number appropriate to your requirement. Then it will begin the project creation. In this creation process you will be asking for enter some details of the project. Such as group Id, artifact Id etc. This is a  small explanation about those parameters.

    groupId : ID of the project group. (com.company.app)
    artifactId : project name (myApp)
    version : version of the project. (1.0)
    package : this is the typical java package. please avoid keywords in this.

    after giving those values you can successfully create new java project.

    To clean the maven project you can use
    maven clean 

    To Build the project you can use 
    maven package   

    Install Maven in Cent OS

    First of all you need to download the latest version of maven. For this requirement you can follow this link. 

    http://mirrors.gigenet.com/apache/maven/maven-3/

    Select the appropriate version that you want to use. Please make sure you download it to your local home directory to avoid unnecessary permission issues.  

    tar -zxvf apache-maven-3.2.3-bin.tar.gz 
    cd <location that you extract the zip file>
    sudo ln -s apache-maven-3.2.3 maven

    The next step is to setup the Maven environment variables in a shared profile so all users on the system will get them import at login time.

    su -c "vi /etc/profile.d/maven.sh"

    # Add the following lines to maven.sh
    export M2_HOME=/usr/local/maven
    export M2=$M2_HOME/bin
    PATH=$M2:$PATH

    you also need to edit your .bashrc file and add environmental variables. Then issue 

    source .bashrc 

    command to get effected the changes.

    Then issue following command to check whether you have install the maven correctly.

    mvn -version

    Analyse Tweets using Flume, Hadoop and Hive

    This is a great tutorial for work with all these new technologies. Please follow the link bellow to get hands on experience in this area.

    And before this step you also need to create a directory in HDFS. You can use Linux file system commands in HDFS. For that this tutorial will be helpful. 

    http://hortonworks.com/hadoop-tutorial/using-commandline-manage-files-hdfs/

    This is the tutorial that you need to follow to experience real data from Tweeter . 

    http://www.thecloudavenue.com/2013/03/analyse-tweets-using-flume-hadoop-and.html

    When you creating this conf/flume.conf file please make sure no space between left and right hand values. 
    e.g : 

    //this will not worked
    TwitterAgent.sources = Twitter
    TwitterAgent.channels = MemChannel
    TwitterAgent.sinks = HDFS

    //this is the correct format
    TwitterAgent.sources=Twitter
    TwitterAgent.channels=MemChannel
    TwitterAgent.sinks=HDFS


    Install Hive on Cent OS

    Please use directory in your home directory because sometimes you may feel some issues regarding permission. 

    This is the link that i used for this installation and this works fine for me. Please ask any question that you may come across.

    Hadoop Intallation on Cent OS

    This is a really easy task but you should be careful. I will post the link to the tutorial that i followed to installed. 

    1. Put your all files inside of a folder in your home directory. In some tutorials they put those files in /usr and other locations. This will be a problem sometimes because of insufficient permission to execution. 
    2. Please make sure that you properly done that ssh key generation part because it is really needed when it comes to working with hadoop. That ssh key procedure will allows to login to localhost with out authentication. you can check this ssh key task is properly effected by issuing 
              ssh localhost
              this will prompt last time you log successfully.

          This is the tutorial that i followed and if you have any question please post here. 

    http://tecadmin.net/setup-hadoop-2-4-single-node-cluster-on-linux/

    Thanks.