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();
?>

Sep 18, 2015

CakePHP how to retrieve POST and GET vars

When you are working with CakePHP framework and you try to retrieve the variables which have been sent through GET or POST.

For POST variables you have

For $_POST['key']  we have
$this->request->data('key');


For GET variables you have

For $_GET['kpa']  we have
$this->request->query('kpa');


Sep 8, 2015

HTML5 vs HTML

There is some differences between HTML and HTML5. So though, we have:

HTML5 was designed to replace both HTML 4, XHTML, and the HTML DOM Level 2.
And XHTML is HTML + XML. For a better syntax and for a better administration they had to force HTML to be proper: for instance, if you open this tag <p> you have to close the tag with </p>.

The main goals of HTML5 are:
- Deliver rich content as graphics or movies without the need of additional plugins as Flash, for instance;
- Provide better semantic support for web page structure. For this, HTML5 introduces new structural element tags;
- Provide better cross-platform support (for PC browser, tablet or smartphone);
- Provide a stricter parsing standard to simplify error handling, ensure more consistent cross-browser behavior.

HTML5 has improved the support for embedding graphics, video and audio. For that HTML5 has some new tags: <canvas>, <audio>, <video>

HTML5 has introduced web workers. A web worker is a script that runs in the background, in another thread, without the page has to wait for it to complete. The visitor can continue to interact with the page while the web worker runs in the background.


HTML5 has new semantic tags to complement the structural logic of modern web applications. Here we have:
<main>
<nav>
<article>
<section>
<header>
<footer>
<aside>

HTML5 has new controls like
<calendar>
<date>
<time>
<email>
<url>
<search>



HTML5 has new extensions to the Javascript API as geolocation, drag-and-drop, storage and caching.

Aug 28, 2015

CakePHP and PHP version

I was trying to code at my project. It was OK on my localhost webserver. But... when I moved the files on the real webserver I had a problem.
I didn't know what could that be. I got errors just on some pages. Not at all pages of my website.
Then, I realized that, perhaps, my version of PHP could be too old. Actually, not my version but real webserver version.

Indeed, the problem it was with PHP version which is 5.3 and this version doesn't know about the arrays declared like this:

$ar = ['key1' => 'value1', 'key2' => 'value2'];

It knows only like this:

$ar = array('key1' => 'value1', 'key2' => 'value2');

I got this issue when I tried to make a Form and I finished to have this PHP code

echo $this->Form->input('name', [
                'label'=>[
                    'class' =>  'ContactInput',
                    'text'  =>  'Name:' . $messgError['name']
                ]

            ]);



Aug 26, 2015

CakePHP 2 - Forms

When you try to create a new form in CakePHP framework using FormHelper, you may have this error:

Missing Database  Table
And if you read very carefully  the Book of CakePHP will see something like that:

You can also pass false for $model. This will place your form data into the array: $this->request->data (instead of in the sub-array: $this->request->data['Model']). This can be handy for short forms that may not represent anything in your database.
So, in your view file like APP/View/Contact/index.ctp, you have  to start with this line:

echo $this->Form->create(false, array('url' => '/contact'));

Good luck!

Aug 19, 2015

CakePHP 2.* how to use custom complex sql Query with model

Let's suppose that we have MySQL database with table categories:

CREATE TABLE `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category` varchar(64) DEFAULT NULL,
  `description` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;


Then, in CakePHP framework, you want to call a simple query as you did it with mysql_query in PHP with no framework.

For that you have the class Model::query()

First, you build the model. You don't want to use predefined Models for a table (like the model Categories for DB table Categories). Because you want to use perhaps this query for extracting data from two tables which are related.

So,  first you have to create the model. For this you have to create the file APP/Model/Categs.php



class Categ extends AppModel {

    public $useTable = false; // it is mandatory to have this line. Whithout this line, 
                              //                                    the Controller will search for table Categ; it doesn't matter that you have a sql query  

    public function getDataFromMyTable(){
        $d = $this->query("SELECT * FROM  categories");
        return $d;
    }

}


Second, you have to create the Controller. The file will be: APP/Controller/CategsController.php


class CostsController extends AppController {
    
    
    public function index(){
        $this->loadModel('Categ');
    
        $rezQuery = $this->Categ->getDataFromMyTable();
        $this->set('cs', $rezQuery);
    }
}
?>


And now we have to create the view. We create folder APP/View/Categs (if this folder doesn't exists). And then we create the file index.ctp into this folder. The name of the ctp file should be the  same as name of the function from Controller. In index.ctp we write:


Aug 14, 2015

CakePHP and .ctp files

If you use CakePHP as PHP framework then you'll see some different types of files: CTP. And you'll need to see them as a php file in your PHP editor, Eclipse. For this you'll do this:

Preference>General>Content Types>Php then add *.ctp

And then you need to restart Eclipse IDE for have an effect.



CakePHP

Last 2 weeks I tried to put ZF2 to my project www.mateonline.net. It was endless pain to configure Zend Framework 2 for me as a beginner with this. ZF2 as syntax is very nice. But something got wrong with server configuration.
So, then I said I will try Symfony 2. But, I quit immediately. I though it will be easier, but it is no so nice as ZF2.
And, then I pass to CakePHP. Which I like. Except the fact that it has no PDO. I don't like  how is linked to MySQL DB but I can use to it.

Aug 3, 2015

PHP namespace

When you use namespace on PHP scripts you have to use require(), require_once(), include() or include_once() . It doesn't work without one of these like you can see on this example:

php namespaces are case-insensitive:

file1.php:
namespace foo;

function 
bar()
{
    echo 
'from bar';
}
?>
file2.php:


fOo
\bar() // output: from bar
?>
This example is here:
http://php.net/manual/en/language.namespaces.rationale.php

A better example is here:
http://www.sitepoint.com/php-53-namespaces-basics/

Jul 23, 2015

Javascript redirect for mobile devices

The best method to redirect for mobile that I found is following:


<script type="text/javascript">
if (screen.width < 1081) {
 var ref = document.referrer;
 var urls = new Array("http://www.mymainsite.com","http://m.mymobilesite.com");
 var n = ref.match(urls[0]);
 var m = ref.match(urls[1]);
 if ((m!==null) || (n!==null)) {
 stop;
 }
 else if (ref=='') {
 var r = confirm("Small Display is Detected.\nClick \"OK\" for MOBILE SITE.");
 if (r==true) {
  window.location = "http://m.mymobilesite.com";
  }
  else {
  stop ;
 }
 }
 else
 {
 window.location = "http://m.mymobilesite.com";
 } 
}
</script>

Angular JS

Last days I was struggling with implementation of Angular JS on one  my websites: www.pensiunealajura.ro/mobil/

The big issue with this was to list HTML code without listing HTML tags like < or >. For instance, I wanted to have

    This is a bold text.

not

  This is a <b>bold text</b>.

So, I tried to have this with the module ngSanitize and $sanitize and $sce with  $sce.trustAsHtml.

But all of these were not good. And i dug more. And I found out that the best way to write formatted HTML code into a web page using Angular JS  is using directive ngBindHtml as is explained here: 
https://docs.angularjs.org/api/ng/directive/ngBindHtml

Now, everything is ok with my page.
:)

May 30, 2015

News about Java

A new article about Java 20 years:

Java's 20 Years Of Innovation

The importance of a given programming language—especially one as pervasive as Java—in changing how people use technology is difficult to underestimate. The big data revolution, for example, is primarily a Java phenomenon. 
[...]
Fatigue with C
However, a fatigue with C was definitely emerging. The language had two major handicaps in those days: First, it was too low level—that is, it required too many instructions to perform even simple tasks. Second, it wasn’t portable, meaning that code written in C for the PC could not easily be made to run on minicomputers and mainframes.

The low-level aspects, which still are apparent today, led developers to feel that writing applications in C was akin to mowing the lawn with a pair of scissors. As a result, large software projects were tedious and truly grueling.
The portability of C was also a major problem. Although by 1995, many vendors had adopted the 1989 ISO standard, they all added unique extensions that made porting code to a new platform almost impossible.
It’s no coincidence, then, that this era saw the emergence of a new generation of languages. In 1995 alone, there appeared Ruby, PHP, Java, and JavaScript.
Java almost immediately became popular for mainstream programming due to its portability and large set of built-in libraries. The then-mantra for Java was “write once, run anywhere.” While not strictly true initially, it quickly became so, making Java a good choice for business applications that needed to run on several platforms.

http://www.forbes.com/sites/oracle/2015/05/20/javas-20-years-of-innovation/

 


May 22, 2015

Java at 20

Remembering what the programming world was like in 1995 is no easy task. Object-oriented programming, for one, was an accepted but seldom practiced paradigm, with much of what passed as so-called object-oriented programs being little more than rebranded C code that used >> instead of printf and class instead of struct. The programs we wrote those days routinely dumped core due to pointer arithmetic errors or ran out of memory due to leaks. Source code could barely be ported between different versions of Unix. Running the same binary on different processors and operating systems was crazy talk.

Java changed all that. While platform-dependent, manually allocated, procedural C code will continue to be with us for the next 20 years at least, Java proved this was a choice, not a requirement. For the first time, we began writing real production code in a cross-platform, garbage-collected, object-oriented language; and we liked it ... millions of us. Languages that have come after Java, most notably C#, have had to clear the new higher bar for developer productivity that Java established.


James Gosling, Mike Sheridan, Patrick Naughton, and the other programmers on Sun’s Green Project did not invent most of the important technologies that Java brought into widespread use. Most of the key features they included in what was then known as Oak found its origins elsewhere:
  • A base Object class from which all classes descend? Smalltalk.
  • Strong static type-checking at compile time? Ada.
  • Multiple interface, single implementation inheritance? Objective-C.
  • Inline documentation? CWeb.
  • Cross-platform virtual machine and byte code with just-in-time compilation? Smalltalk again, especially Sun’s Self dialect.
  • Garbage collection? Lisp.
  • Primitive types and control structures? C.
  • Dual type system with non-object primitive types for performance? C++.


May 18, 2015

MIPS

First of all, this morning I found out that exist two different MIPS in this world.

First MIPS is a reduced instruction set computer (RISC) instruction set architecture (ISA) developed by MIPS Technologies (formerly MIPS Computer Systems, Inc.).

The other MIPS is a software product. I wanted to talk about this one because I had to face it at my workplace. This MIPS is from Management & Information Processing Services. They said that this software is made to help you in your Management activities.

From my experience at my workplace this software help you to annoying you. It is ugly and difficult to use. It is not oriented to user. It is made to build another ugly thinks. MIPS solutions doesn't help you, MIPS generates a lot of new problems. Here we have built something very nice with webserver and external database using AJAX, jQuery for front-end for a wonderful experience for the final users. But, MIPS team came with something ugly and nonsense solution. They have been chosen because they are MIPS even their solution is a big problem for users teams. Because the IT management is old and they don't understand that we are in XXI century.

And how can you have trust in this kind of software when they have a website like this? http://www.mipssoftware.com/
* built like has been made in 1992.
* ugly and non-friendly structure
* unfinished texts
* Underconstruction ???? Since 2011.

STS

I've tried to make a Spring Java project. I tried and tried last week, but today I've discovered this: STS. Which is an Eclipse extension easy to build Spring Projects.

May 5, 2015

HTTP/2: A jump-start for Java developers

HTTP/2 was approved in February 2015 as the successor to the original web communication protocol. While it is in the last stages of finalization, the standard has already been implemented by early adopters such as Jetty and Netty, and will be incorporated into Servlet 4.0. Find out how HTTP/2 renovates HTTP's text-based protocol for better latency, then see techniques like server push, streaming, multiplexing, and header compression implemented in a client-server example using Jetty.


High-speed browser networking


In the early days of the World Wide Web, Internet connection bandwidth was the most important limiting factor for a faster browsing experience. That has changed in the years since, and these days many consumers use broadband technologies for Internet access. As of 2014, Akamai's State of the Internet report showed that the average connection speed for customers in the United States exceeded 11 Mbit/s.
As Internet connection speeds have increased, the importance of latency to web application performance has become more apparent. When the web was new, the delay in sending a request and waiting for a response was much less than the total time to download all of the response data, but today that is no longer the case. "High bandwidth equals high speed" is no longer a valid maxim, but that doesn't mean we can ignore the importance of bandwidth. For use cases that require bulk data transfer such as video streaming or large downloads, bandwidth is still a roadblock. In contrast to web pages, these types of content use long-running connections, which stream a constant flow of data. Such use cases are bandwidth bound in general.