<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ramblings of a Geek - Jeremy Johnstone &#187; Javascript</title>
	<atom:link href="http://www.jeremyjohnstone.com/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jeremyjohnstone.com</link>
	<description>Ramblings of a Geek</description>
	<lastBuildDate>Wed, 28 Jul 2010 18:33:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wind Chill Calculator &#8212; In Javascript, Ruby, and PHP</title>
		<link>http://www.jeremyjohnstone.com/blog/2010-01-12-wind-chill-calculator-in-javascript-ruby-and-php.html</link>
		<comments>http://www.jeremyjohnstone.com/blog/2010-01-12-wind-chill-calculator-in-javascript-ruby-and-php.html#comments</comments>
		<pubDate>Tue, 12 Jan 2010 09:28:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wind chill]]></category>

		<guid isPermaLink="false">http://www.jeremyjohnstone.com/?p=1494</guid>
		<description><![CDATA[Since I spent the time to dig up the method of calculating the wind chill given a specific temperature and wind speed, I figured I would go ahead and share it in case someone else finds it useful. Here&#8217;s three functions for calculating the wind chill, one each for Javascript, PHP, and Ruby.

// Javascript version
// [...]]]></description>
			<content:encoded><![CDATA[<p>Since I spent the time to dig up the method of calculating the wind chill given a specific temperature and wind speed, I figured I would go ahead and share it in case someone else finds it useful. Here&#8217;s three functions for calculating the wind chill, one each for Javascript, PHP, and Ruby.</p>
<pre class="brush: js">
// Javascript version
// wind = wind speed in knots
// temp = temperature in Celsius
function getWindChill(wind, temp) {
   wind = wind * 1.852;
   var wind2 = Math.pow(wind, 0.16);
   var wind_chill = (13.12 + 0.6215 * temp - 11.37 * wind2 + 0.3965 * temp * wind2);
   wind_chill = parseFloat(wind_chill.toFixed(2));
   wind_chill = (wind <= 4.8) ? temp : wind_chill;
   wind_chill = (temp > 10) ? temp : wind_chill;
   return wind_chill;
}
</pre>
<pre class="brush: php">
// PHP version
// wind = wind speed in knots
// temp = temperature in Celsius
function getWindChill($wind, $temp) {
   $wind = $wind * 1.852;
   $wind2 = pow($wind, 0.16);
   $wind_chill = (13.12 + 0.6215 * $temp - 11.37 * $wind2 + 0.3965 * $temp * $wind2);
   $wind_chill = round($wind_chill, 2);
   $wind_chill = ($wind <= 4.8) ? $temp : $wind_chill;
   $wind_chill = ($temp > 10) ? $temp : $wind_chill;
   return $wind_chill;
}
</pre>
<pre class="brush: ruby">
# Ruby version
# wind = wind speed in knots
# temp = temperature in Celsius
def getWindChill(wind, temp)
   wind = (wind * 1.852)
   wind2 = wind**0.16
   wind_chill = (13.12 + 0.6215 * temp - 11.37 * wind2 + 0.3965 * temp * wind2)
   (temp > 10) ? temp : (wind <= 4.8) ? temp : (wind_chill * 100).round.to_f / 100
end
</pre>
<p>As you can see, pretty simple, but hopefully one will prove useful to someone someday.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremyjohnstone.com/blog/2010-01-12-wind-chill-calculator-in-javascript-ruby-and-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yahoo! Web Messenger Meets Fluid.app</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-04-04-yahoo-web-messenger-meets-fluidapp.html</link>
		<comments>http://www.jeremyjohnstone.com/blog/2008-04-04-yahoo-web-messenger-meets-fluidapp.html#comments</comments>
		<pubDate>Sat, 05 Apr 2008 03:14:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Fluid]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Messenger]]></category>

		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=365</guid>
		<description><![CDATA[This evening I decided to play with a really kewl new app called Fluid. What this app does is allow you to create Site Specific Browsers. One of the first usages which popped into mind was a product I helped develop, Yahoo! Web Messenger. An annoyance of mine with it is that it had to [...]]]></description>
			<content:encoded><![CDATA[<p>This evening I decided to play with a really kewl new app called <a href="http://fluidapp.com">Fluid</a>. What this app does is allow you to create <span class="afterthought" title="fancy name for a wrapper around a web based app to allow you to use it "outside" the browser, sorta kinda">Site Specific Browsers</span>. One of the first usages which popped into mind was a product I helped develop, <a href="http://web.im">Yahoo! Web Messenger</a>. An annoyance of mine with it is that it had to live in a browser tab, something prone to getting closed accidentally, and also didn&#8217;t have any <span class="afterthought" title="scrolling title bar in the browser doesn't count to me">decent notifications of new messages when not in focus</span>. Being the perfect candidate for Fluid, IMHO, I set out to give it a shot. In less than an hours time I built a pretty kewl demo and here&#8217;s how you can use it too. </p>
<ol>
<li>First things first, you need to download and install Fluid. You can do this by visiting <a href="http://fluidapp.com">http://fluidapp.com</a>. <span class="afterthought" title="if I have to explain how to do this, stop now, you are hopeless">After installing it</span>, fire up the app.</li>
<li>Second off, we now need to create our SSB instance. For the URL, enter in
<pre class="brush: plain; light: true">http://webmessenger.yahoo.com</pre>
<p> For the name use something like <em>Yahoo! Web.IM</em> or whatever else strikes your fancy. The icon you can download from <a href="http://www.jeremyjohnstone.com/images/cesario.png">here</a>. Click create and you are all set.</li>
<li>Next we can fire up the application. It should live inside your applications folder just like any other desktop app. You use <a href="http://www.blacktree.com/">Quicksilver</a> right?</li>
<li>Now that the app is running, you can see the normal login screen of Web.IM and if you like, sign in just as a test.</li>
<li>Next comes the real powerful part. We need to create a new &#8220;userscript&#8221; which will add advanced functionality over what a normal browser experience provides. We do this by clicking on the <b>Userscripts</b> menu and then selecting &#8220;New Userscripts&#8230;&#8221;, or you can use Cmd-Option-N if you are a keyboard shortcut lover like me. Type in a meaningful name, I used WebIM, and then a new script editor opens. Paste the following code into the window <b>replacing</b> what was there already and then save and close the script editor.
<pre class="brush: jscript">
// ==UserScript==
// @name        WebIM
// @namespace   http://www.jeremyjohnstone.com
// @description Enables advanced notifications and disables ads
// @include     *
// @author      Jeremy Johnstone
// ==/UserScript==

(function () {
    if (window.fluid) {
			// unread is a bit of misnomer, because we clear this
			// as soon as the window regains focus, not when you
			// actually read the IM (TODO: telepathy enabled?)
			var unreadIMCount = 0;

			// store the state of the user being active
			var activeState = true;

			// I don't want ads in my IM client
			window.showAd = function(locale) { }

			// When the window regains focus, clear the unread IM count
			// Also save the state for other functions
			window.onfocus = function() {
				activeState = true;
				unreadIMCount = 0;
				window.fluid.dockBadge = "";
			}
			window.onblur = function() {
				activeState = false;
			}

			// disabling this turns off the normal new IM
			// notification (aka the scrolling title message)
			window.startNotify = function(msg) { }

			// Here we latch into the advancedNotify which
			// splits out the yid from the msg separately
			window.advancedNotify = function(yid, msg) {
				// We don't want to show growl alerts if the
				// user is active already
				if(activeState) return;

				msg = unescape(msg);
				window.fluid.showGrowlNotification({
					title: "New Message from: " + yid,
					description: msg,
					priority: 1,
					sticky: false,
					identifier: null,
					onclick: null
				});

				// Now we increment the unread IM count and then
				// set the dockBadge to be the number of unseen IMs
				unreadIMCount++;
				window.fluid.dockBadge = unreadIMCount;
			}

			// Instead of blowing away the cookies going to login,
			// Let's just close the app instead
			window.exit = function(url) {
				// seems neither of these work... hmmm..
				// fluid bug???
				window.fluid.terminate();
				window.fluid.hide();
			}
    }
})();
</pre>
</li>
<li>Finally, not sure this is needed, but I found it easiest to quit the app and restart it as that way you know for sure your script got loaded right. Probably not needed, but always safer. Also check the Userscripts menu and you should see a menu option for your new script. Make sure there is a check mark next to it. If so, go ahead and sign in as usual.</li>
</ol>
<p>That&#8217;s it! You now have a new Web Messenger client inside it&#8217;s own browser tab with the following new features:</p>
<ul>
<li>Growl Notifications for IMs received when the app isn&#8217;t in focus</li>
<li>Dock Badge updates with the count of unread IMs received</li>
<li>No advertising banners shown</li>
</ul>
<p>My hope is that I can get the <a href="http://twitter.com/iTod">author of Fluid</a> to add a couple more improvements which will make it even better as well as hopefully fix what I think is a bug with hide() and terminate() not working. With dock icon bouncing and a separate cookie jar for each application this will be immensely useful, IMHO.</p>
<p>Here&#8217;s a little video tutorial taking you through the steps above.</p>
<p><object width="640" height="400"><param name="movie" value="http://www.youtube.com/v/dERIgeG7q6Q&#038;hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/dERIgeG7q6Q&#038;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="640" height="400"></embed></object></p>
<p>Enjoy!</p>
<p>-Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremyjohnstone.com/blog/2008-04-04-yahoo-web-messenger-meets-fluidapp.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Useful Javascript OO pattern</title>
		<link>http://www.jeremyjohnstone.com/blog/2007-12-27-useful-javascript-oo-pattern.html</link>
		<comments>http://www.jeremyjohnstone.com/blog/2007-12-27-useful-javascript-oo-pattern.html#comments</comments>
		<pubDate>Fri, 28 Dec 2007 05:52:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=259</guid>
		<description><![CDATA[I&#8217;ve spent the majority of the day (and a good chunk of the evening) refactoring the HTML, CSS, JS, and PHP for the Yahoo! Web Messenger products (we are known internally as the &#8220;Eden Team&#8220;). Being that all but one of our products (the messenger inside Yahoo! Mail, which still uses a Flash based SDK [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the majority of the day (and a good chunk of the evening) refactoring the HTML, CSS, JS, and PHP for the <a href="http://webmessenger.yahoo.com">Yahoo! Web Messenger</a> products (we are known internally as the &#8220;<a href="http://flickr.com/photos/jeremyjohnstone/sets/72157600942931740/">Eden</a> <a href="http://flickr.com/photos/jeremyjohnstone/sets/72157603022215734/">Team</a>&#8220;). Being that all but one of our products (the messenger inside <span id="lw_1198820906_0" class="yshortcuts">Yahoo! Mail</span>, which still uses a <span id="lw_1198820906_1" class="yshortcuts">Flash</span> based SDK for the network transport) we developed on this team are mostly Flash based (Flex/AS3 technically), the non-Flash based components have badly needed some love for a while. Before digging into the Javascript I decided to browse around for a better OO pattern for Javascript classes. Not being someone who likes coding in Javascript much (part of why I joined this team), it&#8217;s not something I have been staying current on lately. Looking at the code for <a href="http://www.swffix.org/devblog/">SWFObject 2.0</a> I discovered they had a pretty clever approach which gives you public and private class variables, public and private methods, and even something akin to a static initializer. Here&#8217;s a bit of sample code to illustrate the concept:<span id="more-259"></span></p>
<pre class="brush: jscript">
var myObj = function() {
    // private instance variables
    var foo = 33;

    // pseudo static initializer
    var staticInitializer = function() {
        // do some code here, will run only once
    }();

    // private method
    function foobar() {
        // do something
    }

    // public api
    return {
        publicMethod: function() {
            // do something
        },

        publicVariable: 42,

        publicMethod2: function() {
             // do something
        }
    }
}();
</pre>
<p>None of the above was new to me, but I had never seen it put all together like that. I liked it enough that I&#8217;ve adopted it as my preferred pattern for JS code going forward. Now, once I get the PHP code looking respectable I can finally sleep a little better at night!</p>
<p><strong>Update:</strong><br />
Yes, the Eden team is the same team which is developing <a href="http://mym.com">myM</a>, and no, I won&#8217;t get you an invite (not this year at least).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremyjohnstone.com/blog/2007-12-27-useful-javascript-oo-pattern.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
