background preloader

Jasmine: BDD for your JavaScript

Jasmine: BDD for your JavaScript

JavaScript Architecture: Backbone.js Routers Updated Aug 11, 2012 to reflect current library versions. In JavaScript Architecture: Backbone.js Views we discussed how to build dynamic apps that change views on the fly using JavaScript. Because view-switching is done without reloading the page or transferring control to a separate page, these are called single-page applications. Single-page applications pose a few issues we need to address: When users hit their browser’s back button, they will be taken away from the app completely rather than back to a previous view within the app itself.Users are only able to link to or bookmark the app itself–not a specific view within the app.Deep views within the app may not be crawlable by search engines. We want a great experience for our users. Like the topics we’ve addressed before, these issues aren’t specific to Backbone. Examples This concept is most easily taught by example so let’s assume we’re building an app that sells shirts. This time we set up our route with three parameter parts.

Documentation JSHint is a program that flags suspicious usage in programs written in JavaScript. The core project consists of a library itself as well as a CLI program distributed as a Node module. More docs: List of all JSHint options · CLI flags · Writing your own reporter · FAQ Basic usage The easiest way to use JSHint is to install it as a Node program. $ npm install jshint -g After you've done that you should be able to use the jshint program. $ jshint myfile.js myfile.js: line 10, col 39, Octal literals are not allowed in strict mode. 1 error If a file path is a dash (-) then JSHint will read from standard input. Configuration JSHint comes with a default set of warnings but it was designed to be very configurable. This setup allows you to have different configuration files per project. Configuration file is a simple JSON file that specifies which JSHint options to turn on or off. Inline configuration /* jshint undef: true, unused: true */ /* global MY_GLOBAL */ Directives jshint /* jshint strict: true */

Building a bookmarking service with python and phantomjs March 29, 2012 19:16/1 comments/ phantomjs python Using python and phantomjs, a headless webkit browser, it is a snap to build a self-hosted bookmarking service that can capture images of entire pages. Combine this with a simple javascript bookmarklet and you end up with a really convenient way of storing bookmarks. The purpose of this post will be to walk through the steps to getting a simple bookmarking service up and running. Installing phantomjs First step is installing phantomjs and making sure it is working correctly. Select the appropriate binary depending on your system architecture: Grab the tarball and extract it somewhere: mkdir ~/bin/ cd ~/bin/ wget tar xzf phantomjs-1.5.0-linux-x86-dynamic.tar.gz Symlink the binary somewhere onto your path sudo ln -s ~/bin/phantomjs/bin/phantomjs /usr/local/bin/phantomjs Install dependencies -- fontconfig and freetype sudo pacman -S fontconfig freetype2 Writing some code

jnicklas/capybara js-test-driver - Remote javascript console Quick Navigation Release 1.3.4-a First Release of 2012, 1.3.4-a: Bugs and Fixes: fixed the reset on syntax error bug. Better error reporting when --preloadFiles is passed in. Features: --basePath and base_path now accept multiple base paths. News: We'll be moving to Git on Google Code in the next two weeks. Release 1.3.3d Fixed issue 273 , Invalid JSON is being sent to the browser with Windows paths Improved queuing for simultaneous clients Release 1.3.3c Fixed issue 278 , Noisy output when using --captureConsole Fixed issue 276 , Absolute Paths on Windows fail Fixed issue 273 , Invalid JSON is being sent to the browser with Windows paths Release 1.3.3b Fixed issue 223 for the last time. Release 1.3.3a New test isolation plugin, documentation forthcoming: issue 272 Fix for issue 223 , which was real pain without a windows box Add test step description to expired callback error messages in the asynch tests. Release 1.3.2 Question?

Zombies! RUN! (Managing Page Transitions In Backbone Apps) One of the common issues or questions I see for Backbone.js goes something like this: “Whenever I hit the same route more than once, I end up getting seeing this call being made multiple times. It seems to accumulate another call every time I hit the route. What’s going on?” or “I’ve noticed that my views are still handling events after I remove them from the screen. “How do I make sure I clean things up when moving to a new page in my app?” At the heart of all of these questions is a problem that most backbone developers will run into at some point: zombies. The Plague: Event Binding The majority of the problems that people are referring to in these questions and issues are caused by the events that we bind to in our apps. We bind events to our DOM elements using the declarative `events` configuration in our views: We bind events from our models and collections so that our views can respond to changes and re-render themselves: Events are everywhere, and with good reason. Rule #2: Double Tap

A Javascript When Function Mon Feb 20 2012 function when(conditionFunc, execFunc, interval){ if (conditionFunc()){ execFunc(); }else{ setTimeout(function(){ when(conditionFunc, execFunc, interval);}, interval); } } You have some code which should only execute when a condition is true. Use when like this... function libIsReady(){ return typeof(LIBRARYNAME) ! Categories

Websockets Server - Cookbook As explained in this webpage, the Websocket protocol allows full-duplex, bi-directional communications between a server and clients. For this WebSocket tutorial, we will need to implement a server. We chose the Tornado Websocket server for our Internet of Things project. In this tutorial, we will present an example of how to get the Tornado Server running using websockets. This tutorial is divided into two parts: A Hello World which uses Tornado A websocket streaming example which uses Websocket4j. 1 - Hello World! 1.1 - Server side: Tornado¶ Warning Tornado only runs on Unix-like platforms. Installation¶ First, download the sources, unpack and follow the readme. For more information concerning the installation, you can go here Code¶ You can find all the documentation you need here, but I will explain the main parts of the following basic Tornado Websocket server program. The main idea is to define a class inherited from the WebSocketHandler class. open on_message on_close In our case: Code¶

Learning JavaScript Design Patterns Design patterns are reusable solutions to commonly occurring problems in software design. They are both exciting and a fascinating topic to explore in any programming language. One reason for this is that they help us build upon the combined experience of many developers that came before us and ensure we structure our code in an optimized way, meeting the needs of problems we're attempting to solve. Design patterns also provide us a common vocabulary to describe solutions. In this book we will explore applying both classical and modern design patterns to the JavaScript programming language. Target Audience This book is targeted at professional developers wishing to improve their knowledge of design patterns and how they can be applied to the JavaScript programming language. Some of the concepts covered (closures, prototypal inheritance) will assume a level of basic prior knowledge and understanding. Acknowledgments Credits Reading Patterns are not an exact solution.

QUnit - jQuery JavaScript Library

Related:  TestingJavascriptTDDtutorial