Posts Tagged ‘javascript’

Facebook Thirteen Application

Posted in Software on June 12th, 2009 by Jamie – Be the first to comment

This application was written primarily as an exercise in creating Facebook Applications. It was very instructive! Here is the project blog if you’d like more details http://thirteengame.blogspot.com/.

It is an adaptation of a web app I originally wrote in 2007. You may play either by logging into Facebook and trying it out, or logging in here http://www.angelforge.org/thirteen/LoginPage.php. To login outside of Facebook, you may either use the user name and password guest or login with your Facebook credentials using Facebook Connect.

Javascript Gaussian/Banker’s Rounding

Posted in Libraries, Programming on April 16th, 2009 by Jamie – Be the first to comment

Here’s a function for Gaussian/Banker’s Rounding in Javascript adapted from code written by Michael Boon at http://boonedocks.net/.

This can be useful if you’re working with Microsoft languages such as VBScript, which use Banker’s Rounding by default in their Round function. Javascript has no built-in gaussian rounding and, instead, uses Arithmetic rounding. For more information on this, see Wikipedia’s article on rounding, specifically, the Round to Even section.

/*
    Adapted from <a href="http://boonedocks.net/code/bround.inc.phps">http://boonedocks.net/code/bround.inc.phps</a>
Provided under the GNU General Public License
    Contact me for use outside the bounds of that license

    ---------------------------------------------------------------
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    The GNU General Public License can be found at:

http://www.gnu.org/copyleft/gpl.html

*/
<a href="http://boonedocks.net/code/bround.inc.phps"></a>
Number.prototype.gaussianRound = Number.prototype.bankersRound = function bround(iDec) {
    return Math.gaussianRound ( this, iDec );
};

Math.gaussianRound = Math.bankersRound = function (dVal, iDec) {

    // banker's style rounding or round-half-even
    // (round down when even number is left of 5, otherwise round up)
    // dVal is value to round
    // iDec specifies number of decimal places to retain

    var
		dFuzz=0.00001, // to deal with floating-point precision loss
		iRoundup=0, // amount to round up by
		iSign= dVal != 0.0 ? Math.floor ( dVal/ Math.abs( dVal ) ) : 1;

	dVal=Math.abs(dVal);

    // get decimal digit in question and amount to right of it as a fraction
    dWorking = dVal * Math.pow ( 10.0, iDec + 1 ) -
		Math.floor ( dVal * Math.pow ( 10.0, iDec ) ) * 10.0;

	iEvenOddDigit =
		Math.floor ( dVal * Math.pow ( 10.0, iDec) ) -
		Math.floor ( dVal * Math.pow ( 10.0, iDec-1 ) ) * 10.0;

    if ( Math.abs ( dWorking - 5.0 ) &lt; dFuzz)
		iRoundup= iEvenOddDigit &amp; 1 ? 1 : 0; // even testing using bitwise and
    else
		iRoundup= dWorking &gt; 5.0 ? 1 : 0;

    return iSign * ( ( Math.floor ( dVal * Math.pow (10.0,iDec ) ) + iRoundup )/ Math.pow(10.0,iDec) );
};

JSXGraph

Posted in Libraries on March 24th, 2009 by Jamie – Be the first to comment

Awesome JS graphics library compatible with JQuery and Prototype.

JSXGraph » Examples

CiteThis! Firefox Extension

Posted in Software on September 1st, 2008 by Jamie – Be the first to comment

This extension will add a bar below the status bar that you may use to assist you in citing the web page you are on. There are other extensions which are more full featured, but this is plain and simple for many needs.

You can find the Mozilla page for this add-on at https://addons.mozilla.org/en-US/firefox/addon/7972.


Switch to our mobile site