20 tips to become a better PHP Programmer
If you are a beginner in PHP programming here are 20 tips that will help you to become a better PHP programmer (as suggested by Marc on his post on webgeekly.com):
1) Use <?php and ?>
2) Separate Configuration Files
3) Comment, comment, comment
4) Use Indentation and Spacing (don’t be cheap on whitespaces)
5) Give your Variables Meaningful Names
6) Initialize your Variables
7) Boolean is False, unless True
8) Using Quotes when accessing Array Keys
9) Use commas to echo different strings
10) Use Ternary Operators
11) Use === for Boolean Checks
12) Use ++ and — Operators
13) Use Assignment Operators
14) Create a Variable Dump Function
15) Use Constants
16) Use $_GET and $_POST, avoid $_REQUEST
17) If your function has lots of paramaters use objects instead of functions
18) Use Method Chaining
19) Stop Repeating Code
20) Aim for Loose Coupling, Strong Cohesion
For full post (and explaination) check 20 Tips you need to learn to become a better PHP Programmer
Playing with CenterIM, a command line instant messenger
When working in the terminal, I use a lot CenterIM, an instant messenger client. While Finch (Pidgin on ncurse) is more feature-rich than CenterIM and has almost all the plugins that Pidgin has, I prefer CenterIM because it has a very clean interface, offering you just what you need to communicate:
-a contact list
-a chat window
-a log window (I find it quite informative)
There is one function in Pidgin that I like a lot and that is the “Pounce” option (being announce with a pop-up when an user log off, log in or some other event you select). After reading the CenterIM Documentation, I found a very simple solution to implement this feature to my favorite command line IM client. So here it is: Read the rest of this entry »
Top 10 torrent clients for linux
GUI torrent clients:
1) Deluge
Deluge is a full-featured BitTorrent client written in python, for Linux, OS X, Unix and Windows. It uses libtorrent in it’s backend and features multiple user-interfaces including: GTK+, web and console. It has been designed using the client server model with a daemon process that handles all the bittorrent activity. The Deluge daemon is able to run on headless machines with the user-interfaces being able to connect remotely from any platform.
|
|
Read the rest of this entry »
A simple solution for “image not available” problem
Is there a simple solution for problems with missing or broken images? Yes, it is. You don’t need any script, just an alternate image to display when this problem occur and the “onerror” event available with the img element. Here is an example:
< img src="/path/to/image.jpg" height="100px" width="100px" onerror="this.src = '/path/to/alternate-image.png'" / >
This simple solution was posted by Satya on his web scripting blog. Anyway, if you preffer a more elegant solution, you could use a script that dynamically detects the missing images and replace them with an alternate image. A good Java Script solution is presented on the tech evangelisit’s article.
PHP: Functions with arbitrary number of arguments
Sometimes you may have to use a function with a variable number of arguments. Here is a simple method of passing a list of variables to a function:
function foo() {
// returns an array of all passed arguments
$args = func_get_args();
foreach ($args as $k => $v) {
echo "arg".($k+1).": $v\n";
}
}
foo();
/* prints nothing */
foo('hello');
/* prints
arg1: hello
*/
foo('hello', 'world', 'again');
/* prints
arg1: hello
arg2: world
arg3: again
*/
For more interesting functions and futures, read the 9 useful php functions and futures you need to know article on net.tutsplus.com.
How would you describe a linux geek father?
Maybe this short clip could be the best answer:
