a non-geek's blog

Random notes on linux and web development

20 tips to become a better PHP Programmer

leave a comment »

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

Written by nongeekboy

December 16, 2010 at 10:24 am

Posted in php

Tagged with , , ,

Playing with CenterIM, a command line instant messenger

leave a comment »

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 »

Written by nongeekboy

November 29, 2010 at 4:21 pm

Top 10 torrent clients for linux

with 38 comments

Two years ago I wrote an article about the best 5 torrent clients for linux. In the open-source world, two years means a lot of time. So, here it is an updated and enlarged list :

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.

[Homepage] [Download]

  • Written in: Python & C++
  • Library: libtorrent (Rasterbar version)
  • Last release: 1.3.0  2010/09/13
  • Interface: GUI (GTK),  Web, CLI, Daemon
  • Encryption: Yes
  • Mainline DHT: Yes
  • Magnet link: Yes
  • Peer Exchange: Yes
  • UPnP: Yes
  • NAT: Yes
  • Local Peer Discovery: Yes
  • IPv6 support: Yes
  • Super Seeding: No
  • Selective downloads: Yes
  • Search engine: Yes
  • RSS: Yes (via plugin)
  • Remote control: Yes
  • Prioritization: Yes
  • Proxy: Yes

Read the rest of this entry »

Written by nongeekboy

September 14, 2010 at 1:48 pm

A simple solution for “image not available” problem

with one comment

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.

Bookmark and Share

Written by nongeekboy

April 29, 2010 at 9:31 am

Posted in HTML, JavaScript

Tagged with ,

PHP: Functions with arbitrary number of arguments

leave a comment »

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.

Bookmark and Share

Written by nongeekboy

April 28, 2010 at 5:43 pm

Posted in php

Tagged with , ,

DOJO: Opening menu item on mouseover when using dijit.MenuBar

with 5 comments

I’m using dojo at the project I’m working on now. One of the problems I encounter when  was how  to make the menu open when mouse over it.  I found a solution on the dojo maillist. Here is the function that does the “magic”:

dijit._MenuBase.prototype.onItemHover = function(item){

       this.focusChild(item);

       if(this.focusedChild.popup && !this.focusedChild.disabled){
            this._openPopup();
       }
};

Source: here

Bookmark and Share

Written by nongeekboy

April 27, 2010 at 11:57 am

Posted in dojo

Tagged with , ,

How would you describe a linux geek father?

with one comment

Maybe this short clip could be the best answer:

Written by nongeekboy

August 21, 2009 at 8:19 am

Posted in fun

Follow

Get every new post delivered to your Inbox.

Join 201 other followers