Unit testing CoffeeScript with QUnit

I got bitten by the CoffeeScript bug and decided that I liked it enough to try to add CoffeeScript support to Cheezburger.com. Paul Betts’ very cool SassAndCoffee library has a method which compiles CoffeeScript to JavaScript which I could easily integrate into our script serving system.

I’ve also been bitten by the QUnit bug so before I enable CoffeeScript on Cheezburger.com, I want to make sure that I can unit test whatever CoffeeScript we write. A quick Google search yielded next to nothing about testing CoffeeScript but I was feeling inventive and came up with the following way to use QUnit with CoffeeScript.

Important Gotcha

Since we’re going to load .coffee scripts via jQuery.get(), they must be served by a web server. They will not load off the local file system if you simply open index.htm locally. If anyone finds a way around this, feel free to comment on the gist.

I enabled IIS Express to serve .coffee files by adding the following element to applicationhost.config in the configuration/system.webserver/staticContent element:

<mimeMap fileExtension=”.coffee” mimeType=”text/plain” />

/Gotcha

Here is a contrived Dog class and a test for it:

And here’s the index.htm which runs the tests:

I started out with the normal set of QUnit files (index.htm, the css, and js), then included the coffee-script.js which enables us to execute CoffeeScript written in a <script type=”text/coffeescript”></script> tag. My usage of this tag in the code was completely unnecessary, but I thought this example would be more interesting if it was ALL CoffeeScript.

The scriptsToTest variable is a list of paths to .coffee files which will get loaded on the page. The tests variable is similar, but holds the tests. I split these up simply for readability.

The loadCoffee function spins through the contents of each of the files handed to it, executes the CoffeeScript compiler on them, and injects a script tag containing the compiled code into the page.

It’s important to include the “bare: on” option when calling the CoffeeScript.compile function. If bare is off (false), then the compiled code will be wrapped in a function so that declared variables get declared globally. My tests expect the Dog class to be declared globally, so I set bare to on.

Here’s a zip file full of all the files to make this example run (except for IIS Express):

QUnitAndCoffeeScript

Posted in Development, Uncategorized | 5 Comments

Turntable.fm: Mute until next track starts

Drag the link below up to your bookmark bar. When clicked, this bookmarklet will mute the current song in Turntable.fm and then unmute when the next song starts playing.

Updated 7/5/2011 – Turntable.fm changed the name of their player control, so instead of calling it directly, we’re just invoking the event handlers for the actual mute button. Should be more stable!

Mute Until Next Track Starts

I requested this feature via the Turntable.fm feedback button but I got tired waiting and decided to dive in and figure how to do it myself. The JavaScript simply activates the click event on the mute button, then binds a handler which waits for a chat message of ” started playing” to appear. When it does, the volume it turned all the way up again and the handler is unbound.

Here’s the code powering the bookmarklet:

Posted in Development, Uncategorized | 2 Comments

Events on JavaScript Objects

I did a search for javascript events and came up with lots of articles about onclick and onload and all the lovely things we use to make our pages interactive. But in this case, I wanted a C#-style event, like an event on an object. With a little more digging, I found this article about C#-style events which pointed me towards the approach of just keeping a list of the functions that should be triggered by that event. However, I didn’t like the way it was written so I decided to re-implement the same idea in a JavaScript writing style more like this article about JavaScript instant iterators. Here’s the result:

Posted in Development, Uncategorized | Comments Off on Events on JavaScript Objects

Building Chrome extensions from a service account

So I got our build system to call the chrome.exe to build my Chrome extension, but it didn’t work. It said:

Could not find exported function RelaunchChromeBrowserWithNewCommandLineIfNeeded

The build system runs in a web application, so I’d have to guess that chrome was mad because it wasn’t running as a real user account.

I found this post that suggested moving the chrome.exe into the application/{version} folder. Once it was there, my build worked.

Clipped from code.google.com
I also faced this problem.
Exact deatails are as follows, In my Organisation Group policy does not allows for downloading and installing any s/w on computers from internet.Since i like chrome very much, I copied the chrome installation file(Chrome folder) from c:doc&settingsusernamelocalsettingapplication datagooglechrome and tried to run chrome and recieved this error( exported function not available)
To solve this problem I copied the chrome.exe from ~application folder into ~chromeapplication8.0.552.215 folder and tried to run chrome , it started working and i recieved no error
qustion is why chrome.exe in ~application folder was not able to read dlls into 8.0552.215 folder though it is hard wired to do so( I think so atleast).
It is a bug which devs should atleast try to correct it. 

I would also suggest to users who are facing this problem to copy chrome.exe from~application folder to ~applicationversion Id folder and running chrome.

Lets see what happens

Regards
Adi

Read more at code.google.com

Posted in Development, Uncategorized | Tagged , , , , | Comments Off on Building Chrome extensions from a service account

Still relevant

Posted in Uncategorized | Tagged , , , , | Comments Off on Still relevant

Basics of Statistics in SQL Server 2005 – Developer.com

I had a table that was too large to get a count of. I tried Select Count(*) from {Table} but the query didn’t want to come back very quickly.

Another way to get the size is to get statistical information on the primary key. You can do sp_helpstats ‘{Schema}.{Table}’, ‘ALL’ to get a list of objects with statistical information. Find the primary key, then do DBCC SHOW_STATISTICS(‘{Schema}.{Table}’, {value of statistics_name column from previous query}

Posted in Development, Uncategorized | Tagged , , , , | Comments Off on Basics of Statistics in SQL Server 2005 – Developer.com

Java Update – Y U NO understand that I hate toolbars?

Java Update, seriously? You want to install Yahoo! toolbar by default? That’s evil and I hate you for it. I’d be OK if I had to click to opt-in.

Posted in Uncategorized | Tagged , , , , | Comments Off on Java Update – Y U NO understand that I hate toolbars?

I want you all to feel empowered on this project

Amplify’d from dilbert.com
 

Posted in Development, Uncategorized | Tagged | Comments Off on I want you all to feel empowered on this project

Reseed the identity on a SQL Server table

I’d rather just take the identity off the table I had to use this on, but this is an excellent solution if you over incremented the identity and need to bring it back.

Amplify’d from msdn.microsoft.com

The following example forces the current identity value in the AddressTypeID column in the AddressType table to a value of 10. Because the table has existing rows, the next row inserted will use 11 as the value, that is, the current identity value plus 1, the current increment value defined for the column.

USE AdventureWorks2008R2;
GO
DBCC CHECKIDENT ("Person.AddressType", RESEED, 10);
GO

Read more at msdn.microsoft.com

 

Posted in Development, Uncategorized | Tagged , , , , | Comments Off on Reseed the identity on a SQL Server table

Enable IIS to serve .woff and .svg files

I needed this functionality, too. Here’s how to do it.

Amplify’d from sebduggan.com

By default, the MIME types in IIS 6 are configured to deliver EOT (as used by IE) and TTF files. But WOFF (Firefox) and SVG (iPhone, iPad & others) will not be served.

Simply add the following MIME type declarations via IIS Manager (HTTP Headers tab of website properties):

.woff  application/x-woff
.svg   image/svg+xml

Read more at sebduggan.com

 

Posted in Uncategorized | Tagged , , , , | Comments Off on Enable IIS to serve .woff and .svg files