A web component that create a CSS-only floating label for input
tags
Handlebars.registerHelper("prettyDate", function (time) { | |
var date = new Date((time || "")), | |
diff = (((new Date()).getTime() - date.getTime()) / 1000), | |
day_diff = Math.floor(diff / 86400); | |
// exit now if not a number... | |
if ( isNaN(day_diff)) return; | |
if ( day_diff < 0 ){ | |
// this is in the future... |
if(typeof APP == "undefined"){ | |
var APP = { | |
Models: {}, | |
Collections: {}, | |
Views: {} | |
}; | |
} | |
APP.Models.Twitter = {}; | |
APP.Models.Twitter.Tweet = Backbone.Model.extend({ |
#!/bin/bash | |
function jsonval { | |
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop` | |
echo ${temp##*|} | |
} | |
json=`curl -s -X GET http://twitter.com/users/show/$1.json` | |
prop='profile_image_url' | |
picurl=`jsonval` |
Router = Backbone.Router.extend({ | |
initialize: function() { | |
this.bind('all', this._trackPageview); | |
}, | |
_trackPageview: function(){ | |
var url = Backbone.history.getFragment(); | |
_gaq.push(['_trackPageview', "/#"+url]); | |
} |
This bar chart visualizes hierarchical data using D3. Each blue bar represents a folder, whose length encodes the total size of all files in that folder (and all subfolders). Clicking on a bar dives into that folder, while clicking on the background bubbles back up to the parent folder. The effect is similar to a zoomable partition layout, though in a more conventional display.
An example of multiple pie (donut) charts created with D3. The data is represented as a two-dimensional array of numbers; each row in the array is mapped to a pie chart. Thus, each pie represents the relative value of a number (such as 1,013) within its rows. Note that in this dataset, the totals for each row are not equal.
##Introduction
One definition of unit testing is the process of taking the smallest piece of testable code in an application, isolating it from the remainder of your codebase and determining if it behaves exactly as expected. In this section, we'll be taking a look at how to unit test Backbone applications using a popular JavaScript testing framework called Jasmine from Pivotal Labs.
For an application to be considered 'well'-tested, distinct functionality should ideally have its own separate unit tests where it's tested against the different conditions you expect it to work under. All tests must pass before functionality is considered 'complete'. This allows developers to both modify a unit of code and it's dependencies with a level of confidence about whether these changes have caused any breakage.
As a basic example of unit testing is where a developer may wish to assert whether passing specific values through to a sum function results in the correct output being re
jasmine.Fixtures.prototype.loadTemplate_ = function(template) { | |
var templateUrl = "/backbone/templates/" + template; | |
var self = this; | |
$.ajax({ | |
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded | |
cache: false, | |
dataType: 'html', | |
url: templateUrl, | |
success: function(data) { | |
$('#' + self.containerId).append(data); |