underscore.js cheat sheet
homepage
collections | arrays | functions | objects | utility
collections
each(list, iterator, [context])
runs the iterator on each object in listmap (list, iterator,[context])
calls the iterator for each object and returns an array of the resultsreduce(list,iterator(memo, token), memo,[context])
passes the return value into iterator as memo and then returns the last memoreduceRight(list, iterator, [context])
reverse of reducedetect(list, iterator, [context])
returns the first item that passes the iteratorselect(list, iterator, [context])
returns all items that pass the iteratorreject(list, iterator, [context])
opposite of selectall(list, iterator, [context])
returns true if all items pass the iteratorany(list, [iterator], [context])
returns true if any items pass the iteratorinclude(list, value)
returns true if list contains valueinvoke(list, methodName, [*args])
invokes the method on each item passing in argspluck(list, propertyName)
extracts a list of property valuesmax(list, [iterator], [context])
returns the max value or max iterator resultmin(list, iterator, [context])
opposite of maxsortBy(list, iterator, [context])
sorts list by iterator resultgroupBy(list, iterator, [context])
groups list by iterator resultsortedIndex(list, value, [iterator])
returns the future index of value based on binary searchtoArray(list, iterator, [context])
converts list to arraysize (list, iterator, [context])
size of list
arrays
first(array, [n])
rest(array, [index])
last(array)
compact(array)
removes falsy valuesflatten(array)
flattens arraywithout(array, [*values])
removes the values from the arrayunion(*arrays)
returns an array of all unique itemsintersection(*arrays)
array of values in all arraysdifference(array, other)
values in array but not in otheruniq(array, [isSorted])
remove duplicateszip(*arrays)
merges the values of each array w/ matching possitionsindexOf(array)
lastIndexOf(array)
range([start], stop, [step])
creates an array
functions
bind(function, object)
the var this inside the function will be objectbindAll(object, [*methodNames)
this is always the object pass for all methods in the objectmemoize(function)
caches the result of the functiondelay(function, wait, [*argumens])
like setTimeoutdefer()
like setTimeout with 0throttle(function, wait)
the returned function can only be called once every waitdebounce(function, wait)
return function will only be invoked after not being called the duration of waitonce(function)
function that can only be called onceafter(count, function)
a function that will be invoked after being called count timeswrap(function, wrapper)
passes function into wrappercompose(function g, function h, * functions)
returns f(g(h(*)))
objects
values(obj)
returns all the valuesfunction(obj)
returns the name of every functionextend(destination, *sources)
move source members to destinationdefaults(destination, *sources)
move source members not in destination to destinationclone(obj)
shallow copytap(obj, interceptor)
isEqual(objA, objB)
compares values of objectsisEmpty(obj)
true if no valuesisElement(obj)
isArray(obj)
isArguments(obj)
isFunction(obj)
isString(obj)
isNumber(obj)
isBoolean(obj)
isDate(obj)
isRegExp(obj)
isNaN(obj)
isNull(obj)
isUndefined()
utility
identity(value)
uselesstimes(n, block)
invokes the block n tiemsmixin(object)
adds functions to _uniqueId([prefix])
creates unique dom idtemplate(template, [context])
ejs template
My team recently switched to tfs and after attending a Kiln demo, I wondered what it would be like to use mercurial with tfs. I recently came across this Stackoverflow question which lead me to this los techies blog post Using Mercurial as a local repository for Team Foundation Server / Start Front’N.
In the post, Eric Hexter gives an excellent break down of how to setup mercurial for use with tfs. The only thing I would like to add, is to make sure you grab the correct version of the makewritable plugin for your mercurial version. Rookie mistake on my end, but it still cost me an hour.Here is my version of the pull.ps1:
function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value Split-Path $Invocation.MyCommand.Path } $originPath = "C:\tfs-working-dir" $workingPath = Get-ScriptDirectory $tf = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" cd $originPath &$tf get hg commit -A -m "from tfs" cd $workingPath hg pull --rebase
and my version of the push.ps1:
function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value Split-Path $Invocation.MyCommand.Path } $originPath = "C:\tfs-working-dir" $workingPath = Get-ScriptDirectory $tf = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" $tfpt = "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\tfpt.exe" hg push cd $originPath &$tfpt scorch /noprompt /exclude:.hg,*.user hg update -C -y &$tfpt online /adds /deletes /exclude:.hg`,.hgignore`,*.ps1`,bin`,obj`,*.user`,*.suo`,App_Data &$tf checkin cd $workingPath
With my netbook’s copy of the Windows 7 beta about to expire, I decided to give Ubuntu another shot. My previous experiences with Linux have been quite painful and in some cases it was easier to install a copy of Windows ME than force Linux to work right.

I downloaded a copy of Ubuntu 9.10 Netbook Remix for the net book and installed it off of a thumb drive. It installed without any issue and was the first time ever my wireless card worked out of the book with Linux.
It still has that slightly buggy Linux feel.
For example:
- Firefox is set to open the home page when it loads but it always loads the last session.
- Adding programs to the startup list doesn’t always seem to stick. I have had to add the same programs about three times each now.
- Launchy doesn’t seem to want to open some files correctly and I get text files instead of Firefox.
- Certain applications are always asking my permission to connect to unverified servers every time they open as Pandora, and I really don’t need that kind of security.
- A GUI task manager because some programs keep locking up.
- Eclipse can’t update and install any plugins such as Java projects.
Adobe has done a really good job with air and flash. Installing air and flash was a breeze and was the only way I could get a decent twitter client.
My two biggest complaints with it are the cartoony oversized controls (that has always bothered me with Linux) and the lack of polish.
I’m going to keep it and am enjoying it greatly; however, it’s not ready for the type of users that don’t care about learning how computer their computer works. My wife would be lost in Linux even though she has been using a mac for three years now. She doesn’t need to spend time customizing everything to work right.
Over the summer I picked up a ASUS EEE 1000HE netbook. The first thing I did when I got it was install win 7 and upgrade the RAM to 2gigs.

It advertises 9.5 hours of battery life and with win7 installed, I was not expecting to get even close, but I usually get over 8. Now, that’s with the monitor dimmed and the turbo button set to auto-mode. Yes, it has a turbo button. I was a little disapointed at first but it’s a nice throw back to the earlier days of computers. The auto-mode doesn’t get in the way much. Most of the time I am typing or reading the minilappy doesn’t need to do much.
As a dev machine, it’s decent. I have it running Visual Studio 2008 with Coderush. The screen real estate is a little tight. When Coderush runs a template, it tends to lag a little, but that’s mainly do to the hard drive. Also VS lags a lot when programming XAML.
For surfing the web, it’s awesome. Chrome is as zippy as ever on this little machine. And small size and ridiculously long battery life makes it an awesome machine for living on the couch.
At conferences, it’s great. Usually power outlets are a rare commodity. With 8+ hrs of batter life and a little prior planning, I free from searching for a place to recharge all day.
Overall, I wouldn’t use this as my main machine, but as a secondary, it is awesome.
code reference for INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged; private void RaiseEventPropertyChanged(PropertyChangedEventArgs e) { PropertyChangedEventHandler temp = PropertyChanged; if (temp != null) { temp(this, e); } } private void OnPropertyChanged(string propertyName) { // perform pre event work // create args and raise event. PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName); RaiseEventPropertyChanged(e); }