Skip to content

Instantly share code, notes, and snippets.

View objectiveSee's full-sized avatar

Danny Ricciotti objectiveSee

  • Starship Studios
View GitHub Profile
User.transactAndSave(userid, function(user) {
// Q chain here
}, function(err, user) {
});
@objectiveSee
objectiveSee / gist:6246542
Created August 16, 2013 01:42
How can I save the value of foo from changing code in this function only?
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) {
@objectiveSee
objectiveSee / gist:6488719
Last active December 22, 2015 14:58
Optimal card shuffling and dealing algorithm for a multi-player game server.
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.
- (void)_getProductsById:(NSSet *)productIDs
{
NSAssert(self.requestingProducts, @"Should be busy from previous method (getProductsWithCompletion)");
NSAssert(self.productRequest == nil, @"logic");
EALog(@"Getting items: %@", productIDs);
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIDs];
[productRequest setDelegate:self];
var post_options = {
host: 'https://buy.itunes.apple.com',
port: '80',
path: '/verifyReceipt',
method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// 'Content-Length': bodyData.length
// }
@objectiveSee
objectiveSee / gist:6605956
Created September 18, 2013 07:52
Xcode5 is saying Socket.IO uses private selectors
+ (id) objectFromJSONData:(NSData *)data error:(NSError **)error {
Class serializer;
// try SBJson first
serializer = NSClassFromString(@"SBJsonParser");
if (serializer) {
id parser;
id object;
parser = [[serializer alloc] init];
var cluster = require('cluster'),
redis = require("socket.io/node_modules/redis"),
numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
//master process - fork children
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
@objectiveSee
objectiveSee / foo.h
Last active December 23, 2015 23:39
Category that enforces objects in a dictionary are of the type I expect them to be.
/**
THE PROBLEM:
NSDictionary *d = [sever getMeta];
// d.score returns something of type 'NSArray'
NSNumber *userId = [d objectForKey:@"score"];
NSInteger i = [userId integerValue]; // <<------- Now what happens!
Evil Apples is hiring!
=== HOORAY ===
Our App has over 250,000 downloads and at any given moment a TON of socket connections.
We are a Top 5 Word Game and Top 100 Game in the Apple App Store!
We are getting more and more attention every day so it is time to find a Node guru to
take charge. A wizard or Jedi is also acceptable.
No sorcerers. We don't trust sorcerers.
@implementation UIDevice (EAAdditions)
+ (BOOL)isFourInch
{
static dispatch_once_t onceToken;
static BOOL itIs = NO;
dispatch_once(&onceToken, ^{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
itIs = YES;