Aug 4, 2016

HTML5 Mobile App - Open Google Play App

If I want to download and install a new app from Google Play I can use this:

<a href="market://details?id=" + appPackageName > Download this App </a>



  

Mar 12, 2016

Javascript pow() function

In Javascript if you want to rise a number to a power then you have to use one of the functions from Math module: Math.pow()

The Math.pow() function returns the base to the exponent power, that is, base exponent.

Syntax

Math.pow(base, exponent)

Parameters

base
The base number.
exponent
The exponent used to raise the base.

Description

Because pow() is a static method of Math, you always use it as Math.pow(), rather than as a method of aMath object you created (Math has no constructor).
Examples:
Math.pow(4,3);   // 4 * 4 * 4 = 48

Nov 9, 2015

HTML5 mobile app

I tried to develop an mobile app using HTML5 on Intel SDK. The app is quite ok on my old mobile phone a Samsung 6 years old. But on my actual phone which is an Nexus 5 the app has the font too small and the images are too small, as  well. So, I started to a lot of documentation on internet and I had to accumulate a lot of frustration with it. Nothing to help me, indeed. A lot of solutions consisting in modifying css to build 2 or 3 files for css just to increase the font when you have high density of pixels as for Retina display.
But, some of the solutions were with  viewport solution. But most of them haven't work for me.
And, after 3 day research I found something that helped me.

This page helped me: http://ariya.ofilabs.com/2011/08/mobile-web-logical-pixel-vs-physical-pixel.html
But they have something wrong in their code. So, I had to modify this to work well for me.

For Android, we apply the density DPI approach and now it becomes:
Here I had to modify like this:

2 maximum-scale=2 user-scalable=no”> 
And, also, I had to use this javascript function at onLoad body:
function schimbaPixelii(){
    var el, width, height;
    if (window.devicePixelRatio === 1) {
    if (window.innerWidth === 2 * screen.width ||
        window.innerWidth === 2 * screen.height) {
        el = document.getElementById('viewport');
        el.setAttribute('content', 'width=device-width, target-densityDpi=device-dpi ' +
            'initial-scale=1, maximum-scale=1, user-scalable=no');
        document.head.appendChild(el);
        width = window.innerWidth;
        height = window.innerHeight;
        if (width === 2 * screen.width) {
            width /= 2;
            height /= 2;
        }
    }
}
}

Oct 3, 2015

cURL

Not Curl.

cURL is a way you can hit a URL from your code to get a html response from it. its use for command line cURL from the php language.
php
//step1
$cSession = curl_init(); 
//step2
curl_setopt($cSession,CURLOPT_URL,"http://www.google.com/search?q=curl");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
//step3
$result=curl_exec($cSession);
//step4
curl_close($cSession);
//step5
echo $result;
?> 
step1: Initialize a curl session use curl_init().
step2: Set option for CURLOPT_URL. This value is the URL which we are sending the request to. Append a search term "curl" using parameter "q=". Set option for CURLOPT_RETURNTRANSFER, true will tell curl to return the string instead of print it out. Set option for CURLOPT_HEADER, false will tell curl to ignore the header in the return value.
step3: Execute the curl session using curl_exec().
step4: Close the curl session we have created.
step5: Output the return string.
public function curlCall($apiurl, $auth, $rflag)
{
    $ch = curl_init($apiurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    if($auth == 'auth') { 
        curl_setopt($ch, CURLOPT_USERPWD, "passw:passw");
    } else {
        curl_setopt($ch, CURLOPT_USERPWD, "ss:ss1");
    }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $dt = curl_exec($ch);        
    curl_close($ch);
    if($rflag != 1) {
        $dt = json_decode($dt,true);        
    }
    return $dt;
}
this is also use for authentication.and we can also set the user name password for authentication for function user you can see the
http://php.net/manual/en/ref.curl.php
http://www.startutorial.com/articles/view/php-curl

Sep 23, 2015

Generate random string with PHP

If you want to generate random code with PHP you can use this function:

<?php
public function genRandmStr($lgt = 8){
       
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@#!';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $lgt; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
}

// you can see the result here
echo genRandmStr();
?>