Tuesday, March 29, 2011

Android SDK and AVD Manager slow download problem

I was Installing the Android SDK (http://developer.android.com/sdk/installing.html) on my Windows XP box.

Problem : Slow download of android SDK platforms ~5kb/s


android sdk download ~5kb per second
Android SDK and AVD Manager Stalling During Download : Google Groups
Android sdk download/update failing : Stack Overflow

How to speed up Android SDK platform download ?

1. Allow download over http : check the option in Settings section of Android SDK and AVD manager.
https
2. Disable/Deactivate your antivirus application.
Recommended at : Adding SDK Components page

Caution: Before you install SDK components, we recommend that you disable any antivirus software that may be running on your computer. There are cases in which antivirus software on Windows is known to interfere with the installation process, so we suggest you disable your antivirus until installation is complete.

After allowing download over http and deactivating antivirus, my download speed increased to around 20kb/s. Still not good but better than ~5kb/s

android sdk download 20kb per second
3. Or you can prefer offline Android SDK component download option :
Stackoverflow: Download the Android SDK components for offline install 
(direct link to post describing offline download procedure)
Hope this helps save some of your android sdk platforms download time.


After download you can start with following Hello World android tutorials.

Android Hello world tutorials:

Hello, World – Android developers
http://developer.android.com/resources/tutorials/hello-world.html
Android Development Tutorial - Gingerbread
http://www.vogella.de/articles/Android/article.html


Or grab this book:




Cheers!

Monday, March 7, 2011

PHP Short Tag : Avoid Them

PHP Short Tag: 

it  look like this:

<?   ?>

<?= $var ?>

obvious ones:

<?php  ?>

<?php echo $var ?>.

I downloaded an open source php script, thinking to work it out for my own purpose – but what sucks is - the project uses short tag that my host doesn’t *seems* to provide support for. For the testing purpose i needed to TOGGLE the short tag on/off switch in php.ini

How to enable PHP Short Tag ?

Open your php.ini file in your favorite editor.

Here’s what it says in line number 214 through 226

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
; short_open_tag = Off

Now change the short_open_tag = Off  to (remove semicolon)

short_open_tag = On

Restart Apache or XAMPP or your WAMPP installation

but here’s a big BUT below

 

Why you should avoid using PHP Short Tag ?

Stackoverflow : Answer

Normally you write PHP like so: <?php PHP CODE HERE ?>. However if *allow_short_tags* directive is enabled you're able to use: <? PHP CODE HERE ?>. Also sort tags provides extra syntax: <?= $var ?> which is equal to <?php echo $var ?>.

Short tags might seem cool but they're not. They causes only more problems. Oh... and IIRC they'll be removed from PHP6.

Stackoverflow: Answer

They're not recommended because it's a PITA if you ever have to move your code to a server where it's not supported (and you can't enable it). As you say, lots of shared hosts do support shorttags but "lots" isn't all of them. If you want to share your scripts, it's best to use the full syntax.

I agree that <? and <?= are easier on programmers than <?php and <?php echo but it is possible to do a bulk find-and-replace as long as you use the same form each time (and don't chuck in spaces (eg: <? php or <? =)

I don't buy readability as a reason at all. Most serious developers have the option of syntax highlighting available to them

 

Use it if :

  • you own a server and don’t care whether shared server support short tag or not
  • you don’t care what community says
  • you don’t want to Open Source your code later

<?php

/*

Oh please, don’t ask another question on stackoverflow about how to disable PHP Short Tag.

Rather you may want to write a parser that will loop through your 500+ php source code files and replace this Pain In The Ass PHP Short Tag to Normal PHP tag and share us the link. Here’s hint.

*/

?>

Sunday, March 6, 2011

Wordpress Themes / Templates - Useful Codes

Here are few fairly basic but handy wordpress codes that a wordpress theme or template developer/designers could use as reference. i personally use these a lot while working with wordpress.

 

Wordpress Site Name:

<?php bloginfo('name'); ?>

 

Wordpress Site Description:

<?php bloginfo('description'); ?>

 

Wordopress: Home Page Link:


<a href="<?php get_option('home'); ?>">Home</a></p>
or
<a href="<?php bloginfo('url'); ?>">Home</a>

 

Wordpress : Navigation – Display List of Pages in <li>

<?php wp_list_pages('title_li=&depth=1&exclude=2,7'); ?>

 

Wordpress Theme/Template Path:

<link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('template_url');?>/css/screen.css" />

 

Wordpress : Inside The Loop

<?php the_permalink() ?>
<?php the_title_attribute(); ?>
Post time: <?php the_time('F jS, Y') ?>
Post Author: <?php the_author() ?>
Post Content: <?php the_content('Read the rest of this entry &raquo;'); ?>
Post Tags: <?php the_tags('Tags: ', ', ', '<br />'); ?>
Post Category: <?php the_category(', ') ?>
Post Edit Link: <?php edit_post_link('Edit', '', ' | '); ?>

 

Wordpress: Display Specific Page/Post Content

display specific  page content with page name

<?php query_posts('pagename=pname'); //pname = your page name?>
<?php while (have_posts()) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<p>
<?php the_content() ?>
</p>    
<?php endwhile; ?>

 display specific  page content with using page_id

<?php query_posts('page_id=1'); //put page id of Home or Stations  in your case?>
<?php while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<p>
<?php
the_content('Read the rest of this entry &raquo;')
?>
</p>
<?php endwhile; ?>

display specific  post content using post id

<?php
// retrieve one post with an ID of 5
query_posts( 'p=5' );
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// the Loop
while (have_posts()) : the_post();
the_content( 'Read the full post »' );
endwhile;
?>

 

Wordpress : Get Custom Value

<?php
$cvalArr = get_post_custom_values("custom-val");   
$cval = $cvalArr[0];     
echo $cval
?>

 

Wordpress : Display X Latest Post from Category Y

<?php query_posts('posts_per_page=5&cat=2');
//post_per_page = number of post to grab
//cat = 2 –> from category 2, find your category id from admin
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php //the_title(); ?>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" title="Read full view of
<?php the_title_attribute(); ?>">Read more</a>
<?php endwhile; wp_reset_query(); ?>

i am thinking to put series of posts live describing wordpress development, let’s see.

Refs: Codex, Wordpress

http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Function_Reference/WP_Query