Sunday, October 7, 2012

Javascript: zerofill function

function zeroFill( number, width )
{
  width -= number.toString().length;
  if ( width > 0 )
  {
    return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
  }
  return number + ""; // always return a string
}

Resource:

Saturday, October 6, 2012

Javascript: calculating logarithm of a number in any base

Given that the javascript log() method returns the natural logarithm of the given number. You have to use the logarithms property using the natural logarithms. For example to calculate the log of x with 10 base or 2 base:


 So,


function log(val, x) {
  return Math.log(val) / Math.log(X);
}

where x is the base, and val is the number you want to calculate the logarithm.

Resources:
http://www.w3schools.com/jsref/jsref_log.asp
http://stackoverflow.com/questions/3019278/any-way-to-specify-the-base-of-math-log-in-javascript

Javascript: getting selected item


Html:

<select id="estadosiniciales">
                    <option value ="sydney">Sydney</option>
                    <option value ="melbourne">Melbourne</option>
                    <option value ="cromwell" selected>Cromwell</option>
                    <option value ="queenstown">Queenstown</option>
</select>

Javascript:


var selectIni = document.getElementById("estadosiniciales");      
alert(selectIni.options[selectIni.selectedIndex].text);


Resources:
http://www.java2s.com/Tutorial/JavaScript/0200__Form/Findtheselectedoption.htm

Javascript: adding options to select dynamically

Your html:


<select id="estadosiniciales">
                    <option value ="sydney">Sydney</option>
                    <option value ="melbourne">Melbourne</option>
                    <option value ="cromwell" selected>Cromwell</option>
                    <option value ="queenstown">Queenstown</option>
</select>

Your Javascript:


var newOption = new Option("newStateName","newStateName");
var selectIni = $("#estadosiniciales"); // using Jquery
selectIni.append(newOption)


Resources:
http://www.devguru.com/technologies/ecmascript/quickref/option.html
http://stackoverflow.com/questions/4647863/trouble-dynamically-adding-options-to-select

Wednesday, October 3, 2012

Eclipse: Svn error : RA layer request failed

If you get this error:

RA layer request failed
svn: Commit failed (details follow):
svn: PROPFIND request failed on '/repo/path/!svn/vcc/default'
svn: PROPFIND of '/repo/path/!svn/vcc/default': Could not read status line: connection was closed by server. (http://example.com)

Switch from JavaHL(JNI) to SVNKit(Pure Java) in Eclipse:

  1. in eclipse go to Help –> Install New Software…
  2. Work with: –> choose the community.polarion.com update site
  3. expand Subversive SVN Connectors
  4. choose the SVNKit version corresponding with your version of subversion
  5. click Next, and then follow the instructions to complete installation
  6. Window –> Preferences –> expand "Team" –> select "SVN" –> select the "SVN Connector" tab –> change the SVN Connector to SVNKit –> OK


Resource:
http://languor.us/eclipse-subversion-ra-layer-request-failed-could-not-read-status-line-errors

PHP: REST APl Sample

Here is a simple and great example of a REST API using PHP

http://coenraets.org/blog/2011/12/restful-services-with-jquery-php-and-the-slim-framework/

Windows 7 : Enable Telnet Client

When you try yo execute telnet command:


C:\Users\John>telnet localhost 80

You get:

'telnet' is not recognized as an internal or external command,
operable program or batch file.

Do this:


  1. Start
  2. Control Panel
  3. Programs And Features
  4. Turn Windows features on or off
  5. Check Telnet Client
  6. Click 'OK' button

After that you can start Telnet via Command Prompt.

Resource:
http://www.fettesps.com/windows-7-enable-telnet/