samedi 25 avril 2015

[AngularJS] No 'Access-Control-Allow-Origin' header is present on the requested resource

If your Ionic application use $http.post (for calling a restful service for example) and if you try test your application (executed with the command ionic serve) on your PC with a browser like Chrome, you will obtain this kind of message in your JavaScript console :
No 'Access-Control-Allow-Origin' header is present on the requested resource[...]

Solution :

During your test, you can do that :

  • replace :
$http.post(url,params);

  • by :
var config = {
     method: 'POST',
     data:params,
     headers: {
        'Content-Type': undefined
     },
     url=url
};$http(config);


  • and define in your restful application :
"Access-Control-Allow-Origin": "*"

Source : http://forum.ionicframework.com/t/angularjs-post-request-cors-issue/10334

Other interesting sources :
http://juhap.iki.fi/webdev/cross-domain-http-with-python/
http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
http://stackoverflow.com/questions/12630231/how-do-cors-and-access-control-allow-headers-work

mercredi 22 avril 2015

[XDK] rename a project

Let's suppose you would like to rename your XDK project my_old_project to my_new_project


In two steps. But be careful, execute these steps at your own risk !!!!!

First of all, close XDK :)

1- rename your project :

  • rename the folder containing your .xdk file : my_old_project -> my_new_project
  • rename your file my_old_project.xdk to my_new_project.xdk (same manipulation for the .xdke file)
  • edit the files :
    • intelxdk.config.android.xml 
    • intelxdk.config.crosswalk.xml
    • intelxdk.config.ios.xml
    • intelxdk.config.windows8.xml 
  • and replace <name>my_old_project</name> by <name>my_new_project</name>
  • edit my_new_project.xdk and replace "appName_": "my_old_project" by         "appName_": "my_new_project"

2- delete the caches of XDK:


  • delete the content of the folders :
    • C:\Users\XXXX\AppData\Local\XDK\Cache
    • C:\Users\XXXX\AppData\Local\XDK\File System\Origins
    • C:\Users\XXXX\AppData\Local\XDK\GPUCache
    • C:\Users\XXXX\AppData\Local\XDK\Local Storage

  • delete files C:\Users\XXXX\AppData\Local\XDK\cookies and cookies-journal and global-settings.xdk and state.json

vendredi 17 avril 2015

[XDK] Intel App Preview - intel.xdk.device.barcode.scan not executed on mobile

If you use the intel.xdk.device.barcode.scan (XDK Javascript Bridge API) in your app and would like to test on a real mobile with the App Preview, you could see the QRCode reader does not display in your mobile.

Below a few steps to solve (I create a new project):

  • create a new project (type : HTML5 + Cordova) 
  • on the project page, verify that field UI Framework is not "unkown"
  • on the project page, uncheck all plugins
  • in  app.js file write :
document.addEventListener("intel.xdk.device.barcode.scan",function(evt){
intel.xdk.notification.beep(1);    
 if (evt.success === true) {            
  //successful scan          
    console.log(evt.codedata);      
        if (evt.codedata == "http://www.sampleurl.com/fake.html")
                {  
                     //in the XDK        
       }              
 else
                {            
          alert(evt.codedata);        
       }      
 }else {            
   //failed scan        
       console.log("failed scan");  
    }
  },false);

  • where you want (for exemple in your index.html), write : <script>intel.xdk.device.scanBarcode(); </script>

jeudi 16 avril 2015

[Cordova] [NetBeans] npm http 404 http://registry.cordova.io/cordova-plugin-file

If you try to run for the first time an android application with Netbeans 8.0.2 and have this kind of message :

npm http 404 http://registry.cordova.io/cordova-plugin-file Failed to install 'cordova-plugin-media-capture':Error: 404 Not Found: cordova-plugin-file

Then you shoud install this plugin separately. For that, go to your project folder and type :
https://github.com/apache/cordova-plugin-file.

Now you can re-run your application under NetBeans.

Source : http://stackoverflow.com/questions/29488069/build-error-cordova-application-error-404-not-found-cordova-plugin-file

mercredi 1 avril 2015

[Linux] Find and move files of a particular size

list them:


find /home/ -type f -size 123c -exec ls {} \;

move them:


find /home/ -type f -size 123c -exec mv {} <your_destination_directory> \;

b – for 512-byte blocks (this is the default if no suffix is used)
c – for bytes
w – for two-byte words
k – for Kilobytes
M – for Megabytes
G – for Gigabytes

You can use -123c for <123c
You can use +123c for >123c

[Linux] Find and move files older than a date

list them :
find . -mtime +7 -type f -exec ls -l "{}" \;


move them :
find . -mtime +7 -type f -exec mv "{}" <your_destination_directory> \;

Categories