This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var redis = require("redis") | |
| , subscriber = redis.createClient() | |
| , publisher = redis.createClient(); | |
| subscriber.on("message", function(channel, message) { | |
| console.log("Message '" + message + "' on channel '" + channel + "' arrived!") | |
| }); | |
| subscriber.subscribe("test"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function merge(left, right) { | |
| var result = []; | |
| while(left.length > 0 && right.length > 0) { | |
| if(left[0] < right[0]) { | |
| result.push(left.shift()); | |
| } else { | |
| result.push(right.shift()); | |
| } | |
| } | |
| return result.concat(left).concat(right); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Animal, Horse, Snake, sam, tom, | |
| __hasProp = {}.hasOwnProperty, | |
| __extends = function(child, parent) { | |
| for (var key in parent) { | |
| if (__hasProp.call(parent, key)) | |
| child[key] = parent[key]; | |
| } | |
| function ctor() { | |
| this.constructor = child; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.time("answer time"); | |
| alert("Click to continue"); | |
| console.timeEnd("answer time"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require.config({ | |
| baseUrl: '/backbone-tests/', | |
| paths: { | |
| 'jquery' : '/app/libs/jquery', | |
| 'underscore' : '/app/libs/underscore', | |
| 'backbone' : '/app/libs/backbone', | |
| 'mocha' : 'libs/mocha', | |
| 'chai' : 'libs/chai', | |
| 'chai-jquery' : 'libs/chai-jquery', | |
| 'models' : '/app/models' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // # Mocha Guide to Testing | |
| // Objective is to explain describe(), it(), and before()/etc hooks | |
| // 1. `describe()` is merely for grouping, which you can nest as deep | |
| // 2. `it()` is a test case | |
| // 3. `before()`, `beforeEach()`, `after()`, `afterEach()` are hooks to run | |
| // before/after first/each it() or describe(). | |
| // | |
| // Which means, `before()` is run before first it()/describe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function reportError(error, message) { | |
| message = message || ''; | |
| console.error( | |
| 'ERROR: ' + message + ' [' + error.toString() + ']\n' + | |
| '\nName:\t\t' + (error.name || '-') + | |
| '\nMessage:\t' + (error.message || '-') + | |
| '\nFile:\t\t\t' + (error.fileName || '-') + | |
| '\nSource:\t\t' + ((error.toSource && error.toSource()) || '-') + | |
| '\nLine #:\t\t' + (error.lineNumber || '-') + | |
| '\nColumn #:\t' + (error.columnNumber || '-') + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var renderSearchedProduct = function(products) { | |
| var Product = Backbone.Model.extend({}); | |
| var Products = Backbone.Collection.extend({ | |
| model: Product, | |
| initialize: function() { | |
| this.add(products); | |
| } | |
| }); | |
| PageData.productCollection = new Products(); | |
| var ProductListView = Backbone.View.extend({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); //HTTP server api | |
| var fs = require('fs'); //For working with local files | |
| var server = new http.Server(); //Create a new HTTP server | |
| server.listen(8000); //Run it in port 8000 | |
| //When the server gets a new request, run this function to handle it | |
| server.on("request", function(request, response) { | |
| var url = require('url').parse(request.url); // Parse the requested url | |
| if(url.pathname === "test/delay") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var test = function(x) { return x + test.prop }; | |
| test.prop = 1; | |
| test(5); //logs: 6 | |
| //You don't know how much counter variable I've written till today to outer scope of function |
NewerOlder