Pages

Wednesday, November 28, 2012

Configure Eclipse for Android Dev/Tools not found Error

Just started up with my first development with Android here is the link to how to setup Android ADT Package in Eclipse...
 
http://developer.android.com/sdk/eclipse-adt.html#installing
 
Here is the link for complete guide.
 
http://developer.android.com/sdk/installing.html#Installing
 
And if you are still getting an error like tools not found in android sdk in Eclipse
  
Run Android SDK Manager from start menu 
 
On the top you will see SDK Path

copy that path(you won't be able to copy it practically.I meant just take a note of that path)

run eclipse 
 
it will show an error that tools not found in a given directory

click on window menu select preferences

select Android from the list on left hand side 
 
on the right hand side you will find "SDK Location". Copy that path next to that and Bingo issue resolved 

Indicating a value as decimal literal in C Sharp

A value such as 14.5 is taken as a double by default by C Sharp and which cannot be automatically typecasted in decimal.

So indicate its data type as decimal we append M at its back

for example

decimal variable= 14.5M

Sunday, November 25, 2012

PHP Fatal error: Class 'CTestCase' not found Yii

PHP Fatal error:  Class 'CTestCase' not found

Running the command from the folder where bootstarp.php for testcases resolves this issue

Try running the tests from \protected\tests

Installing PHP Unit and Selenium and configuring it on Netbeans IDE

Follow the following links and tutorials to install and configure both(wanted it to be a one stop tutorial).

Follow this to install PEAR
http://itfeast.blogspot.in/2012/11/installing-pear.html

Installing PHPUnit

http://pear.phpunit.de/

To  Install Selenium 

Make sure you have Pear and phpunit installed

Then to install Selenium
Use this command
pear install Testing_Selenium-beta

To configure all this on Net-beans use this link
 http://netbeans.org/kb/docs/php/phpunit.html

Sunday, November 11, 2012

Adding php and phpunit to Windows default path

Adding php and phpunit to Windows default path

Open System in control panel=>Advance System Setting=>Envirnoment Variables=>

You will find a variable path in

Path

append to it your php directory..that's it

 Here is an image of the same...



Installing PHP Unit/Nothing to Upgrade error message

First of all we need to install PEAR as stated in my post

http://itfeast.blogspot.in/2012/11/installing-pear.html

Now that we have installed PEAR if success we will notice a PEAR folder in our php directory

also in our PHP directory will find a PEAR command line interface file

We need to place this a windows root path so that we can execute or files from everywhere for this refer

http://itfeast.blogspot.in/2012/11/adding-php-and-phpunit-to-windows.html


Now...

Installing PHP Unit

Fire the following command
pear channel-discover pear.phpunit.de
 
followed by
pear install phpunit/PHPUnit
 
wait for a few time depending on your internet speed phpunit will get downloaded and installed
 
If you get something similar to this you are done with phpunit installation 
 
C:\wamp\bin\php\php5.4.3>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

C:\wamp\bin\php\php5.4.3>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony.com
Did not download optional dependencies: phpunit/PHP_Invoker, use --alldeps to
wnload automatically
phpunit/PHPUnit requires package "channel://pear.symfony.com/Yaml" (version >=
.1.0)
phpunit/PHPUnit can optionally use package "phpunit/PHP_Invoker" (version >= 1
.0)
phpunit/PHPUnit_MockObject can optionally use PHP extension "soap"
downloading File_Iterator-1.3.3.tgz ...
Starting to download File_Iterator-1.3.3.tgz (5,152 bytes)
.....done: 5,152 bytes
downloading Text_Template-1.1.4.tgz ...
Starting to download Text_Template-1.1.4.tgz (3,701 bytes)
...done: 3,701 bytes
downloading PHP_CodeCoverage-1.2.6.tgz ...
Starting to download PHP_CodeCoverage-1.2.6.tgz (155,960 bytes)
...done: 155,960 bytes
downloading PHP_Timer-1.0.4.tgz ...
Starting to download PHP_Timer-1.0.4.tgz (3,694 bytes)
...done: 3,694 bytes
downloading PHPUnit_MockObject-1.2.2.tgz ...
Starting to download PHPUnit_MockObject-1.2.2.tgz (20,347 bytes)
...done: 20,347 bytes
downloading PHP_TokenStream-1.1.5.tgz ...
Starting to download PHP_TokenStream-1.1.5.tgz (9,859 bytes)
...done: 9,859 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.3.3
install ok: channel://pear.phpunit.de/Text_Template-1.1.4
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.4
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.1.5
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.2.6
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.2.2

C:\wamp\bin\php\php5.4.3> 
 

Now there are times we get an error while updating phpunit "Unabable to update PHP UNIT"

Message comes "Nothing to upgrade"

Follow following steps to upgrade phpunit in such cases

pear clear -cache

pear install -a-- phpunit/phpunit

and phpunit will upgrade successfully

Selecting random row from mysql database

Here is a simple query to select random row from a phpmysql database

Select * from `users` ORDER BY rand() limit 0,1

where users is the name of my table

Installing PEAR

PEAR is a very good package which contains pre defined built classes for various functionality which prevents one to re invent the wheel

I use mostly for TDD Test driven development which needs phpUnit which requires PEAR

Installing PEAR is very simple all you have to do is install php or a vanilla package like wamp, mamp, xampp, lamp now

download the file

http://pear.php.net/go-pear.phar

and place it under your php folder I use Wamp vanilla package so I will place under C:\wamp\bin\php\php.version

Its a windows machine

Now open your command line interface(windows) or shell(linux) and navigate to directory of your php folder and execute

php go-pear.phar

Under windows Vista,7 or in some versions of linux you might get a permission denied message in such  cases you need to run command prompt under admin mode.

To do so in windows under start->all programs->accessories->(right click on command prompt and select run as administrator to get the things work out for you)

Thursday, November 8, 2012

Wordpress plugins posting form or data to another Page in plugin

Wordpress plugins posting form or data to another Page in plugin

 <form id="mikex-settings" action="<?php echo plugins_url('update.php', __FILE__) ?>">  
   <label>Search Text:</label> <input name="search" value="<?php echo $options['search'] ?>" type="text" /><br />  
   <label>Replace Text:</label> <input name="replace" value="<?php echo $options['replace'] ?>" type="text" /><br />  
   <label>Replace Color</label> <input name="replace-color" value="<?php echo $options['replace-color'] ?>" type="text" /><br />  
   <label>Toggle Color:</label> <input name="toggle" value="<?php echo $options['toggle'] ?>" type="text" /><br />  
   <input type="submit" value="Update" /><span class="update-status"></span>  
 </form>  


In this way we an call another page to show up completely of a plugin in case of searchboxes etc

Add Metaboxes and Metafields to your wordpress posts

Add Metaboxes and metafields to your wordpress posts


 add_action('add_meta_boxes','mypost_add_custom_box');  
 add_action('save_post','myplugin_save_postdata');  
 function mypost_add_custom_box() {  
   add_meta_box(  
     'myplugin_sectionid',  
     __('Post Type Selection','myplugin_textdomain'),  
     'myplugin_inner_custom_box',  
     'post'  
   );  
 }  
 function myplugin_inner_custom_box( $post ) {  
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );  
  // The actual fields for data entry  
  $scheckval=esc_attr(get_post_meta($post->ID,'slider_post',true));  
  $pcheckval=esc_attr(get_post_meta($post->ID,'popular_post',true));  
  if($scheckval=='on')  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field"/>';  
  echo '<label for="myplugin_slider_field">';  
     _e("Slider Post", 'myplugin_sdomain' );  
  echo '</label> ';  
  if($pcheckval=='on')  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field"/>';  
  echo '<label for="myplugin_popular_field">';  
     _e("Popular Post", 'myplugin_pdomain' );  
  echo '</label>';  
 }  
 /* When the post is saved, saves our custom data */  
 function myplugin_save_postdata( $post_id ) {  
  // verify if this is an auto save routine.  
  // If it is our form has not been submitted, so we dont want to do anything  
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )  
    return;  
  // verify this came from the our screen and with proper authorization,  
  // because save_post can be triggered at other times  
  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )  
    return;  
  // Check permissions  
  if ( 'page' == $_POST['post_type'] )  
  {  
   if ( !current_user_can( 'edit_page', $post_id ) )  
     return;  
  }  
  else  
  {  
   if ( !current_user_can( 'edit_post', $post_id ) )  
     return;  
  }  
  // OK, we're authenticated: we need to find and save the data  
  if($_POST['myplugin_slider_field']=='on')  
  $smydata=$_POST['myplugin_slider_field'];  
  else  
  $smydata='off';  
  if($_POST['myplugin_popular_field']=='on')  
  $pmydata=$_POST['myplugin_popular_field'];  
  else  
  $pmydata='off';  
  update_post_meta($post_id,'slider_post',$smydata);  
  update_post_meta($post_id,'popular_post',$pmydata);  
 }