Pages

Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

Friday, September 30, 2016

Angular Js- Using minified version of Controller,filter js files

Using minifed version of controller JS Files

Here we will use a controller as an example same can be used for Filters

One important thing to note when we isolate controller from our HTML file is during its minification.
The minification also minifies variable in controller and $scope,$http,$filter may become variables a,b,c which are not recognized by angular see the minified version of above controller.js is as follows

controller.js

 angular.module('myApp',[]).controller('myCtrl',function($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 });  

controller.min.js

 angular.module("myApp",[]).controller("myCtrl",function(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]});  

Here $scope becomes n and this will not be recognized by angular js.To over come this problem use code controller code in controller.js as

controller.js

 angular.module('myApp',[]).controller('myCtrl',["$scope",myCtrl]);  
 function myCtrl($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 };  

In this we isolate the Controller function but we also tell the module that the first parameter of this function will be "$scope"

The Minified version of this file is

controller.min.js

 function myCtrl(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]}angular.module("myApp",[]).controller("myCtrl",["$scope",myCtrl]);  

Above file also changes the parameter $scope of the function to "n" but when final call is made to function the first parameter is sent as $scope

Wednesday, July 17, 2013

GIT Repository-Export only modified and added files with folder structure in Git

Recently I was working on a git repository setup on  my local and had a task of getting all the modified and changed files in a tar.(Remember I had not committed my changed files).Even if you have you can use the corresponding commit id to get list of changed files in that commit

Here is the command I used to extract modified and added files in a GIT repository


 git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id | xargs tar -rf mytarfile.tar  

Tuesday, November 6, 2012

Unable to upload files from form

enctype=multipart/form-data

Always when adding input type="file" in your form add this parameter to your form tag as a property.....



now what does this mean

When submitting a form, you're trying to say your browser to send via the HTTP protocol a message on the network properly enveloped in a TCP/IP protocol message structure. When sending data, you can use POST or GET modes to send data using HTTP protocol. POST tells your browser to build an HTTP message and put all content in the header of the message ( a very useful way of doing things, more safe and also flexible). GET has some constraints about data representation and length.
When sending a file, it is necessary to tell HTTP protocol that you are sending a file having several characteristics and information inside it. In this way it is possible to consistently send data to receiver and let him open the file with the current format and so on... This is a requirement from the HTTP protocol as shown here:http://www.w3.org/TR/html401/interact/forms.html
You cannot send files using default send enctype parameters because your receiver might encounter problems reading it (consider that a file is a descriptor for some data for a specific operating system, if you see things this way, maybe you'll understand why it is so important to specify a different enctype for files).
This way of doing things also ensures that some security algorithms work on your messages. This information is also used by application-level routers in order to act as good firewalls for external data.