Saturday, December 5, 2015

Windows + Ubuntu dual boot : boot loader problem

After trying to uncover my newly installed ubuntu as dual boot with a previous windows installation without much success I finally came to this easy and simple solution.
With boot-repair ou can quickly restore your newly installed linux os by typing the following commands...:
  1. Boot from your live CD/ Bootable USB and choose the option try ubuntu.
  2. CTRL + ALT+ T to open a new terminal
  3. $ sudo add-apt-repository ppa:yannubuntu/boot-repair
  4. $ sudo apt-get update
  5. $ sudo apt-get install boot-repair
  6. Run boot-repair from your system or just type boot-repair from your terminal
  7. On start select  Recommended Repair , then follow up ...
  8.  Soon on restart you will be presented with your grub menu...
  9.  That is all
Enjoy it !

Should I install Mpi on virtualbox ?

The objective of this post is not to claim that it is not possible to run open mpi on virtualbox. But I intend to warning of the potential challenges that are awaiting for you when you opt for running open mpi on virtualization especially virtualbox.
I have just wasted  some times trying to make work. Even when it works you have a limited of processors of course depending on your hardware specification. In my case I was running a 32-bit ubuntu 14 installed on a HP laptop icore 5 . and I have at most 4 processors with only 2 usable. Everything was just a nightmare.... so many other issues came up.
 If you don't have enough time and have a serious application to be developped with open mpi please you are warned don't opt for virtualbox especially if you have a normal standart hardware.
  Feel free to share your experience with us. 
 

Wednesday, October 28, 2015

Cygwin Terminal Clear Screen Command

Are you working with Cygwin and wondering how you can clear your terminal's screen ?
No need to install any extra packages , the following keys combination will do the job.

  1.  Ctrl + L
  2.  ALT + F8

Have Fun !

Wednesday, October 21, 2015

How to change drive in cygwin ?

You have installed Cygwin in your windows OS. now you want to access other drives like "E:" from your terminal. How to achieve this ?
Use CYGDRIVE   as follows:
>  cd  /cygdrive/e/.

Install a new package after Cygwin installation

Have you installed Cygwin and  looking for how to install extra packages without using the setup again ? Then it is possible and apt-cyg is your friend :).
How ?
Yes in fact this package is similar to the apt-get you have in linux .
Just launch your cygwin terminal and fire the following command.

lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin/
apt-cyg install bc

I found these commands very helpful and all prizes go to Knorv from stackexchange.
Then have fun !!!

Sunday, September 13, 2015

Android reload database on resume or restart.

This scenario happens when , say we have two activities A and B.
From A we go to B and update the database. Then when we comeback at A
we notice that the A is not updated.
We have to implement the OnRestart in A, so that when the BACK button is pressed our
database is reloaded.

      @Override
    public void onRestart()
    {
        super.onRestart();
        finish();
        startActivity(getIntent());
    }

  


You can also try OnResume too



     @Override
    public void onResume() {
        super.onResume();  // Always call the superclass method first
        finish();
        startActivity(getIntent());

    }

  

This is just a trick, hope it paved your way out. 

Wednesday, September 9, 2015

Modulo Operator in Structured Text

 If you are reading this post, I am sure that you have other programming language background and have to fire the %  operator in your IF ELSE condition.
 But rather the equivalent operator for structured text you should use is MOD operator.
So instead of writing
 IF ( ( myVar % 10 ) == 0 ) THEN

 You should

IF ( ( myVar MOD 10 ) = 0 ) THEN

I hope that you are going to continue peaceful your journey to your project in automation.

Happy coding day !!

 

Wednesday, September 2, 2015

First PLC experience of a Computer Science Student

It has been a couple of months that I have been involved in PLC. I am computer science graduate used to mainly Soft-Programming. So far I have done essentially high level programming with languages such as java, C/C++ , PHP, Python and more.
After many hesitations I have decided to take an offer involving Hardware programming.
It has been my first time dealing with this complex type of programming. I have been really surprised by lack of documentation online on this important area of industrial automation. The few I even got were not free. If you are reading this post I am sure that you faced a similar scenario.  My intention starting this series of posts is to share with you whatever experiences and resources I assume useful, therefore giving back my contributions to this evolving community. I will be glad to know that whatever I share here is useful to my readers. The next post is coming soon, please feel free to drop a line of comment.

Saturday, May 16, 2015

Exam registration system on Java MVC pattern

I recently played around the mvc pattern in Java 8. I have implemented a small exam registration system having two views : student and teacher views. It detects duplicate registration and check that the student ID is in the form xxxxyyyy where x = letter and y= digit.
Here is a package diagram with calculated instability.

Here are some views:
CONTROL PANEL:

STUDENT:

TEACHER:

Source Code:
Project structure:


Registration


        package registration;

import controller.Controller;
import view.CPanelUI;

public class Registration {
    public static void main(String[] args) {
       
       Registration registration = new Registration(); 
        
    }
    //Main Frame call
    public Registration(){
       new CPanelUI( new Controller().getListOfIds()).setVisible(true);
    }
}

  

Exam


       package model;

import java.util.ArrayList;

public class Exam {
    
    //Students list declaration
   private  ArrayList  students = new ArrayList(); 
  
   // Adding an id to the list
   public void addStudent(String id){
       students.add(id);
   }
   
   //Returning the list of students IDs
   public ArrayList getStudents(){
       return students;
   }
   
   //Setting the list of students IDs
   public void setStudents(ArrayList  students){
       this.students=students;
   }
   
}

  
Controller

      
package controller;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import model.Exam;

public class Controller {
    Exam exam = new Exam();
     
    
    public Controller(){
             
    }
    
    public void setList(ArrayList list){
        exam.setStudents(list);
    }
    public ArrayList getListOfIds(){
        return exam.getStudents();
    }
    
    public void register(String id){
        
       //Checking ID format
           if(checkIdFormat(id)==false){
             JOptionPane.showMessageDialog(null, "INVALID ID FORMAT");
           }
           else{
              
               //Checking ID Duplication
              if(checkIdDuplicate(getListOfIds(),id)==true){
                JOptionPane.showMessageDialog(null, "ID DUPLICATED");
              }
              else{
                  //Adding new id to the list
                   exam.addStudent(id);
                   JOptionPane.showMessageDialog(null, id+ " successfully registered for the exam !");
               }
                
           }         

    }
    
    
    public boolean checkIdFormat(String id){
     //Check if the ID contains 4 letters followed by 4 digits
       if(id.matches("^[a-zA-Z]{4}[0-9]{4}$")) {
           return true;
        } else {
           return false;
        }
    }
    
    
    public boolean checkIdDuplicate(ArrayList list, String id){
        // check whether the id exists in the list or not
        if(list.indexOf(id)==-1){
            return false;
        }else{
            return true;
        }
    }
}

  


CPanelUI

      
   package view;

import java.awt.FlowLayout;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class CPanelUI extends JFrame{
    private final JLabel lblTitle = new JLabel("Teacher UI");
    private final JButton btnStudent = new JButton("Student");
    private final JButton btnTeacher = new JButton("Teacher");
       
    public CPanelUI (ArrayList list){
        setSize(300,300);
        setLayout(new FlowLayout());
        setTitle("Control Panel UI");
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(lblTitle);
        panel.add(btnStudent);
        panel.add(btnTeacher);
        add(panel);
 
        btnStudent.addActionListener(
          ev->{
           dispose();
           new StudentUI(list).setVisible(true);
          }
        );
        
        btnTeacher.addActionListener(
         ev -> {
          dispose();
          new TeacherUI(list).setVisible(true);
         
         }
        );
         //uses the default look and feel specified by windows themes
        setDefaultLookAndFeelDecorated(true);
        //centered the window position
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
    }
    
}

  

StudentUI

      
   package view;

import controller.Controller;
import java.awt.FlowLayout;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class StudentUI extends JFrame {
    private final JLabel lblId = new JLabel("Enter your ID (4 letters and 4 digits): ");
    private JTextField txtId = new JTextField(10);
    private final JButton btnId= new JButton("Submit ID");
    Controller controller = new Controller();
    public StudentUI (ArrayList list){
        //setVisible(true);
        setSize(300,300);
        setLayout(new FlowLayout());
        setTitle("Student UI");
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(lblId);
        panel.add(txtId);
        panel.add(btnId);
        add(panel);
        btnId.addActionListener(
         ev -> {
           String id = txtId.getText();
           controller.setList(list);
           controller.register(id);
           dispose();
           new CPanelUI(list).setVisible(true);
           }
        );
        //uses the default look and feel specified by windows themes
        setDefaultLookAndFeelDecorated(true);
        //centered the window position
        setLocationRelativeTo(null);
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
}
  


TeacherUI

   
   package view;

import java.awt.FlowLayout;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class TeacherUI extends JFrame{
    private final JLabel lblTitle = new JLabel("Teacher UI");
    private final JButton btnBack = new JButton("Back");
    private final JList listIds ;
    //passing model to UI
    public TeacherUI(ArrayList list){
        listIds = new JList(list.toArray());
        setSize(300,300);
        setLayout(new FlowLayout());
        setTitle("Student UI");
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(lblTitle);
        panel.add(new JScrollPane(listIds));
        panel.add(btnBack);
        add(panel);
        listIds.setFixedCellWidth(300);
         btnBack.addActionListener(
         ev -> {
             setVisible(false);
             new CPanelUI(list).setVisible(true);
           }
        );
         //uses the default look and feel specified by windows themes
        setDefaultLookAndFeelDecorated(true);
        //centered the window position
        setLocationRelativeTo(null);
    } 
}
  


Althought this system is working properly and following all the stable dependencies principles, we to add an observer pattern between views and the model to make it more scalable. And that is the next thing I will add to this system. Stay tuned. Feel free to drop your comments...

Note: This is project built on Java 8

inner class initialization and instantiation in C++/CPP

The following snippet shows you how to handle inner class in C++, especially the initialization and the instantiation.  It is important to note that the public inner class members are accessible outside the outer class while the private inner class members are accessible only inside the outer class. Please have a look at the code !


Hope you enjoy it !

Monday, May 11, 2015

Cool tools for UML diagrams drawing for java, cpp and others.

Hi,
Recently I have come across the following tools for drawing different UML diagrams. If you are using OOP like Java , CPP and others then these free tools are suitable for you.
  1. VISUAL PARADIAGM
  2. MODELIO
  3.  ???
This list is not exhaustive please I have USED any such tool please share your experience with us.

String length with Regular Expression in Java

Here is an example of strings manipulation in Java using regular expression.
Have a look at the following line and have fun.




Hope you enjoy it.

Thursday, February 19, 2015

What is JSON ?

JSON stands for Javascript Object Notation.
Some descriptions are:

  • Format for sharing data
  • Derived from Javascript
  • Language independent (Originated with Js but availabe in many other language like PHP, C, Pearl, python)
  • An alternative to XML

Advantages:
  •  Leaner than XML
  • Easy to read
  •  Growing support in APIs
  • Natural format for Javascript
  • Implementation in many languages

Wednesday, January 14, 2015

Add a CSS file in Intrexx

As you already know you can directly write your CSS code in intrexx without any issue. But if  you have, say a third-party CSS library or a CSS file that you want to add in intrexx you need to be aware of the following fact:
  1. Put a copy of your CSS file preferably in this directory or any other location:  \org\yourPortalName\external\htmlroot\include\custom\
  2. Open the following CSS file (\org\deinportal\external\htmlroot\include\custom\custom.js) and add the following:  
    Loader.loadCssFilesOnDemand('yourCssFile.css');
  3. Save everything and reload  your application
Enjoy it.

adding jquery plugin in intrexx

As you already know you can directly write your javascript code in intrexx without any issue. But if  you have say a third-party javascript library or a jquery plugin that you want to add in intrexx you need to be aware of the following fact:
  1. Put a copy of your plugin in this directory:  \org\yourPortalName\external\htmlroot\include\custom\
  2. Open the following js file (\org\deinportal\external\htmlroot\include\custom\custom.js) and add the following:  Loader.loadJsFileOnDemand("include/custom/yourScriptName.js");
  3. Save everything and reload  your application
Enjoy it.

Friday, January 2, 2015

jquery NaN error

I have just written a small script today with jquery and come across this small error message.
inital code:

var1 += parseInt($(this).html());
var2 = parseFloat(age);

Solution

    var1 += parseInt( $(this).text(), 10 ) || 0;
  var2 = parseFloat(age) || 0;
 
Hope it helps.