Formats a Phone Number in Javascript

This really use function formats a phone number to look like this: (201) 248 1421

function formatPhone(v) {
    var fv1 = v.substring(0,3);
    var fv2 = v.substring(3,6);
    var fv3 = v.substring(6,10);
    return("("+fv1+") "+fv2+"-"+fv3);                      
}

Search for a String in an Array with Javascript

This snippet searches for a string value inside an array with Javascript. Usage example is inside the console.log.

Array.prototype.exists = function(search){
  for (var i=0; i<this.length; i++)
    if (this[i] == search) return true;
  return false;
}
console.log("does "+keyword+" exist in keywordsArray?" + keywordsArray.exists(keyword));

FadeIn() the Appending of HTML in jQuery

This is how you fadeIn() html content using the html() method available in jQuery:

$('#message').hide().html("You clicked on a checkbox.").fadeIn('slow');

Good PDF Online Editor

I found this useful its an online pdf editor! Very good for simple tasks such as editing text.

http://www.pdfescape.com/

Take Non-Alphanumerics Out of a String in Java

This java code snipped will take all non-alphamerics out of a string, every character EXCEPT for letters (upper and lower case), numbers AND a decimal. I made this to clean filenames and a period ‘.’ is what files use to decipher their extensions. If you want to take out the period also, remove it after the ’9′:

filename = filename.replaceAll("[^a-zA-Z0-9.]", "");

Setters and Getters in a PHP Class – Object Oriented PHP

This is a really cool example of how to make “setters” and “getters” in PHP. All of you Java programmers will be well versed in the ways of set and get. These can be very important to the entire structure of your application and are vital when designing a structure. Here we create a class called “team” which contains a private variable called “$position.”

class team {

    private $position;
   
    public function __set($key,$val) {
        $this->$key=$val;
    }
    public function __get($key) {
        return $this->$key;
    }
       
}

After creating your object (new team()) you can set “position” like this:

$t = new team();
$t->__set("position","striker");

This will set the position to striker in the object. Creating an object may seem to some to be only available in this current script (team.php for example), however it’s important to remember that if you save the object to a session, it will be available throughout your entire web app!

$_SESSION["teamObject"] = $t;

This truly demonstrates the power of OOP in web development. Without this ability, OOP would be redundant, and overly complicated in almost every case.

Find out if and which version of OpenSSL is installed

If you run this in a terminal on a *nix machine it will tell you what version you have installed, if it returns an error or nothing at all then it’s not installed!

openssl version

Chrome Extension Find Current Tabs URL

First, you have to set permissions in your manifest.json file:

"permissions": [
    "tabs"
]

The “getSelected” method gets the current selected tab, you can then access the URL of the current tab by using the “tab” object and specifying “url”. Remember that you can console.log the object to see everything that it contains!

    chrome.tabs.getSelected(null, function(tab) {
        myFunction(tab.url);
    });

    function myFunction(tablink) {
        // do stuff here
        console.log(tablink);
        $("#response2").html("Current TAB: "+tablink);

    }

Capitalize the First Letter of each Word in a String with Javascript

This example capitalizes the first letter of each word in a string in Javascript. Useful for auto-formatting text:

function capWord(str) {
        var val = str.split(' ');
        var newVal = "";
        for(var c=0; c < val.length; c++) {
           newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + ' ';
        }
        return newVal;
}

Get’s first two characters of string in javascript

This examples gets the first two characters of a given string in Javascript:

var commandPrefix = command.substring(0,2);