: Follow us
Blog Ocean
  • Home
  • Blog
    • Technology
    • Women >
      • Contest
    • Fiction
    • Personal / Daily Life
    • News and Media
    • Sports
    • Religion
  • Guestbook
  • Contact

PHP 5.5: What’s New?

24/1/2014

0 Comments

 
PHP 5.5 is the latest version of the language bringing about many exclusive features to increase its efficiency. The changes have contributed to improve its performance and the developers have been privileged immensely. Some of The exciting features and the outcomes are briefly discussed here.

list() support by foreach statement:

It introduces list () support for foreach statement. While working with nested arrays, you can unpack the array elements into variables in each iteration via list().

$product = [
    ["Nokia", "Lumia"],
    ["Samsung", "Galaxy"],
    ["Apple", "iPod"],
];

foreach ($product as list($Brand, $device)) {
   
    echo "Brand: $Brand; Device: $device\n";
}


Output:

Brand: Nokia; Device: Lumia
Brand: Samsung; Device: Galaxy
Brand: Apple; Device: iPod

Generator Support

Generator provides an alternative way to implement iterator without implementing the iterator interface and thus remove the overhead of iterator. Generator is very similar to a function, difference is instead of returning value, it yields its value. The keyword yield is used for this purpose.

<?php
function generatorTest() {
    echo "Generator starts\n";
    for ($count = 1; $count < 6; $count++ ) {
        yield $count;
        echo "count: $count \n";
    }
    echo "Generator ends";
}
foreach (generatorTest() as $gen);
?>


Output:

Generator starts
count: 1
count: 2
count: 3
count: 4
count: 5
Generator ends

Array and string dereferencing support:

PHP 5.5 adds support for array dereferencing into individual element as well as string dereferencing into individual characters.

<?php
echo 'Array dereferencing example:';
echo [
0, 1, 2][0];
echo 
"\n";

echo 
'String dereferencing example:';
echo 
'Web'[0];
echo 
"\n";
?>

Output:
Array dereferencing example: 0
String dereferencing example: W

Finally keyword for exception handling:

In php 5.5, finally keyword has been introduced for exception handling. In previous versions, exceptions were handled by try catch block only, no finally block was available.  The finally keyword is followed by a block of code, which is placed after every catch block. This block of code will always be executed, however any exception is thrown or not.

function division($x,$y) {
    if ($y==0)
 {
        throw new Exception('Divide by zero');
             }
 return $x/$y;
}
try {
             echo division(10,0) . "\n";
} catch (Exception $ex) {
 echo 'Caught exception: ',  $ex->getMessage(), "\n";
} finally {
   echo "Finally block after division.\n";
}


empty()  function support for expression:

In previous versions, empty() function was able to only check value of a variable, by taking a variable as an argument. Now any expression can be used as argument in empty function to perform the same stuff.

<?php
$ a = 5;
$b = 8;

function check_val() {
if(($a - $b) > 0)
                        return 
true;
else
return 
false;
}
if (empty(check_val ())) {
    echo "False returned.\n";
}
else
echo "True returned.\n";
?> 

Output:
True returned.

New password API:

This version introduces a secure password hashing API, which is one of the most important contributions. Previously, we had to depend on crypt() function and md5 technology which lacks security and is somewhat confusing.  In new API, hashing is performed by bcrypt() function, which returns a strong hash with automatically salted. PHP 5.5 introduces two new function named password_hash() and password_verify().

New features in GD library

PHP GD extension has improved its ability with some advanced image operations. Here is a list of new functions for image  different operation:
  • Imageflip() : Provides image flipping support
  • Imagecrop() and imagecropauto() : Provides advanced image cropping support
  • Imagecreatefromwebp() and imagewebp() : WebP read and write support

The introduction of new features in PHP 5.5 has contributed greatly to upgrade the language and PHP development.

Read also introduction to HTML5.

0 Comments

Introduction to HTML5

24/1/2014

0 Comments

 
HTML5 coding canvasOutput: Html5 coding for Bangladesh flag
HTML5 for web design

HTML5 is the new standard for Hypertext Markup Language (HTML), where 5 mean it is the fifth revision of HTML.

Why HTML5 is better:
  • HTML5 and javascript are interpreted.
  • Cross-platform support
  • Mobile device support
  • No need for software updates
  • Mobile development

New Elements:
HTML5 introduces some new elements for
  • Structure
  • Media
  • Form
  • Canvas

New structure element in Html5:
<article>
<aside>
<bdi>
<command>
<details>
<dialog>
<summary>
<figure>
<figcaption>
<footer>
<header>
<mark>
<meter>
<nav>
<progress>
<ruby>
<rt>
<rp>
<section>
<time>
<wbr>

New media elements in Html5:
<audio>
<video>
<source>
<embed>
<track>

New form elements in Html5:
<datalist>
<keygen>
<output>

 Some new types have been included as form input type.
         tel
         search
         url
         email
         datetime
         date
         month
         week
         time
         datetime-local
         number
         range
         color

New canvas element:
<canvas>

Obsolete Elements:
Some former elements have been obsolete in HTML5:
<acronym>
<applet>
<basefont>
<big>
<center>
<dir>
<font>
<frame>
<frameset>
<noframes>
<strike>
<tt>

New API:
Some new APIs have been introduced in HTML5. Out of them, here is a list of some useful API.

Application Cache API  : Interact with application cache. The method window.applicationCache is used to get ApplicationCache object. 
Data Transfer API: Performs drag-drop operations.
History API : Provides browsing session history.
Media Controller API : Interact with <audio> and <video> elements.
File API: Performs file upload and file manipulation.
File Write API: Performs file write operation from web application.
Geolocation API:  Retrieves geolocation information for a client device.

Introduction to a very Exciting Feature of HTML5: Canvas

Canvas is one of the most exciting features for web design using HTML5. It is used to draw graphics element in web page on the fly using the scripting language.  Here is a brief discussion on how to create and use canvas in webpage.

Create a canvas using the following tag.
<canvas>

You have to fix the width and height of the canvas. Initially it is blank.
 <canvas id="canvas" width="150" height="150"></canvas>

Next the rendering context is needed to be accessed and draw something on it. At first retrieve the canvas DOM node using the getElementById method. We can then access the drawing context using thegetContextmethod.

var canvas = document.getElementById(canvas);
var ctx = canvas.getContext('2d');

For error handling, we can first check whether browser supports the canvas:

      var canvas = document.getElementById(canvas);
if (canvas.getContext){
  var ctx = canvas.getContext('2d');
  // drawing code
} else {
  // canvas-unsupported code
}



Then we can draw something on the canvas. As for example, we can draw a rectangle and a circle on the canvas. You can draw shapes on your canvas which is very useful for web design.

if (canvas.getContext){
  var canvasCtx = canvas.getContext('2d');

ctx.fillStyle = "rgb(0,255,0)";
        ctx.fillRect (10, 10, 60, 50);

                ctx.beginPath();
      ctx.arc(40, 35, 15, 0, 2 * Math.PI, false);          
                ctx.fillStyle = 'red';
      ctx.fill();
      ctx.lineWidth = 0;
     // ctx.strokeStyle = '#003300';
      ctx.stroke();
} else {
  // canvas-unsupported code
}


Make it all together. It draws the national flag of Bangladesh on the canvas.

<html>
 <head>
  <script >
    function draw() {
      var canvas = document.getElementById('canvas');
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        ctx.fillStyle = "rgb(0,180,0)";
        ctx.fillRect (10, 10, 60, 50);
         ctx.beginPath();
         ctx.arc(40, 35, 15, 0, 2 * Math.PI, false);    
         ctx.fillStyle = 'red';
         ctx.fill();
         ctx.lineWidth = 0;
      }
    }

  </script>
 </head>
 <body onload="draw();">
   <canvas id="canvas" width="150" height="150"></canvas>
 </body>
</html>


Output:


The new features and new API’s introduced by HTML5 reflects to a revolutionary change to the worldwide web. Hopefully, from the above discussion, you have got some ideas about the power of HTML5. Enjoy the vitality of HTML5 and use it for your business, development or whatever you do.

Read new features in PHP5.5 as well.


0 Comments

Create SqlLite Database and Table in Android

20/1/2014

0 Comments

 
Android Database and TableAndroid Database and Table
SqlLite database is an integral part of an application that is used for local storage. The advantage SqlLite database offers are:
  • Simple and easy to administer
  • Small and reliable.
  • Can be embedded into a large program

In android, SqlLite is most commonly used database. Here we are going to create a sqllite database and table.

Account database:

Let’s think about an account database. Generally a database contain several tables to fullfil its purpose. Here we will create a database and make one table.

Let, our table will store account no and account name of the account holder. Account no is primary key. Look at the structure of the table given below:

Database name: accountDB

Table name: accountInfo
Table structure:
 




Create new application:

We are going to create a new application using eclipse editor. Go to New->project->android application project. Name the application and complete other configurations. Set launcher activity name to MainActivity.

Look at our MainActivity class.

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        MyDBHandler db = new MyDBHandler(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Consider this line:
 MyDBHandler db = new MyDBHandler(this);

It is used to make a database handler for our program. In the following section, we are going to discuss about the database handler class.

Create a database handler class named MyDBHandler.  All the information about database, table, and attributes of the table will be specified here. In onCreate function, table accountInfo will be created. In onUpgrade function, database will be upgraded to new version.

public class MyDBHandler extends SQLiteOpenHelper {
           
            private static final int DATABASE_VERSION = 1;

            // Database Name
            private static final String DATABASE_NAME = "accountDB";

            // Contacts table name
            private static final String TABLE_ACCOUNT = "accountInfo";

            // Contacts Table Columns names
            private static final String KEY_ACNO = "accountNo";
            private static final String KEY_NAME = "accountName";

            public MyDBHandler(Context context) {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
                        // TODO Auto-generated method stub
                        String CREATE_ACCOUNT_TABLE = "CREATE TABLE " + TABLE_ACCOUNT + "("
                                                + KEY_ACNO + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT" + ")";
                        db.execSQL(CREATE_ACCOUNT_TABLE);
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                        // TODO Auto-generated method stub
                        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ACCOUNT);

                        // Create tables again
                        onCreate(db); 
            }
}

Create a class named Account. It will be used to set account information and retrieve the information. This class is used to perform CRUD (Create, Read, Update and Delete) operations in database. For now, this operation is out of scope for us in this article. We are just going to look at the class. 

public class Account {
           
            int accountNo;
            String accountName;
           
            // empty constructor
            public Account(){
            }

            // constructor
            public Account(int accountNo, String accountName){
                        this.accountNo = accountNo;
                        this.accountName = accountName;
            }
           
            // get account no
                        public int getAccNo(){
                                    return this.accountNo;
                        }
                       
                        // set account no
                        public void setAccNo(int accNo){
                                    this.accountNo = accNo;
                        }
                       
                        // get account name
                        public String getAccName(){
                                    return this.accountName;
                        }
                       
                        // set account name
                        public void setAccName(String accName){
                                    this.accountName = accName;
                        }
}

Here is a brief about the stated function.

Account(): Constructor,  set account no and name.
setAccNo(): Set the account no
getAccNo(): get the account no
setAccName(): Set the account name
getAccName():  Get the account name.

From this article, we have learnt how to create SqlLite database and table. But if we want to use the database, we would have to learn how to perform CRUD(create, read, update, delete) operations.


Also know android project structure to start developing Apps and game in android and Working with bitmap image to see how Guess Who? image apps are created in Android.


0 Comments

Android Project Structure

20/1/2014

0 Comments

 
Android app development - Android project structure 1
Apps and game development in android is a very promising profession now-a day. One must know Android project structure if they want to develop the career in Android based development.

Create a new project:

First, we would create a new project using eclipse. In different steps of project creation, we will configure the application which will affect some of our project configuration files.

 Step 1: File->new->project->android application project

Here, we have namedour application, package name under which the application will run; build sdk version and minimum sdk version. Minimum sdk version is required to make your application backward compatible, i.e. to run into previous android OS based device.


Read More
0 Comments

New features in WordPress 3.8

16/1/2014

0 Comments

 
wordpress 3.8 Admin color scheme
Admin color scheme in wordpress 3.8
wordpress 3.8 dashboardDashboard of wordpress 3.8
WordPress 3.8, “Parker”, the latest addition in WordPress field is the outcome of toils of 188 core contributors. The term “Parker”, has been given commemorating Charlie Parker, a jazz saxophonist and bepob innovator. Some awesome features have been introduced in this version of wordpress, which are going to be discussed below:

Modern admin interface

New version of wordpress provides a modern and improved admin interface. This improvement is mainly done by the MP6 plugin, which has been made a part of wordpress 3.8 core. It facilitates the wordpress admin by breaking up and simplifying admin UI.

Admin color scheme

Wordpress 3.8 provides colorful and refreshing interface for admin. If you don’t like the default color, don’t worry. Just go to your dashboard, select Users->Profile.

Just look at the color schemes available for you. You are surely going to like these color schemes and customization

Responsive design

This version offers a responsive design by achieving significant improvement in content display.

It introduces vector based icons called dash icons. By using vector based graphics instead of pixels, it offers significantly fast page load facilities.

It introduces the Open Sans font throughout the admin area. It is a simple and friendly font with good spacing between characters. So it increases readability as well as it simplifies editing.  Along with these, it is optimized for both desktop and mobile display.

Sophisticated dashboard

Till the release of wordpress 3.8, dashboard of wordpress was sort of ignored in case of improvement in the previous versions. In this version, it has got some attention and the outcome is the new look.

New dashboard is simplified, attractive and sophisticated. Previous eight widgets are replaced by four. So, organization of the dashboard has got a smarter look.


The ‘Activity’ widget is the replacement of previous ‘Recent comment’ widget, which displayed most recent five (5) comments. It is a closer mimic than the previous one.

Two draft related widget ‘Recent draft’ and ‘Quick press’ are condensed into a new widget named ‘Quick draft’.

Three news related widget ‘Wordpress blog’, ‘Other wordpress news’ and ‘Plugins’ are condensed into a new widget ‘Wordpress news’.

Attractive widget management

One of the satisfactory features is new attractive widget interface. The organization of widgets and widget areas is simple and easy to handle. Addition, removal and transfer of widget also have been simplified.

Default 2014 theme

Twenty fourteen is a new wordpress theme designed with magazine layout. It was released before the release of wordpress 3.8. From the initial design, this theme has been improved significantly and achieved good user experience. As a result, in wordpress 3.8, it has been made the default theme.

WordPress 3.8 has emerged with its unique features being more user friendly and advantageous to use. Here we have discussed some new amazing features of WordPress 3.8. Hopefully you have enjoyed it and will make a try for hands on experience.

Default 2014 theme in wordpress 3.8
Default 2014 theme in wordpress 3.8
0 Comments

Cloud Computing

16/1/2014

2 Comments

 
Picture
cloud service modelDifferent cloud service model
Cloud computing is a new class of network based computing which uses internet for communication and provides hardware, software and network service to clients. Some important characteristics are:
  • On demand service
  • Pay per use
  • Elastic scalability

Service Models

Cloud computing service is offered to different groups of clients in different model.

The service models which are commonly deployed are:

  • Software as a Service (SaaS)
An application or software is installed in the cloud. Users get the authorization to access the application from the client side.

 Consumers purchase the ability to access and use an application or service that is hosted in the cloud. These applications achieve scalability by cloning the task on to multiple virtual machines.  Cloud service providers manage the infrastructure and platform of the app.

  • Platform as a Service (PaaS)
Consumers get access to the computing platforms. They can deploy their own software and applications in the cloud and need not think about the underlying hardware and software.

Windows azure is an example of PaaS.

  • Infrastructure as a Service (IaaS)
 This service model offers physical or virtual machines and other resources which may include virtual-machine disk library, raw (block) and file-based storage, firewalls, load balancers, IP addresses, virtual local area networks (VLANs) software bundles etc.










 

Deployment Models

Depending on the users and requirements, different deployment model has been introduced.
  • Public cloud
  • Community cloud
  • Private cloud
  • Hybrid cloud

Characteristics of each model are discussed on the following section.       

  • Public Cloud
The cloud infrastructure is accessible over a public network, such as the internet. Compared to other models, it offers significantly low costs as well as provides ultimate scalability with vast pool of resources, such reliability that individual users will experience no ill suffer. It is also flexible as we can use any service model such as SaaS, IaaS, PaaS in public cloud. The only problem may be the security problem.

Example: Amazon Elastic Compute Cloud (EC2), IBM' Blue cloud, Google AppEngine, Windows Azure Services Platform etc.

  • Community Cloud
This infrastructure is dedicated to several organizations or communities with same interest. These communities have similar interest or goal to achieve. For example, a community cloud can aim to healthcare, IT solution etc. The cost is shared by the groups altogether. The cloud service is managed and secured by all participating organizations or a third party service provider.

  • Private Cloud
This infrastructure is dedicated to a particular organization. It costs a lot, which can be met some big giant companies only. It offers higher security, privacy, full control on the service and improved reliability.

  • Hybrid Cloud
This infrastructure is not any distinct concept, rather a combination of private and public cloud. Cost effectiveness of public cloud and improved security and privacy of private cloud is integrated here. Therefore, an organization can maximize their efficiencies  and cost effectiveness by employing public cloud services for the non-sensitive operations, such as their brochure site, while relying on a private cloud where security and privacy is required, such as for e-commerce portion.

Cloud computing is the future of computing system.  The advantage it offers with cost reduction of hardware and software, flexibility and scalability are really a great contribution to computing system. It has become very popular in this era.


2 Comments

    RSS Feed

    Author

    Vaibhav O Yadav - Top IT professional. Worked with Fortune 100 company. I like to spread the knowledge. Analyse situation and environment with long term vision and solution. Firm believer of sustainable development for earth. Apart from from being geeky also like to play multitude variety of video games on greater stretch of time with favorite being economic simulation

    Categories

    All
    Android
    Android App Development
    App Development
    Apple
    Cloud
    Data Virtualization
    Data Warehouse
    Virtualization
    Wordpress

    Archives

    October 2014
    March 2014
    January 2014
    December 2013

    Tweets by @BlogOcean
Powered by Create your own unique website with customizable templates.