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
THE PROBLEM: | |
A game server deals hands of cards to each player in a multi-player game. | |
The ideal user experience is for players to be able to play multiple | |
games (with random opponents) and not be dealt repeated cards until | |
they have seen most of the cards in the deck. | |
CONDITIONS: | |
1. Each card has a unique id. |
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
if(request.args.game_id === undefined) { | |
var foo = undefined; | |
Game.transactById(request.args.game_id, function(err, game) { | |
foo = game.participantDiscards(request.getUserId(), request.args.card_id_array); | |
}, function(err, game) { |
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
User.transactAndSave(userid, function(user) { | |
// Q chain here | |
}, function(err, user) { | |
}); |
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
Analyzing dependencies | |
[31m[!] Pod::Executable pull | |
Updating a1d1b07..de42d82 | |
error: Your local changes to the following files would be overwritten by merge: | |
AFKissXMLRequestOperation/0.0.1/AFKissXMLRequestOperation.podspec | |
AdMob/6.4.2/AdMob.podspec |
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
return Q.fcall(game.makeDeckIfNeeded.bind(game)) | |
.then(game.deck.drawAnswers(participant, cardsToGet)) | |
.then(function(newCards) { | |
// add newcards to hand | |
var newHand = _.union(h,newCards); | |
participant.hand = newHand; | |
return Q.fcall(function() { return game.update(); }); | |
}); |
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
/** | |
* NOTE: game.participants contains 3 objects. | |
GOAL: I would like each promise created in lines 31-43 to be executed in serial. | |
I do not want any line of code in drawAnswers() to be called before the previous promise is fulfilled. | |
BUG: The log in drawAnswers() shows me that drawAnswers() is being called 3 times before the | |
1st promise from drawAnswers() is fulfilled. |
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
shitFinder.findGamesPastDay() | |
.then(shitFinder.printShit()) | |
.done(function (result) { | |
console.log('DONE! res=', result); // logs the result from findGamesPastDay instead of foo | |
process.exit(0) | |
}, function (error) { | |
process.exit(1); | |
}); | |
printShit: function(result) { |
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
// bootstrap! | |
require('../lib/globals.js'); | |
(function() { | |
var HttpServer = require('../lib/http_server.js'); | |
var SocketServer = require('../lib/socket_server.js'); | |
var h = new HttpServer(); | |
var s = new SocketServer(); |
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
double delayInSeconds = 0.3; | |
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); | |
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ | |
NSLog(@"!!!!!!! Go time !!!!!!"); | |
EAForcedUpdateViewController *f = [[EAForcedUpdateViewController alloc] initWithNibName:nil bundle:nil]; | |
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
window.rootViewController = f; | |
// [self.window resignKeyWindow]; | |
// [self.window setHidden:YES]; |
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
/** | |
* question: how can I rewrite lines 8 & 9 to not use an intermediate function? | |
* | |
* | |
*/ | |
Q.fcall(this.findGamesNearby.bind(this,user,location)) | |
.then(function(games_nearby) { | |
return matchmaking.makeGameIfNeeded(games_nearby, user, location); | |
}); |