Friday 10 July 2015

How to browse root user directories with nautilus file browser in Linux.

linux nautilus
If you are logged in with restricted permission you may be able to navigate to other directory through terminal switching to root, but without been logged in as root how can you browse windows directory of root and other users. It can simply be done with nautilus. Nautilus is a utility in Linux to browse your computer. 



Steps to browse other root and other user's directory.

1. Open terminal
2. Switch to root user (su -)
3. type nautilus -browser pathOfYourDesiredDirectory
    e.g. nautilus --browser /root/Documents/

Disadvantages of using nautilus.

You cannot browse network using nautilus browser.

Nautilus is mainly required when you need to access some important files / directories of other users, or need to open some file, which is always very tiresome from the command line. 

#linux #redhat #gnome #nautilus

Wednesday 8 July 2015

Add, Update, Delete Oracle data with AngularJS and JSP

angularjs jsp
In a few posts a few months back I have tried to retrieve data from Oracle database 12c through JSP and using $http.get retrieve that data to view in table format. Now what about inserting, updating or deleting data from oracle database. It's a wonder how much powerful angularjs is, data retrieving and page rendering is so fast. In the section below both the jsp code and angularjs code is provided. You can run the jsp file alone with parameters and see the result which is actually retrieved by $http.get.
All you need to do is create a table called emp with two fields emp_code and emp_name. And on the connection string change the hostname / ipaddress,

1. Table emp

   create table emp
   (
     emp_code number not null,
     emp_name varchar2(100) not null
   ); 

2. test.html

<html>
<script src= "
"http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="src/app.js">
</script>
<body ng-app="app">   <!-- ng-app on BODY scope -->
<div id="divCtrl" ng-controller="MyCtrl">  
<!-- ng-controller on div scope --> 

<!-- ng-model empCode and empName is used for http get and post -->

<input type="text" name="empCode" ng-model="empCode" value="" />
<input type="text" name="empName"  ng-model="empName" value="" /><br/>
 

<!-- Two buttons having ng-click each calling addData and updateData. updateData updates the record with emp_code value in where condition-->
 

<input type="button" value="Add" ng-click="addData()" /><br/>
<input type="button" value="Update" ng-click="updateData()" />
<table border=1>
<tr><th>Emp Code</th><th>Emp Name</th>
<tr ng-repeat="emp in empArr">


<!-- Remove eclosed in <a> tag having ng-click calling dalateData to delete the current row from the view as well from the database -->

 <td>{{emp.EMP_CODE}}</td><td>{{emp.EMP_NAME}}</td><td> 
<a href="" ng-click="deleteData(emp)">Remove</a></td>
</tr>
</table>
</div>
</body>
</html>


3. app.js 

  app = angular.module('app',[]);
  app.controller('MyCtrl',function($scope,$http) {
     refreshData();

/*     This function is called from ng-click in button "Add"  which adds data in table EMP and updates the view */
     $scope.addData = function() {
       $http.post("insertUpdateDelete.jsp?empCode=" + $scope.empCode + "&empName=" + 

         $scope.empName + "&dmlType=Ins")
        .success(function(response) {
             refreshData();
        });

/* dmlType checks the type of DML transaction to perform, this prevents from creating separate JSP files for insert, update and delete */
      }




/*     This function is called from ng-click in button "Update"  which updates data in table EMP and updates the view */     $scope.updateData = function() {
       $http.post("insertUpdateDelete.jsp?empCode=" + $scope.empCode + "&empName=" + 

       $scope.empName + "&dmlType=Upd")
        .success(function(response) {
           refreshData();
        });
     }




/*     This function is called from the link Remove in the third column of HTML table  which adds data in table EMP and updates the view */
     $scope.deleteData = function(curData) {
        $http.post("insertUpdateDelete.jsp?empCode=" + curData.EMP_CODE + 

         "&empName=" + curData.EMP_NAME + "&dmlType=Del")
        .success(function(response) {
               $scope.empArr.splice($scope.empArr.indexOf(curData),1);
                refreshData();
        });
     }



/*     This function gets fresh data from table  and updates the view */
/* get_oracle_data.jsp is explained in Oracle 12c data generator in JSON by dynamic sql using JSP */
      function refreshData() {
       $http.get("get_oracle_data.jsp?sqlStr=select * from emp")
       .success(function(response) {
          $scope.empArr = response;
        })
       .error(function(response) {
      alert("");
      $scope.empArr={};
       });
     }
  });


4. insertUpdateDelete.jsp
/* This section is not explained here check this url http://techgigsonline.blogspot.in/2015/01/oracle-12c-data-generator-in-json-by.html for jsp oracle tutorial*/
<%@ page import = "java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.1:1521:orcl", 

"username","password");
String dml_type = request.getParameter("dmlType");
String emp_code = request.getParameter("empCode");
String emp_name = request.getParameter("empName");
String sql="";
if("Ins".equals(dml_type))
  sql = "insert into emp values(" + emp_code + ",'" + emp_name + "')";
else if("Del".equals(dml_type))
  sql = "delete from emp where emp_code = " + emp_code + " and emp_name = '" + emp_name + "'";
else if("Upd".equals(dml_type))
  sql = "update emp set emp_name = '" + emp_name + "' where emp_code = " + emp_code;
out.println(dml_type);   
try
{
 Statement stmt = con.createStatement();
 stmt.executeQuery(sql);
}
catch(SQLException e)
{
 out.print("SQL Error encountered " + dml_type  + "," + e.getMessage());
}
con.close();
con=null;
%>


   

Tuesday 7 July 2015

Creating a Button toolbar with AngularJS

angularjs
I am working on a project where I have used one button toolbar.It is probably the simplest way I have created button toolbar. AngularJS made it simple. It's only JSON data and ngRepeat and my button toolbar is ready to work. I am sharing the code with you and will try to explain as much as I can. This project consists of three files.



1. Index.jsp
2. button.jsp
3. button.js
4. Menu.css

The original project is written on JSP with back-end database as Oracle 12c. All the dynamic page design is done with AngularJS and Ajax. Just check out the code below.

Index.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" charset=utf-8" />
<link rel="stylesheet" type="text/css" href="stylesheet/menu.css">
<link rel="stylesheet" type="text/css" href="stylesheet/main.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js">
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-route.min.js">
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-animate.js">
</script>
<script src="src/menu.js"></script> <!-- Menu.js contains the JSON data to build the toolbar -->
<title>ABC Industries Limited</title>
</head>
<body>
<div class="mainDiv" id="mainDiv">
<div width=80% id="divHeader" ng-controller="RouteController">
    <jsp:include page="button.jsp" /> <!-- This is the section where button.jsp is included -->
    <jsp:include page="menu.jsp" />
</div>
<div id="ngviewDiv" ng-view=""> <!-- This is where the invoked templated are embedded -->
</div>
<!--<img width=84% class="image1" src="Images/BACK.jpg" />-->
</div>
</body>
</html>


Button.jsp

<div class="mnuContainer">
<table id="btntable" width=40% height=20% border=1>
<tr id="mnuButton">
<td width=10% ng-repeat="bmenu in buttonMenu"><center><a href="" ng-click="buttonOption('{{bmenu.funcLink}}')"><img width=30% height=30% ng-src="{{bmenu.Link}}" class="btnsubmnu" /></a></center></td>
</tr></table>
</div>

Menu.js


myApp=angular.module('myApp',['ngRoute']);

myApp.controller('RouteController',function($scope,$http) {
/* I have not defined the linked function (funcLink) newRecord, deleteRecord, etc. for it will make the code to lengthy to understand. Button images is the directory where all the button images are located.*/

    $scope.buttonMenu=[
    {'Name':'New','Link':'Images/new.ico','funcLink':'newRecord'},
    {'Name':'Delete','Link':'Images/delete.ico','funcLink':'deleteRecord'},
    {'Name':'Query','Link':'Images/query.ICO','funcLink':'queryRecord'},
    {'Name':'Execute','Link':'Images/execute.ico','funcLink':'executeRecord'},
    {'Name':'First','Link':'Images/First.ICO','funcLink':'firstRecord'},
    {'Name':'Previous','Link':'Images/Prev.ICO','funcLink':'prevRecord'},
    {'Name':'Next','Link':'Images/Next.ICO','funcLink':'nextRecord'},
    {'Name':'Last','Link':'Images/Last.ICO','funcLink':'lastRecord'},
    {'Name':'Print','Link':'Images/print.ico','funcLink':'printRecord'}
    ];
});


Menu.css

div.btnDiv
{
padding:5px;
opacity:0.8;
box-shadow: 2px 2px 1px 2px #999;
background:white;
cursor:pointer;
cursor:hand;
border-radius: 5px;
width:60%;
height:60%;
}
img.imgsubmnu
{
width:100%;
height:100%;
}


   

Monday 6 July 2015

Changing background opacity of DOM Element dynamically with JQuery

jquery
Background opacity can be hard coded, but what about if you need to change the opacity dynamically!. JQuery makes your page more dynamic and interactive. In this section of code you can see how you can change the background opacity of a H1 element dynamically by changing the value in a combo list. Combo list consists of numbers from 0 to 100. 0 means fully transparent and 100 means fully opaque. Whenever you change the value opacity change. Try this code.

<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function() {

   /* select list is dynamically created within a div with classname divOption, to fill it up with 0 to 100 using loop */
   var s="<select id='pct'>";
   for(i=0;i<=100;i++)
     s+="<option value=" + i + ">" + i + "</option>";
   s+="</select>";
   $("div.divOption").html(s);
   $("#pct").val("100"); // Set the current value to 100 that means fully opaque

   /* Initially when loading opacity is set to 1 i.e. fully opaque */
   $("h1").css({"color":"00FF00","fontSize":"36px","background-color":"rgba(0,0,255,1)"});

   $("#pct").change(function() {
 /* Follow the calculation in the change event,
since our combo value is 0 to 100, we divide it by 100 to get the fractional value */
     $("h1").css({"background-color":"rgba(0,0,255," + $(this).val()*1.0/100 + ")"});
   });
});   
</script>
<title>
</title>
</head>
<body>
<div class="divOption"></div>
<h1>Hello Subhroneel</h1>
</ br>
</body>
</html>


     

Hello Subhroneel

</ br>

Sunday 5 July 2015

Order of parameters in controller and custom directive link function in AngularJS

Have you ever tried changing the order of parameters of AngularJS app controller or link function in Angularjs directive?. If you have done so you will find something important difference between the two. Controller callbacks parameters are strict naming convention. Although it does not depends on it's order but directive link function parameters are maintains order of the parameters though it does not maintain naming convention.

 
Suppose say we have this controller defined.

var app = angular.module('app',[]);

app.controller('MyCtrl',function($scope,$http) {

});

Now if you change the order like say
app.controller('MyCtrl',function($http, $scope) {

});

$http and $scope does not change there property. 

But now take one app directive link function say

A.
app.directive('panel',function(scope,element, attrs, ctrl, transclude) {
});

If you change the order like say

B.
app.directive('panel',function(element,scope, ctrl, attrs, transclude) {
});

Then here element meant to be scope, scope meant to be element, ctrl meant to be attrs and attrs 
meant to be ctrl. This means in case of directive link function order of argument is very important.
The order mentioned at below point A. is actually the order and if you change the names it will not change the order. You can even change there name then also it will retain the same order. You can 
write like this 

C.
app.directive('panel,function(a, b, c, d, e) {
});

Here a means scope, b means element, c means attrs, d means ctrl and e means transclude.


But in case of controller callback function name cannot be change so you can change the order.

But you can change the name or order in this case also for that you have to define your controller 
like this.

app.controller('MyCtrl',[$http,$scope, function($http, $scope) {
}]);

You can even change their name or to say put alias like this.

app.controller('MyCtrl',[$http,$scope, function(a, b) {
}]);

Here a means $http and b means $scope.

---------------------------------------------------------------------------------------------------------------------------

#angularjs #javascript #jquery #ajax #controller #directive

Saturday 4 July 2015

Basic calculator with AngularJS filter

www.angularjs.org/
Today I have been trying to build a calculator. No there is no buttons, but only Addition, Subtraction, Multiplication and Division. I have created 4 filters Add, Subtract, Multiply and Divide. I have used these filter in four different input box. Textbox  parse input in 

Addition : i.e. 5+4+2+8+3
Subtraction : i.e. 5-4-2-8-3
Multiplication : i.e. 5*4*2*8*3
Division : i.e. 5/4/2/8/3  -- this will return float value


<!DOCTYPE html>
<html>
<head>
    <title>Calculators with Filters </title>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('app',[]);
        app.controller('MyCtrl',function($scope){
      $scope.addTxt="1+4+5+6"
      $scope.subTxt="1-4-5-6"
      $scope.multTxt="1*4*5*6"
      $scope.divTxt="1/4/5/6"
        });

        app.filter('Add',function()
        {
            return function(text) {
                var arr = text.split("+");
                var result = 0;
                for(i=0;i<arr.length;i++)
                    result+=Number(arr[i]);
                return result;
            }
        });

        app.filter('Subtract',function()
        {
            return function(text) {
                var arr = text.split("-");
                var result = 0;
                for(i=0;i<arr.length;i++)
                    result-=Number(arr[i]);
                return result;
            }
        });

        app.filter('Multiply',function()
        {
            return function(text) {
                var arr = text.split("*");
                var result = 1;
                for(i=0;i<arr.length;i++)
                    result*=Number(arr[i]);
                return result;
            }
        });

        app.filter('Divide',function()
        {
            return function(text) {
                var arr = text.split("/");
                var result = 1.0;
                for(i=0;i<arr.length;i++)
                    if(Number(arr[i])>0)
                        result/=Number(arr[i]);
                return result;
            }
        });
    </script>
</head>
    <body>
        <div id="divApp" ng-app="app">
            <div ng-controller="MyCtrl">
                Addition : <input type="text" ng-model="addTxt" />
                Result : {{addTxt|Add}} <br />



                Subtraction : <input type="text" ng-model="subTxt" />
                Result : {{subTxt|Subtract}} <br />

                Addition : <input type="text" ng-model="multTxt" />
                Result : {{multTxt|Multiply}} <br />

                Addition : <input type="text" ng-model="divTxt" />
                Result : {{divTxt|Divide}} <br />
            </div>
        </div>
    </body>
</html>


#angularjs #javascript #js #jquery #ajax #customfilter

Using transclude in AngularJS.

angularjs
What happens when you put some content straight into your custom element (i.e. custom element name say panel and you put like this <panel>This is my content</panel> and when you define the directive in you script the content above in your html code is overwritten by the template value. So what can be done, angularjs provides a transclude option which lets you display the content along with the template. So I am writing a small program which let you gain a little concept about how you can retain your html content.
I have used transclude in two different  ways. In the first one I have used ng-transclude directive in a div and added it with existing template value. In the second option I have injected transclude, invoking it as a function which clones the html content value. With loop you can view the content multiple times. Only if you remove transclude:false then you can hide the content.


<!DOCTYPE html>
<html>
    <head>
        <title>Hell with this world</title>
        <meta charset="utf-8">
        <style type="text/css">
            h1.first
            {
                color:#FF0000;
            }
            h1.second
            {
                color:#0000FF;
            }
        </style>
        <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
        <script>
            var myApp = angular.module('myApp',[]);
            myApp.controller('MyCtrl',function($scope){

            });


            myApp.directive("panel1",function(){
                return {
                    restrict: "E",
                    transclude: true,
                    template: '<h1 class="second">This panel1 div meant to see if ng-transclude included... </h1><div ng-transclude></div>'               

                         }
            });

            myApp.directive("panel2",function(){
                return {
                    restrict: "E",
                    transclude: true,
                    template: '<h1 class="second">This panel2 div meant to see if ng-transclude included...</h1>',
                    link: function(scope, element, attrs, ctrl, transclude){
                        transclude(function(clone){
                            element.append(clone);
                        });
                    }
                }
            });
        </script>

    </head>
    <body>
    <div ng-app="myApp">
        <div ng-controller="MyCtrl">
            <panel1>   
                <h1 class="first"> This is in my first HTML section, cannot see if transclude is set to 

                 false!!!!
                </h1>
            </panel1>

            <panel2>   
                <h1 class="first"> This is in my second HTML section, cannot see if transclude is set to 

                 false!!!!
                </h1>
            </panel2>

        </div>
    </div>
    </body>
</html>


Youtube Tutorial

#AngularJS #mvc #javascript #googleapi #ngtransclude 

Friday 3 July 2015

Building custom filters in AngularJS

As working on AngularJS we are very accustomed with using filters. But generally the filters we used are in built filter like orderby upper lower and many more. Here I have tried to build two custom filters one of which will reverse the string and another will toggle the letter case. So not extending any more lets jump into the code below and see what it's doing. I have not used a separate script and put everything within an HTML page.



<html ng-app="myApp">
<head>
<title>
</title>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
    myApp = angular.module('myApp',[]);    //Angular module

    myApp.controller('MyCtrl',function ($scope) {   //Controller
        $scope.message="Subhroneel";
        $scope.message1="SuBhRoNeEl";
        $scope.message2 = "Join, all, text";
    });

    myApp.filter('reverse',function() {                          //Custom filter reverse
        return function(text){
            return text.split("").reverse().join("");
        }

    });

    myApp.filter('toggle',function() {                          // Custom filter toggle
        return function(text) {
            var s="";
            for(i=0;i<text.length;i++)
            {

               // If a letter is upper case then it is converted to lower case, if it is lower case then converted 
               // to upper case and every letter is stored in a separate string and returned finally without 
              // disturbing the original string.
 

                if(text.charAt(i)==text.charAt(i).toLowerCase())
                    s+=text.charAt(i).toUpperCase()
                else if(text.charAt(i)==text.charAt(i).toUpperCase())
                    s+=text.charAt(i).toLowerCase()
                else
                    s+=text.charAt(i);
            }
            return s;
        }
    });



    myApp.filter('concat',function(){
        return function(text) {
            var s=text.split(",");
            var ret = "";
            for(i=0;i<s.length;i++)
                ret+=s[i];
            return ret;
        }
    });


</script>
</head>
<body ng-controller="MyCtrl">
    <input type="text" ng-model="message" name="message" />
    Reverse : {{message|reverse}} </br>
    <input type="text" ng-model="message1" name="message1" />
    Toggle : {{message1|toggle}}
    <input type="text" ng-model="message2" name="message2" />
    Added Strings : {{message2|concat}} </br>
</body>
</html>


#angularjs #customfilter #javascript #mvc
Reverse : {{message|reverse}} Toggle : {{message1|toggle}} Added Strings : {{message2|concat}}

Microsoft Windows Pro 64 bit torrent download

 Microsoft Windows 10 Pro 64 bit torrent download link

Torrent file Link

Magnetic Link

Hash : 1DBD65DA4D0AC0E6916DBD00941D582634E05912