This file contains 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
class Test | |
waitForTwoCalls: () -> | |
$.when(@firstCall(), @secondCall()).then () => | |
doSomeThing() | |
firstCall: () -> | |
token = $.Deferred | |
$.ajax({ | |
url: foo/bar, |
This file contains 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
# Makes ajax req to fetch data | |
class Model | |
initialize(id) | |
@id = id | |
load: (token) -> | |
$.ajax({ | |
url: "foo/bar/#{@id}", | |
.... | |
success: (response) => |
This file contains 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
MaxLength = N | |
valid_string = some_long_text[0,N] if some_long_text.length > N |
This file contains 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 fs = require('fs'); | |
var spawnProcess = require('child_process').spawn; | |
var filename = 'some/file' | |
fs.watch(filename, function() { | |
var list = spawnProcess('ls', ['-lh', filename]); | |
var info = ''; | |
// listener get invoked every time a chunk of data is available. Data is read in chunks | |
list.stdout.on('data', function(chunk) { |
This file contains 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 MongoClient = require('mongodb').MongoClient; | |
var connectionString = 'mongodb://localhost:27017/test'; | |
// connect to test db | |
MongoClient.connect(connectionString, function(err, db) { | |
if(err) throw err; | |
console.log("CONNECTED"); | |
var q = {name: 'Super Man'}; | |
// query superheroes collection and display result |
This file contains 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
// Represents the node in the tree. Will be displayed as a small circle in the browser. | |
// x, y --> x, y co-ordinates of the center of circle | |
// r --> radius of the circle | |
// ctx --> context of the canvas | |
// data --> data to be displayed (Only number) | |
var Node = function(x,y,r, ctx, data) { | |
// left child of a node | |
this.leftNode = null; | |
// right child of a node |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
.center {margin: auto; width: 50%;} | |
<style> | |
</head> | |
<body> | |
<div class='input-box'> | |
<input id='tree-input' type='number' placeholder='Enter number'> |
This file contains 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
// Draws a line from one circle(node) to another circle (node) | |
var Line = function() { | |
// Takes | |
// x,y - starting x,y coordinate | |
// toX, toY - ending x,y coordinate | |
this.draw = function(x, y, toX, toY, r, ctx) { | |
var moveToX = x; | |
var moveToY = y + r; | |
var lineToX = toX; | |
var lineToY = toY - r; |
This file contains 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
// Represents the btree logic | |
var BTree = function() { | |
var c = document.getElementById('my-canvas'); | |
var ctx = c.getContext('2d'); | |
var line = new Line(); | |
this.root = null; | |
var self = this; | |
// Getter for root |
This file contains 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 addToTree = function() { | |
input = document.getElementById('tree-input'); | |
value = parseInt(input.value); | |
if(value) | |
btree.add(value); | |
else | |
alert("Wrong input"); | |
}; |
OlderNewer