Want the best way to trim a sting in javascript?
A while ago, I came across a post on such a subject. It was written a few years ago but it’s still as relevant and useful as ever.
Want the best way to trim a sting in javascript?
A while ago, I came across a post on such a subject. It was written a few years ago but it’s still as relevant and useful as ever.
Something that has bugged me recently is that when I go to proxy on a particular port, the port is already in use and I get the following error.
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 8090
Could not request local forwarding.
Weiterlesen „Find process using port number in Bash“
I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable.
This tool will help code meet the indentation rules in the WordPress coding standards.
Weiterlesen „Tidy assignments in Coda and TextWrangler“
This is a super simple command but there is something about the following sequence of characters that I simply cannot retain in my brain.
Weiterlesen „Debugging PHP by monitoring errors in terminal“
Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors.
[source language=“php“]
/**
* Takes XML string and returns a boolean result where valid XML returns true
*/
function is_valid_xml ( $xml ) {
libxml_use_internal_errors( true );
$doc = new DOMDocument(‚1.0‘, ‚utf-8‘);
$doc->loadXML( $xml );
$errors = libxml_get_errors();
return empty( $errors );
}
[/source]
Here is a function to find duplicate items in an array.
[source language=“php“]
/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}
[/source]
Neat way of removing excess whitespace and tabbing from strings.
[source language=“php“]
$string = "Tom\tThumb\t is sooooooo\t\t\tdumb";
$string = preg_replace( ‚/\s+/‘, ‚ ‚, $string );
echo $string;
//will echo "Tom Thumb is sooooooo dumb"
[/source]
If you want to convert comma separated values into an associated array, then use the following code.
Weiterlesen „Convert CSV data into an associative array“
Excellent post from one of my favourite sites – Become a command line ninja with these time saving shortcuts
Simple one. If you need to add/remove escape slashes to/from a string, use the following code.
Weiterlesen „Addslashes and stripslashes in Javascript“