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
// Loading a Track | |
var track = Track.fromURI(uri, function(track) { | |
console.log(track.name + " loaded!"); | |
if (track.playable) | |
// handle case in which some tracks are not playable | |
[...] | |
}); | |
// Loading an Album |
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 GitGoggles = { | |
getRepos: function(callback) { | |
this._get('repositories', callback); | |
}, | |
getRepo: function(repo, callback) { | |
this._get('repository/' + repo, callback); | |
}, | |
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
static NSString *CellID = @"CustomCell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID]; | |
UIImage *rainbow = [UIImage imageNamed:@"rainbow"]; | |
UIImageView *mainImageView = [[UIImageView alloc] initWithImage:rainbow]; | |
UIImageView *otherImageView = [[UIImageView alloc] initWithImage:rainbow]; | |
CGRect iconFrame = (CGRect) { { 12.0, 4.0 }, rainbow.size }; |
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
@interface KTEManagedTableViewCell : UITableViewCell { } | |
+ (id)cellForTableView:(UITableView *)tableView; | |
+ (id)cellForTableView:(UITableView *)tableView fromNib:(UINib *)nib; | |
+ (NSString *)cellIdentifier; | |
- (id)initWithCellIdentifer:(NSString *)cellID; | |
@end |
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
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
KTEDoubleRainbowCell *cell = [KTEDoubleRainbowCell cellForTableView:tableView]; | |
cell.mainLabel.text = [self.quotes objectAtIndex:indexPath.row]; | |
return cell; | |
} |
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
// A module that can be mixed in to *any object* in order to provide it with | |
// custom events. You may bind with `on` or remove with `off` callback | |
// functions to an event; `trigger`-ing an event fires all callbacks in | |
// succession. | |
// | |
// var object = {}; | |
// _.extend(object, Backbone.Events); | |
// object.on('expand', function(){ alert('expanded'); }); | |
// object.trigger('expand'); | |
// |
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
$(document).ready(function() { | |
module("Backbone.Events"); | |
test("on and trigger", 2, function() { | |
var obj = { counter: 0 }; | |
_.extend(obj,Backbone.Events); | |
obj.on('event', function() { obj.counter += 1; }); | |
obj.trigger('event'); | |
equal(obj.counter,1,'counter should be incremented.'); |
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
Board.prototype.isWinner = function () { | |
if ((this.state[0] == this.state[1] == this.state[2] == 1) | |
|| (this.state[3] == this.state[4] == this.state[5] == 1) | |
|| (this.state[6] == this.state[7] == this.state[8] == 1) | |
|| (this.state[0] == this.state[3] == this.state[6] == 1) | |
|| (this.state[1] == this.state[4] == this.state[7] == 1) | |
|| (this.state[2] == this.state[5] == this.state[8] == 1) | |
|| (this.state[0] == this.state[4] == this.state[8] == 1) | |
|| (this.state[1] == this.state[4] == this.state[6] == 1)) { | |
return 1; |
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
describe('minimax', function () { | |
var INFINITY = 1.7976931348623157E+10308; | |
var N_INFINITY = -1.7976931348623157E+10308; | |
var COMPUTER = 1; | |
var HUMAN = 2; | |
it('should return INFINITY when computer has won', function () { | |
var state = [1, 1, 1, -1, -1, -1, -1, 2, 2]; | |
var board = new Board(state); |
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
describe('isWinner', function () { | |
var COMPUTER = 1; | |
var HUMAN = 2; | |
it('should return COMPUTER if the computer has won', function () { | |
var state = [1, 1, 1, -1, -1, -1, -1, 2, 2]; | |
var board = new Board(state); | |
assert.equal(board.isWinner(), COMPUTER); /* assertion passes */ | |
}) |
OlderNewer