You are previewing CoffeeScript Application Development Cookbook.
O'Reilly logo
CoffeeScript Application Development Cookbook

Book Description

Over 90 hands-on recipes to help you develop engaging applications using CoffeeScript

In Detail

CoffeeScript is a JavaScript compiler. CoffeeScript brings many things to the table that are lacking in JavaScript itself. This includes a class and module system, a syntax that is cleaner, less terse, and well structured, and list comprehensions that make working with collections of data more enjoyable. CoffeeScript can be used as not only a tool for the Web, but also as a tool for day-to-day DevOps type tasks (for example, file processing, working with databases, and more).

This practical guide contains a wide range of recipes demonstrating how CoffeeScript can be used while developing the entire stack of an application. With recipes that range from easy and intermediate to advanced, there is something here for anyone looking to escape the common pitfalls of JavaScript and develop in a clean and expressive language.

What You Will Learn

  • Create user interfaces with jQuery, Backbone, AngularJS, and Kendo.UI

  • Develop RESTful services using Node and Express

  • Read and write data using SQLite, Redis, MongoDB, CouchDB, and Microsoft SQL Server

  • Interface with external services to send e-mails, SMS text messages, and use cloud storage services such as DropBox and S3

  • Test your code using Jasmine, QUnit, Zombie, Persona, and Mocha with Chai

  • Work with a variety of hosts such as Heroku, Azure, and Amazon Web Services

  • Use CoffeeScript for DevOps tasks such as managing files and directories, and parsing CSV and fixed-width files

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. CoffeeScript Application Development Cookbook
      1. Table of Contents
      2. CoffeeScript Application Development Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Ready
        1. Introduction
        2. Configuring your environment and tools
          1. Getting ready
          2. How to do it...
        3. Configuring Sublime Text
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Commands
            2. Snippets
        4. Configuring Visual Studio
          1. Getting ready
          2. How to do it...
        5. A quick dive into CoffeeScript
          1. How to do it...
          2. There's more...
            1. The CoffeeScript REPL
        6. Debugging CoffeeScript using source maps
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Debugging CoffeeScript using Node Inspector
          1. Getting ready
          2. How to do it...
          3. How it works...
      9. 2. Starting with the Basics
        1. Introduction
        2. Working with strings
          1. String interpolation
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          2. Wrapping text
            1. How to do it...
            2. How it works...
            3. See also
          3. Truncating text
            1. How to do it...
            2. How it works...
          4. Converting character casing
            1. How to do it...
            2. How it works...
          5. Using regular expressions
            1. How to do it...
            2. How it works...
            3. There's more...
        3. Working with numbers
          1. Converting between bases
            1. How to do it...
            2. How it works...
          2. Generating random numbers
            1. How to do it...
            2. How it works...
          3. Converting between degrees and radians
            1. How to do it...
            2. How it works...
          4. Checking a credit card checksum
            1. How to do it...
            2. How it works...
            3. There's more...
        4. Working with dates and times
          1. Performing date calculations
            1. How to do it...
            2. How it works...
          2. Measuring elapsed time
            1. How to do it...
            2. How it works...
        5. Working with arrays
          1. Iterating over arrays
            1. Getting ready
            2. How to do it…
            3. How it works...
            4. There's more...
          2. Sorting arrays
            1. How to do it…
            2. How it works...
          3. Shuffling an array
            1. Getting ready
            2. How to do it…
            3. How it works...
          4. Mapping and reducing arrays
            1. Getting ready
            2. How to do it...
          5. Filtering and testing arrays
            1. Getting ready
            2. How to do it...
            3. How it works...
        6. Working with classes
          1. Defining classes
            1. How to do it...
            2. How it works...
          2. Dealing with inheritance
            1. How to do it...
            2. How it works...
          3. Class properties and methods
            1. How to do it...
            2. How it works...
        7. Dealing with the this keyword
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Creating Client Applications
        1. Introduction
        2. Working with jQuery
          1. Executing on load
            1. Getting ready
            2. How to do it...
            3. How it works...
          2. Handling DOM events
            1. How to do it...
            2. How it works...
          3. Modifying the DOM
            1. How to do it...
            2. How it works...
            3. There's more...
          4. Communicating with the server using AJAX
            1. How to do it...
            2. How it works...
          5. Using jQuery UI widgets
            1. How to do it...
            2. How it works...
            3. There's more...
          6. Displaying an image gallery using Lightbox
            1. How to do it...
            2. How it works...
        3. Working with Backbone
          1. Creating models
            1. Getting ready
            2. How to do it...
            3. How it works...
          2. Creating collections
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          3. Creating views
            1. Getting ready
            2. How to do it...
            3. How it works...
          4. Handling UI events
            1. Getting ready
            2. How to do it...
            3. How it works...
          5. Creating routers
            1. How to do it...
            2. How it works...
            3. There's more...
        4. Working with AngularJS
          1. Creating an Angular application module
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          2. Creating Angular controllers
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          3. Creating Angular providers
            1. How to do it…
            2. How it works…
            3. There's more...
          4. Creating Angular directives
            1. How to do it...
            2. How it works...
          5. Creating Angular routers
            1. How to do it...
            2. How it works...
          6. Handling inter-controller events
            1. How to do it...
            2. How it works…
            3. There's more...
        5. Communicating in real time with Socket.io
          1. Getting ready
          2. How to do it...
          3. How it works…
      11. 4. Using Kendo UI for Desktop and Mobile Applications
        1. Introduction
        2. Using the Kendo UI Core widgets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Using the Kendo UI Core mobile widgets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      12. 5. Going Native with Cordova
        1. Introduction
        2. Creating a basic Cordova application
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using the camera
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Using geolocation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Using contacts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Getting device information
          1. Getting ready
          2. How to do it...
          3. How it works...
      13. 6. Working with Databases
        1. Introduction
        2. Working with SQLite
          1. Getting started
          2. Inserting and updating records, and executing commands
            1. How to do it...
            2. How it works...
            3. There's more...
          3. Reading records
            1. How to do it...
            2. How it works...
            3. There's more...
          4. Executing queries in parallel versus serial
            1. How to do it...
            2. How it works...
        3. Working with Redis
          1. Connecting to the Redis server
            1. How to do it...
            2. How it works...
          2. Storing and retrieving single values
            1. How to do it...
            2. How it works...
            3. There's more...
          3. Using counters
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          4. Storing and retrieving hashes
            1. How to do it…
            2. How it works...
            3. There's more...
          5. Storing and retrieving lists
            1. How to do it...
            2. How it works...
            3. There's more...
          6. Deleting keys
            1. How to do it...
            2. How it works...
            3. There's more...
        4. Working with MongoDB
          1. Opening a connection
            1. Getting ready...
            2. How to do it...
            3. How it works...
          2. Inserting documents
            1. How to do it...
            2. How it works...
          3. Finding documents
            1. How to do it...
            2. How it works...
            3. There's more...
          4. Updating documents
            1. How to do it...
            2. How it works...
            3. There's more...
          5. Deleting documents
            1. How to do it...
            2. How it works...
        5. Working with CouchDB
          1. Opening a connection
            1. Getting ready...
            2. How to do it...
            3. How it works...
            4. There's more...
          2. Creating documents
            1. How to do it...
            2. How it works...
          3. Updating documents
            1. How to do it...
            2. How it works...
          4. Reading documents
            1. How to do it...
            2. How it works...
          5. Deleting documents
            1. How to do it...
            2. How it works...
          6. Querying documents using views
            1. How to do it...
            2. How it works...
            3. There's more...
      14. 7. Building Application Services
        1. Introduction
        2. Working with base64 encoding
          1. Encoding a string as base64
            1. Getting ready
            2. How to do it...
            3. How it works...
          2. Encoding a binary file as base64
            1. Getting ready
            2. How to do it...
            3. How it works...
        3. Working with domain name services
          1. Retrieving the IP address for a domain name
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          2. Retrieving a hostname for an IP address
            1. Getting ready
            2. How to do it...
            3. How it works...
        4. Parsing a URL into its various components
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Creating RESTful web services
          1. Managing dependencies with package.json
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
          2. Creating a basic express application
            1. Getting ready
            2. How to do it...
            3. How it works...
          3. Creating a web API
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
      15. 8. Using External Services
        1. Introduction
        2. Working with web services
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Sending e-mail
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Sending SMS and MMS messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Working with Amazon's S3 storage
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Transferring files via FTP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      16. 9. Testing Our Applications
        1. Introduction
        2. Unit testing with QUnit
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. End-to-end testing with Mocha and Zombie.js
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Stubbing and mocking with Sinon
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      17. 10. Hosting Our Web Applications
        1. Introduction
        2. Compiling our source with Grunt
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Preparing deployments for staging and production
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Deploying our application to Heroku
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Deploying our application to Microsoft Azure
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      18. 11. Scripting for DevOps
        1. Introduction
        2. Executing shell commands with exec
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Executing shell commands with spawn
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Copying, moving, and deleting files and directories
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Archiving files and directories
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Parsing CSV files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Parsing fixed-width files
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Padding and aligning output
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Formatting dates with moment.js
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        10. Formatting numbers with accounting.js
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      19. Index