Check For Loaded PHP Extensions

Sometimes you want to make sure a certain php extension is loaded or not. These extension can be curl, xmlrpc, or ldap. After all when you move your application from one server to another the configuration not necessarily the same. So here how you do check for loaded or existing php extensions using get_loaded_extensions().


$extNeeded = array('ldap', 'mysql', 'xmlrpc','ron_ext');
$loadedExtension = get_loaded_extensions();
foreach($extNeeded as $ext){ 
 if(!in_array($ext, $loadedExtension)){
  echo 'The application cannot start properly, '.$ext.' extension is missing. 
  The following extensions are needed: '.implode(', ', $extNeeded).'. 
  Terminating application ...';
  die;
 }
}

Extending an Existing Javascript Function

Extending an existing javascript function

This is how you extend an existing javascript function.
Assuming that you want to preserve the existing function and the “added algorithm” is somewhat only needed to be executed based on a certain environment only.


function abc(){
  alert('abc is called');       
}      
var abcOrig = abc;
abc = function(){
  abcOrig();
  alert('abc has been extended!');
}
alert('test 1');
abc();
alert('test 2');
abc();      

Map Network Drive using DOS command

Create a batch file named “mapdrive.bat”
Write the following text into its content


REM Map network Drive
net use j: \\server1\john_music
net use p: \\server2\pdfs
pause

Explaination:
Line 1 is to create a comment
Line 2 (similar with line 3) is to map a network folder \\server1\john_music to drive J:>
Line 4 is to pause the DOS window so it won’t close automatically

Super Powerful Debugging Function in Javascript

Super powerful debugging function in javascript. This function will output your variable in question to firebug console or html page.
With this function you can debug anything from Object, array, string, integer, etc. It is also recursive safe.


/**
 * @author: Ronald Pringadi, 2011
 * @desc: to debug a JavaScript Object
 * @usage: debug(yourObject);  
 * or debug(yourString); 
 * or debug(yourArray);  
 * @param object vTraceObject
 * @param string vPadding
 * @param object vPadding
 * 
 */

function debug(vTraceObject, vPadding, vPreviousTraceObject) {
	'use strict';

	function getObjectClass(vObj) {

		if (vObj && vObj.constructor && vObj.constructor.toString) {
			var arr = vObj.constructor.toString().match(/function\s*(\w+)/);
			if (arr && arr.length === 2) {
				return arr[1];
			}
		}
		return undefined;
	}
	function typeOf(vObj) {

		var vResult = typeof vObj;
		if (vResult === 'object') {
			try {
				if (vObj.length !== undefined) {
					vResult = 'array';
				}
			} catch (e) {
			}
		}

		return vResult;
	}	
	function print(vPadding, vType, vValue) {

		if (vPadding === undefined) {
			vPadding = '';
		}
		if (vType === undefined) {
			vType = '';
		}
		if (vValue === undefined) {
			vValue = '';
		}
		try{
			console.log(vPadding + ' (' + vType + '): ' + vValue + "\n");
		}catch(e){
			document.write(vPadding + ' (' + vType + '): ' + vValue + "\n");
		}
		
	}	

	if (vPadding === '' || vPadding === undefined) {
		vPadding = '';
	}
	if (typeOf(vTraceObject) === 'object'
			&& typeOf(vPreviousTraceObject) === 'object') {
		if (getObjectClass(vPreviousTraceObject) === getObjectClass(vTraceObject)) {
			print(vPadding, 'ERROR', 'RECURSION EXISTING ...');
			return null;
		}
	}

	var vType = typeOf(vTraceObject);
	if (vType === 'object' || vType === 'array') {
		if (vPadding === '') {
			print(vPadding, vType, '...');
			vPadding = '----';

		}
		try {
			var vTempType = '';
			var variable = '';
			for (variable in vTraceObject) {
				vTempType = typeOf(vTraceObject[variable]);
				if (vTempType === 'object' || vTempType === 'array') {
					print(vPadding, vTempType, variable);
					debug(vTraceObject[variable], vPadding + '----',
							vTraceObject);
				} else {
					print(vPadding, vTempType, variable + ' : '
							+ vTraceObject[variable]);
				}
			}
		} catch (e) {
			print(vPadding, 'ERR', 'EXCEPTION');
		}
	} else {
		print(vPadding, vType, vTraceObject);

	}


}

function objA() {
	this.varA1 = 'a1';
	this.varA2 = 'a2';
	this.myCars = new Array();
	this.myCars[0] = "Saab";
	this.myCars[1] = "Volvo";
	this.myCars[2] = "BMW";
}

function objB() {
	this.varB1 = 'b1';
	this.varB2 = 'b2';
	this.varB3 = new objA;

}
instanceB = new objB;

Output

(object): ...
---- (string): varB1 : b1
---- (string): varB2 : b2
---- (object): varB3
-------- (string): varA1 : a1
-------- (string): varA2 : a2
-------- (array): myCars
------------ (string): 0 : Saab
------------ (string): 1 : Volvo
------------ (string): 2 : BMW

Storage Speed Benchmark Using CrystalDiskMark

I have always been an enthusiast in computer hardware benchmark. Lately I been trying to increase my overall PC performance (both laptop and desktop).
A speedy and responsive system does not only take a fast processor, but also enough RAM and good harddrive.
CrystalDiskMark is one of the free benchmarking tool that you can download from http://crystalmark.info.

I have benchmark various storage media with CrystalDiskMark, my hard drives, USB flash drives, SD cards. And the table below will show you the result.
Most of the time my CrystalDiskMark setting is set at max 50MB test and run 3x. CrystalDiskMark will avarage the result

Type Maker Unit Capacity Sequential Read (MB/s) Sequential Write (MB/s) Random Read 512KB (MB/s) Random Write 512KB (MB/s) Random Read 4KB (MB/s) Random Write 4KB (MB/s)
SD Card AData 2GB 4.223 1.319 4.207 1.132 3.233 0.016
SD Card Memorette 2GB 4.085 4.213 4.128 1.357 2.801 0.014
SDHC Card Lexar 2GB 4.240 6.360 4.231 2.246 3.465 0.029
3.5″ hard disk over an eSata Enclosure Western Digital WD1502FAEX 1.5 TB 102.267 99.281 56.421 71.049 1.117 1.717
USB Flash drive Verbatim 2 GB 12.696 4.537 12.584 1.358 5.425 0.030
3.5″ hard disk Seagate ST3320620NS 320.0 GB 52.890 47.749 32.586 31.949 0.604 1.112
2.5″ hard disk over USB2.0 Enclosure Seagate ST9500420AS 500GB 16MB Cache 33.141 29.265 20.262 26.809 0.479 1.067
2.5″ hard disk Seagate ST9500420AS 500GB 16MB Cache 97.769 85.319 44.833 26.809 0.681 1.139
2.5″ hard disk Seagate ST95005620AS Momentus XT 500GB + 32 MB Cache + 4GB SSD 97.572 95.051 60.792 107.489 1.050 0.751
2.5″ hard disk Western Digital WD5000BEVT – 00A0RT0 500GB 70.775 74.614 23.257 41.557 0.446 1.256
2.5″ SSD Crucial M4 SSD 128GB 256.4 171.3 226.3 142.5 14.15 20.83
3.5″ hard disk inside VMWare Workstation Western Digital WD5000BEVT – 00A0RT0 500GB 32.018 24.076 9.777 16.341 0.101 0.753

Fix Microsoft Mouse in Linux Ubuntu

nano /etc/X11/xorg.conf

Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
# Option "Device" "/dev/input/mice"
Option "Protocol" "ExplorerPS/2"
Option "Emulate3Buttons" "false"
Option "ZAxisMapping" "4 5"
Option "ButtonMapping" "1 2 3 6 7"
EndSection

Colorize Linux Shell Menu

Do you ever feel like you’re going blind because the prompt text color and the result text color are the same?
We here is how to colorize your shell menu

Open your favorite text editor vim or nano, and add this at the end

$ nano ~/.bashrc
PS1='\[\e[1;32m\][\u@\h \t \w]\$\[\e[0m\] '

0;30 black
0;31 light red
0;32 light green
0;33 light yellow
0;34 light blue
0;35 light purple
0;36 light cyan

Edit default Gnome-Terminal

Every time I open a shell terminal in my Ubuntu, I always think that the window size is too small. I always ended up resizing the shell window manually using the mouse. I you’re having this problem here is how to fix it permanently.
gnome-terminal --geometry=80x25 -x /home/janne/.adom/adom