Thursday, March 31, 2011

Congratulations : Google Nepal

What is Google ?

Google Inc. is an American multinational public corporation invested in Internet search, cloud computing, and advertising technologies. Google hosts and develops a number of Internet-based services and products, and generates profit primarily from advertising through its AdWords program. The company was founded by Larry Page and Sergey Brin, often dubbed the "Google Guys", while the two were attending Stanford University as Ph.D. candidates. It was first incorporated as a privately held company on September 4, 1998, and its initial public offering followed on August 19, 2004. At that time Larry Page, Sergey Brin, and Eric Schmidt agreed to work together at Google for twenty years, until the year 2024. The company's mission statement from the outset was "to organize the world's information and make it universally accessible and useful", and the company's unofficial slogan – coined by Google engineer Paul Buchheit – is "Don't be evil". In 2006, the company moved to its current headquarters in Mountain View, California.

Google runs over one million servers in data centers around the world, and processes over one billion search requests and about twenty-four petabytes of user-generated data every day.  Source : Wiki

Google’s Philosophy : Ten things

“The perfect search engine,” says co–founder Larry Page, “would understand exactly what you mean and give back exactly what you want.” When Google began, you would have been pleasantly surprised to enter a search query and immediately find the right answer. Google became successful precisely because we were better and faster at finding the right answer than other search engines at the time.

Following principles are what guides Google’s actions:

1. Focus on the user and all else will follow.
2. It’s best to do one thing really, really well.
3.Fast is better than slow.
4.Democracy on the web works.
5.You don’t need to be at your desk to need an answer.
6.You can make money without doing evil.
7.There’s always more information out there.
8.The need for information crosses all borders.
9.You can be serious without a suit.
10.Great just isn’t good enough.

To read details about how these 10 principles guide Google on its decision please visit the following URL  : http://www.google.com/corporate/tenthings.html

Google offices

Guided by those fundamental principles for its “every decisions”, Google till now has expanded its office locations to most of the countries of the world except Nepal and few others.

 google-nepal

We were worried about why there is no Google office in Nepal till last week. Oh, yes, here is a Good message. It all started June last year.

Congratulations

google-nepal-logo

Google Nepal Address:

New Baneshwor,
House Number : 53,
Google Marg, Kathmandu, Nepal
Phone: 01-042011
Contact Person: John Doe Google

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