Sunday, October 13, 2013

How to install .apk files on Android Emulator

How to install .apk files on Android Emulator


Its handy to test android applications on emulator included in SDK for testing purpose or if you don’t have an actual device.
Remember you don’t have to be a developer to do this and you don’t even require any IDE like eclipse or any other for this task.
Now i will elaborate the way to do this.
SDK Installation
  1. Download and install Android SDK from developer.android.com/sdk/
  2. Include  path of /tools folder in SDK installation folder in My Computer > right click > Advanced Tab > Environmental Variables button > System Variables > Path variable
Now the SDK is installed, we have to run emulator and install the application.  For running the emulator
Run Emulator
There are two separate ways to do this for two different versions of SDK i cam across 1.0 R2 and 1.5 R1.
1.0 R2
Go to /tools folder and just execute emulator.exe file.
1.5 R1
In this version another good feature is added to android emulator, different Android Virtual Device and Targets.
I will not go in details of  AVD and Targets in this post.
To run emulator you have to specify a avd, and to create a avd to have to specify a target, lets first check what are targets.
  1. Go to command line interface by typing “cmd” in run and click OK.
  2. Go to location of android SDK installation folder and further in /tools folder.
  3. View the list of available Targets by typing “android list targets”, press return.
  4. Now to create an AVD type “android create avd -n myavd -t 2″ press return, where -n is switch to specify avd name and -t to specify target. Specify integer number of any target from list of available targets.
  5. Now view the list of AVD’s and locate our newly created “myavd” in list by typing “android list avd”, press return.
  6. Finally type “emulator -avd myavd” and press return to run the emulator.
Install .apk files
Now finally to install android application .apk files, download and place .apk file in /tools folder and type “adb install my_android_app.apk”, press return.

Now you can probably see newly installed applicatin in menu.

Thursday, September 26, 2013

Ajax not work in yii

Ajax not work in yii

'enableAjaxValidation'=>false,

true this parameter in form view. like this

'enableAjaxValidation'=>true,

Friday, August 23, 2013

output buffering in php

Output Buffering

Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script.
Advantages of output buffering for Web developers
  • Turning on output buffering alone decreases the amount of time it takes to download and render our HTML because it's not being sent to the browser in pieces as PHP processes the HTML.
  • All the fancy stuff we can do with PHP strings, we can now do with our whole HTML page as one variable.
  • If you've ever encountered the message "Warning: Cannot modify header information - headers already sent by (output)" while setting cookies, you'll be happy to know that output buffering is your answer.

List vs Array

List vs Array

List is dynamic size and array is fixed size.

If You can add new elements to a list, but to add a new element to an array you need to create a new larger array and copy the old elements.
Arrays are a little leaner and more efficient if you don't need dynamic resizing, but lists are usually more convenient and the performance difference rarely matters for most applications.

For more information. 

Tuesday, July 16, 2013

2 days cron configuration

To run a cron job every 48 hours (i.e. every two days) try the following command:
Minute Hour Day Month Weekday
0 0 */2 * *

Send an HTML email

Send an HTML email:

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
?>  

Friday, July 12, 2013

Crontab examples

Crontab examples

Writing a crontab file can be a somewhat confusing for first time users, therefore I have listed below some crontab examples:
* * * * * <command> #Runs every minute
30 * * * * <command> #Runs at 30 minutes past the hour
45 6 * * * <command> #Runs at 6:45 am every day
45 18 * * * <command> #Runs at 6:45 pm every day
00 1 * * 0 <command> #Runs at 1:00 am every Sunday
00 1 * * 7 <command> #Runs at 1:00 am every Sunday
00 1 * * Sun <command> #Runs at 1:00 am every Sunday
30 8 1 * * <command> #Runs at 8:30 am on the first day of every month
00 0-23/2 02 07 * <command> #Runs every other hour on the 2nd of July


As well as the above there are also special strings that can be used:

@reboot <command> #Runs at boot
@yearly <command> #Runs once a year [0 0 1 1 *]
@annually <command> #Runs once a year [0 0 1 1 *]
@monthly <command> #Runs once a month [0 0 1 * *]
@weekly <command> #Runs once a week [0 0 * * 0]
@daily <command> #Runs once a day [0 0 * * *]
@midnight <command> #Runs once a day [0 0 * * *]
@hourly <command> #Runs once an hour [0 * * * *]

Crontab syntax

Crontab syntax

A crontab file has six fields for specifying minute, hour, day of month, month, day of week and the command to be run at that interval. See below:

*     *     *     *     *  command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

How to set-up a crontab file

How to set-up a crontab file?


Crontab syntax

A crontab file has six fields for specifying minute, hour, day of month, month, day of week and the command to be run at that interval. See below:
*     *     *     *     *  command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Crontab examples

Writing a crontab file can be a somewhat confusing for first time users, therefore I have listed below some crontab examples:
* * * * * <command> #Runs every minute
30 * * * * <command> #Runs at 30 minutes past the hour
45 6 * * * <command> #Runs at 6:45 am every day
45 18 * * * <command> #Runs at 6:45 pm every day
00 1 * * 0 <command> #Runs at 1:00 am every Sunday
00 1 * * 7 <command> #Runs at 1:00 am every Sunday
00 1 * * Sun <command> #Runs at 1:00 am every Sunday
30 8 1 * * <command> #Runs at 8:30 am on the first day of every month
00 0-23/2 02 07 * <command> #Runs every other hour on the 2nd of July
As well as the above there are also special strings that can be used:
@reboot <command> #Runs at boot
@yearly <command> #Runs once a year [0 0 1 1 *]
@annually <command> #Runs once a year [0 0 1 1 *]
@monthly <command> #Runs once a month [0 0 1 * *]
@weekly <command> #Runs once a week [0 0 * * 0]
@daily <command> #Runs once a day [0 0 * * *]
@midnight <command> #Runs once a day [0 0 * * *]
@hourly <command> #Runs once an hour [0 * * * *]

change the default crontab editor


Change the default crontab editor .

env EDITOR=nano crontab -e

Tuesday, July 9, 2013

Online PHP Training

If you want to learn PHP, comment with name. Course is very easy and not expensive. 

why we use php?

Why we use php?

1. Open Source
2. Easy
3. Web Scripting
4. Easily Integrated with html and javascript
5. Lot of frameworks
6. Lot of CMS (Content Management Systems)
7. More Jobs

Wednesday, June 26, 2013

SQL UNION Operator

SQL UNION Operator

The UNION operator is used to combine the result-set of two or more SELECT statements.

SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;

FULL OUTER JOIN

FULL OUTER JOIN

The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2). The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;

SQL RIGHT JOIN

SQL RIGHT JOIN

The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side whenthere is no match.

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;

SQL LEFT JOIN

SQL LEFT JOIN

The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side whenthere is no match.

SELECT column_name(s)
FROM table1
LEFT JOIN table2

ON table1.column_name=table2.column_name;

Tuesday, June 25, 2013

PHP TYPE HINTING

PHP TYPEHINTING

Functions are now able to force parameters to be objects.
<?php
// An example class
class MyClass {
    public $var = 'Hello World';
}

/**
 * A test function
 *
 * First parameter must be an object of type MyClass
 */
function myFunction(MyClass $foo) {
    echo $foo->var;
}

// Works
$myclass = new MyClass;
myFunction($myclass);
?>

Change variable type

PHP TYPE CASTING

Change variable type.
<?php
echo (float) ( (0.1+0.7)); // echoes 0!
echo (int) ( (0.1+0.7)); // echoes 0.8!
echo (double) ( (0.1+0.7)); // echoes 0.8!
?>

PHP TYPECASTING

TYPECASTING

Change variable type.
<?php
    echo (float) ( (0.1+0.7)); // echoes 0!
    echo (int) ( (0.1+0.7)); // echoes 0.8!
    echo (double) ( (0.1+0.7)); // echoes 0.8!
?>

xml XPath

XML XPath


XPath is a syntax for defining parts of an XML document.

Expression Description
------------------------------------

nodename Selects all nodes with the name "nodename"
/ Selects from the root node
// Selects nodes in the document from the current node that match the selection no matter where they are
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes

Example:

Path Expression Result
------------------------------------

bookstore Selects all nodes with the name "bookstore"
/bookstore Selects the root element bookstore
Note: If the path starts with a slash ( / ) it always represents an absolute path to an element!

bookstore/book Selects all book elements that are children of bookstore
//book Selects all book elements no matter where they are in the document
bookstore//book Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element
//@lang Selects all attributes that are named lang

REQUIRE_ONCE vs INCLUDE_ONCE

REQUIRE_ONCE vs INCLUDE_ONCE

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again

REQUIRE vs INCLUDE

PHP REQUIRE vs INCLUDE

The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

REQUIRE_ONCE vs INCLUDE_ONCE

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.

Difference between php require and inlcude functions. 

Mysql Transactions

Mysql Transactions

Avoid inconsistency in the cases where the script terminates unexpectedly.

try {
  $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $dbh->beginTransaction();

  $dbh->exec("insert into staff (id, first, last) values (23, 'Joe', 'Bloggs')");
  $dbh->exec("insert into salarychange (id, amount, changedate)
      values (23, 50000, NOW())");

  $dbh->commit();
 
} catch (Exception $e) {

  $dbh->rollBack(); // roll back if error occured

  echo "Failed: " . $e->getMessage();
}

Mysql FULTEXT Search

FULTEXT Search

LIKE search

SELECT * FROM articles WHERE body LIKE '%$keyword%';

This was slow and inefficient.Every time someone searched for an article, they got
far too many results.

Fultext search

SELECT * FROM articles WHERE MATCH(title, body) AGAINST ('PHP')

Monday, June 24, 2013

MYISAM vs InnoDB

MYISAM vs InnoDB

MYISAM:

MYISAM supports Table-level Locking
MyISAM designed for need of speed
MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.
MYISAM supports fulltext search
You can use MyISAM, if the table is more static with lots of select and less update and delete.

INNODB:

InnoDB supports Row-level Locking
InnoDB designed for maximum performance when processing high volume of data
InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
InnoDB stores its tables and indexes in a tablespace
InnoDB supports transaction. You can commit and rollback with InnoDB

Sunday, June 23, 2013

PDO vs MYSQLI

PDO MySQLi

Database support 12 different drivers MySQL only
API OOP OOP + procedural
Connection Easy Easy
Named parameters Yes No
Object mapping Yes Yes
Prepared statements
(client side) Yes No
Performance Fast Fast
Stored procedures Yes Yes

Database Support

PDO:

CUBIRD, mysql server, firebird/interbase, ibm, informix, mysql, oracle, odbc, db2, postgresql, sqlite, 4d

mysqli:

mysql