jeudi 12 novembre 2015

[AngularJS] retrieve param in url

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
 
var queryValue = getParameterByName('test_user_bLzgB');

Then it is not necessary to enable html5 and to define a <base>...

Source : http://stackoverflow.com/a/28473677

mercredi 9 septembre 2015

http://{s}.tile.osm.org/{z}/{x}/{y}.png ERR_INSECURE_RESPONSE

If you use Leaflet (http://leafletjs.com) inside a HTTPS page and you would like to access to the OpenStreetMap tiles like that : 
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

You must do that :

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

OpenStreetMap  doesn't have a certificate for the abbreviated domain osm.org




Source : https://github.com/Leaflet/Leaflet/issues/3186

jeudi 6 août 2015

[Ansible] problem when executing a mongo script on a remote server

When you want to execute the command mongo on the remote server (for exemple when you want to do mongo --host myserver --port 27017 myscript.js you must do that in your playbook :

-shell: mongo --host myserver --port 27017 < myscript.js 

Source : http://stackoverflow.com/questions/4837673/how-to-execute-mongo-commands-through-shell-scripts#comment21193090_4837678

mercredi 29 juillet 2015

[Python] Buffered ouput by default

By default, Python produces buffered output (when you use print).

This could be a problem when you would like to see in "real time" your print(...) for example in a log file.

You can disable the buffer for output, by adding the option "-u" like that :
python -u my_script.py


I had this problem with Tornado + supervisor. I did not understand why my print(..) was not written immediately in my log file => -u option solves my problem !

lundi 20 juillet 2015

[Nginx] Redirect http to https


server {
   listen 80;
   server_name my.domain.com;
   return 301 https://$server_name$request_uri; 


server { 
   listen 443 ssl; 
   server_name my.domain.com; 
   [....] 

dimanche 3 mai 2015

[AngularJS] [Ionic] ng-click called twice

When I click on a <A> tag having a ng-click, the ng-click is called twice.

For solving this problem, I use the new ng-click provided in the module ngTouch.


The original ng-click provided inside the ng core :
https://docs.angularjs.org/api/ng/directive/ngClick

The new ng-click inside the ngTouch module :
https://docs.angularjs.org/api/ngTouch


For calling the ng-click in ngTouch : 

<script src="angular.js">
<script src="angular-touch.js">
angular.module('app', ['ngTouch']);

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> \;

mercredi 25 février 2015

mardi 27 janvier 2015

[Python] Tornado - send POST parameters in the body with AsyncHTTPClient

If you want to send POST data to an URL(a RESTful web service for example) with AsyncHTTPClient, you can do that :

import urllib
post_data = { 'data': 'test data' } #A dictionary of your post data
body = urllib.urlencode(post_data) #Make it into a post request
http_client = tornado.httpclient.AsyncHTTPClient()
http_client.fetch("http://127.0.0.1:8888", handle_request, method='POST', headers=None, body=body)
Link : http://stackoverflow.com/questions/10367981/how-to-use-post-method-in-tornado

Categories