Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Dan Berlyoung

print_r() for Actionscript

Here's a cheap little function to mimic the print_r() function from PHP in Actionscript. It's designed to work on most any array and will handle nested arrays through recursion.
//
// recursive function to print out the contents of an array similar to the PHP print_r() funciton
//
function print_a( obj, indent ) {
	if (indent == null) indent = "";
	var out = "";
	for ( item in obj ) {
		if (typeof( obj[item] ) == "object" )
			out += indent+"[" + item + "] => Object\n";
		else
			out += indent+"[" + item + "] => " + obj[item]+"\n";
		out += print_a( obj[item], indent+"   " );
	}
	return out;
}
// example call
trace( print_a( example_array ) );

Collapse Whitespace function for Actionscript

This function will strip out all tabs and return characters. It will also collapse all runs of multiple spaces down to one. It will also remove a leading and trailing spaces. It is similar to the php_strip_whiespace() function in PHP.

function collapseWhiteSpace( theString ) {
	theString =  theString.split("\r").join("");
	theString =  theString.split("\t").join("");
	while ( theString.indexOf("  " ) != -1 ) {
		theString= theString.split("  ").join(" ");
	}
	if (theString.substr(0,1) == " ") {
		theString = theString.substr( 1 );
	}
	if (theString.substr( theString.length-1, 1 ) == " ") {
		theString = theString.substr( 0, theString.length - 1 );
	}
	return( theString );
}

Parse out body content from html file in PHP

Parse out the body content of an html file. If no tags found, assume whole file is the content to be used.

	$body_content = join( "", file( $file_to_be_read ) );
	if (eregi( "<body.*>(.*)</body>", $t, $regs ) ) {
		$body_content = $regs[0];
	}

Reverse DNS from command line

Quick and easy way to look up a domain name given an IP address.

dig -x 17.254.3.183


Retreiving a Flash movie's domain name

Use the LocalConnection object to get the domain name of the server where the Flash movie is located.

var localDomainLC:LocalConneciton = new LocalConnection();
myDomainName = localDomainLC.domain();
trace( "My domain is " + myDomainName );



This will print out something like this:

My domain is example.com


Search for open files that won't allow you to unmount a server volume

lsof | grep "Office Server"

Lists out all open files on a given volume ("Office Server" in this case.) Good to find those peskey open files that won't let you eject a mounted network volume.