Dec 25 2009

Good Practices in PHP

Here are a few tips for those of you who’d like to write good code in PHP:

Set up a Development Server

Set up a development server or sandbox. Don’t write, test, or develop code on a production server. If you are a *nix user, you probably already have a LAMP environment on your own computer. If you are a Windows user, try XAMPP or WAMPSERVER (personal favorite). If you are on mac, try MAMP.

As you develop your PHP, you will need to be learning about the environment which it runs in, and the settings that will affect your code and/or application. This is a journey, so don’t expect to master it all at once. You will get into things like virtual hosts, .htaccess files, rewrite rules, and file permissions.

Turn on Error Reporting

At least, on your development server. On your production site, turn off displaying errors, but have them sent to a file. Check this file periodically as it will show you what unexpected things are happening in your code.

Do’s and Don’t’s

Don’t use short codes. They take longer to type, but PHP will be moving away from them in future versions. Also, the <? syntax can be mistaken for XML. Examples of short codes include <? instead of <?php, and also the syntax <?= $var ?> which is the easy way of writing <?php echo $var; ?>

Do use comments and document your code.

Don’t use a closing ?> at the end of your PHP files. Just leave it off – it is not required and it keeps you from accidentally having white space under your closing ?> so that headers, sessions, and cookies don’t get messed up.

Do use the latest version of PHP possible for developing applications. Right now the most common version / latest stable version of PHP is 5.2.8. While 5.3.x is out, there were some major changes many hosting companies and server admins have not completely adapted to, yet. Some of these deal with symlinks / softlinks / junctions and how the code is parsed. So, always try and use the latest commonly-adopted version.

Do use a versioning software of some sort (SVN, CVS, or GIT)


Dec 23 2009

WPtouch iPhone Theme

“With a single click, WPtouch transforms your WordPress blog into an iPhone application-style theme, complete with ajax loading articles and effects, when viewed from an iPhone, iPod touch, Android or BlackBerry touch mobile device.”

Basically, this plugin will take your Wordpress 2.7+ blog and check the HTTP headers to find out if the user’s browser is a mobile phone or iPhone, etc. Then, instead of serving up your normal theme, s/he is given a cool iPhone style interface to navigate your blog.

It’s really quite cool and it takes care of some issues regarding small screen size browsing. It didn’t disable some of my plugins, however, which use javascript, (for example, the snow falling script) which seem to give the iPhone’s processor  a little bit of trouble (lots of math for that script).

Over, I like it.


Dec 22 2009

TIOBE Language Popularity

As of December 2009- Java, C, and PHP are the top three languages.

See the full index


Dec 21 2009

google donates $20 million to charity

google donates $20 million to charity for Christmas / Holiday 2009 season

Quote:

“Because charities are experiencing their toughest year in decades, we have committed $20 million to helping those who help us all. Our gift to you is a gift to them. Happy Holidays” – From Google

View their page

Google will be donating to these organizations:

  • Feeding America
  • Boys and Girls Clubs
  • Smile Train
  • CARE, Mothers Matter
  • World Wildlife Fund, Natural Capital Project
  • Mobile Creches
  • Prajwala
  • HEAL Africa
  • African Institute for Mathematical Sciences
  • The Mango Tree
  • National Center for Missing and Exploited Children
  • Harlem Children’s Zone
  • Save the Children, Latin America focus
  • Reporters Without Borders
  • Witness
  • Loud Against Nazis
  • Global Voices
  • Ushahidi
  • Save the Children, Middle East and Eurasia focus
  • Grupo Cultural Afro Reaggae
  • Ashesi University College, Ghana
  • Pratham
  • Australian Indigenous Mentoring Experience
  • Shin Shin Educational Foundation
  • Tzu Chi Foundation

Oct 10 2009

Your tech lesson of the day: 301 Redirects

What is a 301 redirect?

The HTTP standard defines several status codes for redirection:
* 300 multiple choices (e.g. offer different languages)
* 301 moved permanently
* 302 found (originally temporary redirect, but now commonly used to specify redirection for unspecified reason)
* 303 see other (e.g. for results of cgi-scripts)
* 307 temporary redirect

Why do you want to use 301 redirects when possible?

Google will transfer your existing search rankings and good keywords. Users will arrive at the new site seamlessly.

How to do you create a 301 redirect?

What is different about a meta refresh tag or javascript redirect


A meta refresh tag or ( <meta http-equiv=”refresh” content=”0;url=http://www.google.com/”> ) a javascript redirect (window.location = http://google.com) waits for the window content to load, then tells the browser to go to the new location.
A 301 redirect will send the user along to the new location before any content is served by using http headers.

Why should you avoid meta refresh / javascript?

Googlle bots don’t have javascript enabled. They don’t follow meta refresh pages. And your users will actually see the old page load, depending on how quick their browser is. It’s just not a great way to do a redirect, but sometimes the server doesn’t have the capability to give a 301, or you don’t have admin privileges to set one up.

Can you give me an example of a .htaccess file redirect?

The file will look like this:
RewriteEngine on
RewriteRule (.*) http://www.newsite.com/ [R=301,L]

What does that mean?


  1. turn on the apache rewrite module
  2. (.*) is a regular expression which means any character, any number of times, or basically, everything
  3. followed by the site it should go to
  4. and R=301 sets the 301 code. L means it’s the last rule that applies, don’t look for any more rules

Why are we getting rid of GoDaddy?

In addition to being a slow host for wordpress, GoDaddy only reads the .htaccess files once every few hours. This makes it VERY difficult to know if your .htaccess file has errors, and if it does have errors you site may not work for a few hours. By comparison, other hosts read the .htaccess file on every page load. This is the way it’s supposed to be done.
Hostnine has a lot better control panel for managing all of the domains. In addition, they have the cPanel which makes maintaining individual domains a lot easier.


Sep 1 2009

Increase Gmail search result count (from 20)

Are you frustrated that when you search g-mail there are only 20 results that show up at a time? It’s quite difficult to review, mark, and move messages when the search results are limited to 20 messages.

Does it make sense that a “search company” which offers GIGABYTES of storage in their e-mail system limits your result count to 20? No. Of course not.

Visit the GMAIL SUGGESTIONS PAGE and choose the second one from the bottom “Better message search functionality” – also, possibly choose the dropdown box at the bottom, select OTHER, and tell google you want more than 20 results! :)

gmail_limited_search_results


Jul 23 2009

Fit-PC 2 nettop stays slim, gets an Atom upgrade

clipped from www.engadget.com

The original Fit-PC slim may have been able to proclaim itself the “world’s smallest,” but with an 500MHz AMD Geode processor and no more than 512MB of RAM, it had a bit of difficulty with the “PC” side of the equation. Fit-PC looks to have gone some way towards improving that with its new Fit-PC 2, however, which matches the current nettop ranks by adding your choice of an Atom Z530 or Z510 processor. Otherwise, you can expect the usual 1GB of RAM, your choice of 2.5-inch SATA hard drive, built-in WiFi, a generous six USB ports, HDMI out, XP or Ubuntu for an OS, and support for full 1,920 x 1,080 resolution. From the looks of it, this one is just starting to roll out now, and will set you back between $245 and $400 depending on the configuration. Still looking for more? Then head on past the break for a quick hands-on video.


Jul 9 2009

Google to reveal PC operating system

clipped from www.watoday.com.au
  • July 8, 2009

Google will on Wednesday announce plans for a personal computer operating system, the New York Times reported, in what will be another clash between the Internet search king and software giant Microsoft.

Details on the system were unavailable, other than it would be based on Google’s Chrome browser.

The Mountain View, California company was set to make the announcement on its blog later on Wednesday, the Times said, citing sources briefed on the plans.

Chrome was launched in September but has failed to enjoy the spectacular success of Google’s search engine.

The company floated its first US television advertisements in recent months for the browser, which has captured just a tiny share of a market dominated by Microsoft’s Internet Explorer.

Microsoft’s new search engine Bing was launched in a bid to hit back at Google’s gains in the search market, but still lags behind its rival.


Jun 21 2009

“What Exactly is a ‘Mashup’?”

clipped from netforbeginners.about.com

You hear this “mashup” expression being used by techie friends of yours. They talk about “oh, that is such an awesome mashup”. But what exactly does “mashup” mean?

“Mashup” comes from the term “mashed potatoes”, but is much more sophisticated. A “mashup” combines services from different websites into a single website. The intent is to give exceptional customer service to the reader by combining the best of two or more online software products.
Mashups are not new, by any means. The idea of combining multiple software API services (“application programming interfaces”) is decades old. In fact, your Microsoft Windows operating system is a perfect everyday example of mashup programming. But in the last few years, web site mashups have become a serious business for web programmers.

Jun 10 2009

Delicious Bookmarklet for Google Chrome

clipped from www.techlifeweb.com

chrome_bkmkbar2
Drag this link: Bookmark on Delicious up to your Bookmarks Toolbar similar to how it is shown above.