Temporarily Disable Flash in Firefox

Forefox Addon: How to Temporarily Disable Flash Player?
Is there any way to Temporarily Disable Flash Player in Firefox?

There is one website where manga scans are made delicious! Naruto, Bleach, One Piece, Claymore, Hana Kimi, Vampire Knight... it's all in there and more!
I always visit that website but they got these ads in Flash format, and they got all sorts of moving and flashing stuff. After seeing it several times, I came up with this question. Is there a way to turn it off and on?

Actually, I did rename the .DLL file used for Flash player and it stopped working, but I hate to have to do that everytime I use to visit that site,

Luckily, after googling for some answer, I found this two firefox extensions: FlashBlock and
AdBlock

FlashBlock does just what it's name suggests... This is great as long as you really don't want most flash to show up, but it does cause problems with some desired flash.

AdBlock will allow you to block the ad server who is responsible for the ads. Personally, I *love* AdBlock; I sometimes forget what webpages look like with ads...

What I like about AdBlock over FlashBlock is that it's only killing the advertising Flash files from ad servers that I've configured. I still get menus and other "wanted" flash content... just never any of the annoying flash ads. Whenever I come across a new advertising server, I block the iFrame with AdBlock, and never see the content again.

AdBlock is actually one of my favorite Firefox extension.

Just in case you were still using IE and want to disable flash , try this site...Works like a charm.

isset() vs strlen()

When working with strings and you need to check that the string is either of a certain length you’d understandably would want to use the strlen() function. This function is pretty quick since it’s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.

<?
if (strlen($foo) < 5) { echo "Foo is too short"; }
if (!isset(
$foo{5})) { echo "Foo is too short"; }
?>

Calling
isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it’s execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string’s length.

How to optimize your php codes

  1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
  2. echo is faster than print.
  3. Use echo's multiple parameters instead of string concatenation.
  4. Set the maxvalue for your for-loops before and not in the loop.
  5. Unset your variables to free memory, especially large arrays.
  6. Avoid magic like __get, __set, __autoload
  7. require_once() is expensive
  8. Use full paths in includes and requires, less time spent on resolving the OS paths.
  9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
  10. See if you can use strncasecmp, strpbrk and stripos instead of regex
  11. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4
  12. If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
  13. It's better to use switch statements than multi if, else if, statements.
  14. Error suppression with @ is very slow.
  15. Turn on apache's mod_deflate
  16. Close your database connections when you're done with them
  17. $row[’id’] is 7 times faster than $row[id]
  18. Error messages are expensive
  19. Do not use functions inside of for loop, such as for ($x=0; $x <>
  20. Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
  21. Incrementing a global variable is 2 times slow than a local var.
  22. Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
  23. Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
  24. Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
  25. Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
  26. Methods in derived classes run faster than ones defined in the base class.
  27. A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.
  28. Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.
  29. When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
  30. A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.
  31. Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.
  32. Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request
  33. When working with strings and you need to check that the string is either of a certain length you'd understandably would want to use the strlen() function. This function is pretty quick since it's operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.
    Ex.
    if (strlen($foo) < 5) { echo "Foo is too short"; }
    vs.
    if (!isset($foo{5})) { echo "Foo is too short"; }
    Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it's execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string's length.
    more about isset() vs strlen() here
  34. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.
  35. Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.
  36. Do not implement every data structure as a class, arrays are useful, too
  37. Don't split methods too much, think, which code you will really re-use
  38. You can always split the code of a method later, when needed
  39. Make use of the countless predefined functions
  40. If you have very time consuming functions in your code, consider writing them as C extensions
  41. Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview
  42. mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%
  43. Excellent Article about optimizing php by John Lim

Disclamer: This was article wasn't really mine, someone emailed this to me and I just found it useful.

$HTTP_SERVER_VARS

Basic surfer information variables (from HTTP_SERVER_VARS)
<?php
$surfer_info
[ip] $HTTP_SERVER_VARS["REMOTE_ADDR"];
// $surfer_info[real_ip] will only contain something if the surfer used a transparent proxy
$surfer_info[real_ip] $HTTP_SERVER_VARS["X_FORWARDED_FOR"];
$surfer_info[port] $HTTP_SERVER_VARS["REMOTE_PORT"];
$surfer_info[browser_lang] $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"];
$surfer_info[user_agent] $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
$surfer_info[request_path] $HTTP_SERVER_VARS["PATH_INFO"];
$surfer_info[request_query] $HTTP_SERVER_VARS["QUERY_STRING"];
$surfer_info[request_method] $HTTP_SERVER_VARS["REQUEST_METHOD"];
$surfer_info[http_referrer] $HTTP_SERVER_VARS["HTTP_REFERER"];
?>

It is just a row of variables, - it is up to you to decide how they are useful to your script and how to integrate them.
But if you want to see something happening any way, add

print_r($surfer_info);
to the bottom of the script (but before the closing ?>). Doing so will cause the script to show you what information the variables picked up.

Cross browser compatibility

BROWSERSHOTS.ORG
I use this site everytime i check my design. You can choose from a lot of browsers too. This site is amazing.

How the site works:
Browsershots makes screenshots of your web design in different browsers. It is a free open-source online service created by Johann C. Rocholl. When you submit your web address, it will be added to the job queue. A number of distributed computers will open your website in their browser. Then they will make screenshots and upload them to the central server where you can see the result.

Detecting Mobile Browsers in PHP

I used the following block of code to redirect  site to a page when it is been accessed via mobile phone browser and to another page when it is accessed  via desktop browsers. This is tested in  ie, firefox, netscape, opera, chrome and some mobile phone browser simulator. This works well for me.
<?
$site1
"http://coffeeandpaste.blogspot.com/";
$site2 "http://monkeetech.blogspot.com/";

$BrowserSplit explode("/",$HTTP_SERVER_VARS["HTTP_USER_AGENT"]);
$Machine $BrowserSplit[0];

if($Machine == "Opera" || $Machine == "Mozilla") {
header("location: $site1");
}
else {
header("location: $site2");
}
?>

The Windows-versus-Linux server face-off

San Francisco - Linux certainly has established itself as a prominent server OS these days, pushing Unix into the background. But the open source OS shares the stage with commercial software giant Microsoft, which remains a dominant player with Windows Server.

Gartner research published this month found the server OS market shaping up as a battle between Windows Server and Linux. Gartner in other research also has found both OSes on a growth track in terms of revenue. "There still seems to be plenty of robust interest in deploying on Windows, but Linux is still very key," says Gartner analyst George Weiss.

[ The InfoWorld Test Center rates Windows Server 2008. | Why Linux is greener than Windows Server. | Has Linux killed OpenSolaris? ]

A lot of Linux usage is in Web server applications, but it's become increasingly common in mission-critical applications, Weiss notes. But "I don't have an indicator that says Linux is chewing up the market for Windows," he adds.

Other forms of Unix continue to fade away in what is becoming a two-OS choice for IT. "The key here is that really Linux and Windows are moving away from the pack here and it's becoming a two-horse race," says Jim Zemlin, executive director of the Linux Foundation.

Both Linux and Windows Server see datacenter growth
Regarding migration of current workloads, 43 percent of respondents in a Gartner survey at a Linux-oriented conference anticipated migrating mostly from Unix to Linux, 13 percent said they would migrate mostly from Windows to Linux, and only 4 percent said they would switch off Linux to go to Windows. Twenty-one percent had no plans to migrate workloads.

Gartner expects IT organizations to shift their focus to more-complex Linux deployments and continue a trend of migration from Unix. Gartner found that 52 percent of respondents anticipate that the total workload of their Linux server environment will increase moderately in 2008; another 25 percent said there would be a substantial increase. Only 5 percent anticipated moderate decrease, while 4 percent expected a substantial decrease in Linux workloads for this year. Respondents were three times more likely to migrate workloads from Unix to Linux than from Windows to Linux.

Although Linux growth is strong, so is that of Windows Server, according to Gartner's research. Linux was ranked by 39 percent of respondents as the OS expected to have the most growth in their datacenters during the next five years. Windows was a close second, ranked as the OS with the most growth potential by 35 percent of respondents at the Linux-oriented conference.

Based on Gartner's annual estimates for worldwide server shipment revenues, both Windows Server and Linux will increase. Windows Server sales will move from about $20 billion last year to roughly $22 billion in 2012; Linux will grow from about $9 billion last year to $12 billion in three years. But because Linux is often provided at no cost (with vendors making revenues from support contracts and other services), those numbers may not be comparable.

Roy Schestowitz, an ardent supporter of Linux and ardent opponent of Microsoft who runs the Boycott Novell Web site, argues that Linux gets shortchanged in surveys on market share because only "sold" OSes are counted -- and often just those sold as part of server hardware by major companies such as Dell Computer, Hewlett-Packard, and IBM.

Is it really a race?
With both OSes growing, should IT be thinking of Linux and Windows Server as either/or propositions? No.

Linux provider Red Hat sees heterogeneity ruling the day, with users deploying both Linux and Windows Server. Linux already has a large base in Web deployments but is expected to move into high-end database and enterprise application deployments, says Nick Carr, Red Hat's marketing director. Windows, meanwhile, has a large base as a server for Exchange Server, SQL Server, and file and print deployments, he notes.

"Nobody has a sort of homogeneous world anymore," Carr notes. "People tend to think that one grows at the expense of the other but that's not what's happening at the moment." That's why Red Hat and Microsoft recently agreed to let Red Hat Linux users run Windows servers in virtual machines and let Windows Server users run Red Hat Linux in VMs. "Increasingly, such servers that run in mixed environments rely on virtualization," notes Linux proponent Schestowitz.

CRIS Camera Services is an example of the mixed Linux-Windows Server environment that will keep both OSes in demand. At CRIS, Linux gets the nod for running PHP, MySQL, and Apache software, says Josh Treadwell, the company's IT director. But it relies on Windows Server for its Microsoft Dynamics and SharePoint applications. And its use of Windows Server benefits from the wide availability of Windows training certifications. "We have found college education circles around Microsoft languages," he says, noting there is no central certification for Linux.

The cost question
Possible reasons for moving to Linux include antipathy toward Microsoft and the perception that Linux is cheaper in terms of license fees, says Gartner's Weiss. Linux has an inside track with startups as well as with larger ventures such as Google, he notes -- two environments where cost or "anyone but Microsoft" concerns are key.

But the Linux financial advantage may not be real, Weiss says. When adding up the numbers for Linux deployments in a larger scalable environment, he does not see much difference among Linux, Unix, and Windows once you factor in the costs to achieve high availability, implement a global file system, and get technical support. Also, equipment expenses are a wash between Linux and Windows, he says: "Windows and Linux can run on the same hardware."

The Linux Foundation's Zemlin argues that Linux is in fact cheaper to use than Windows. One reason is the lack of licensing costs for Linux. Another is that Linux runs across a much wider variety of systems than the predominantly Intel x86-based Windows platform, he says, so you get an economy of scale across a mix of hardware. In addition to x86 serves and blades, both of which run Windows, Zemlin notes that Linux runs on mainframes, IBM Power systems, and other Unix-oriented hardware. "Linux can be a very cost-effective common denominator among these systems, he contends.

Some organizations may see cost savings from running free, unsupported Linux distros, but Gartner's Weiss says that is foolishly dangerous. A major outage or security breach without immediate access to a Linux support provider can easily wipe out any money saved from relying only on yourself. (Windows Server support is also needed, and it too requires paying a support provider.)
[source]

Passing JavaScript variables to PHP

JavaScript is mainly used as a client side scripting language, while PHP is a server side technology. Unlike Java or ASP.Net, PHP doesn't have tools to make it work client side. That is why you need to combine JavaScript and PHP scripts to develop powerful web-applications.

One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:

<script type=&qout;text/javascript&qout;>

width = screen.width;
height = screen.height;

if (width > 0 && height >0) {
window.location.href = &qout;http://localhost/main.php?width=&qout; + width + &qout;&height=&qout; + height;
} else
exit();

</script>


Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.

The main.php looks as follows:

<?php
echo &qout;<h1>Screen Resolution:</h1>&qout;;
echo &qout;Width : &qout;.$_GET['width'].&qout;<br>&qout;;
echo &qout;Height : &qout;.$_GET['height'].&qout;<br>&qout;;
?>


As you can see, passing JavaScript variables in PHP is similar to sending data using GET method.

[source]

single-quote( ' ) vs double-quote ( " ) in PHP

Difference between single-quote( ' ) and double-quote ( " ) strings in php

Briefly:
In double-quoted strings, variables are replaced by their values:
PHP Code:
$word = "Hello".
echo "$word there!"

The above code will output:
Hello there!

Doing the same with single quotes:
PHP Code:
$word = "Hello".
echo '$word there!'

...will print:
$word there!

Using single quotes where possible, will be slightly more efficient to process, because PHP doesn't have to search single quoted strings for variables.

PHP Arrays

PHP Arrays provide a way to group together many variables such that they can be referenced and manipulated using a single variable. An array is, in many ways, a self-contained list of variables.

Once an array has been created items can be added, removed and modified, sorted and much more. The items in an array can be of any variable type, and an array can contain any mixture of data types - it is not necessary to have each element in the array of the same type.

Elements of an array are accessed using a key. There are two types of array, and the type of key that is used to access an array element dictates the array type. In a numerical key array, elements are accessed by specifying the numerical position of the item in the array. The first item in an array is element 0, the second is element 1 and so on. The second type of array is the associative array where a name is given to each element, and that name is used to access the corresponding array element.