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
### Keybase proof | |
I hereby claim: | |
* I am crabasa on github. | |
* I am carterrabasa (https://keybase.io/carterrabasa) on keybase. | |
* I have a public key whose fingerprint is BBF3 AD23 FD40 EC24 1E16 BF9F 4495 F1D3 412F B86B | |
To claim this, I am signing this object: |
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 d = domain.create(); | |
d.on("error", function(error) { | |
// handle it | |
}); | |
d.run(function() { | |
// deeply nested and possibly async code | |
}); |
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
#pragma mark * UIView methods | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
// Synchronous networking on the main thread is seriously bad - only doing this for | |
// demo purposes | |
NSURL* url = [NSURL URLWithString:@"https://your-domain.azurewebsites.net/capability"]; | |
NSURLResponse* response = nil; |
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 'twilio-ruby' | |
require './creds' | |
# initialize Twilio client | |
client = Twilio::REST::Client.new(Creds.ACCOUNT_SID, Creds.AUTH_TOKEN) | |
# groups all phone numbers based on number of correct answers to trivia questions | |
pool = [ | |
[3, ["a", "b", "c"]], | |
[2, ["d", "e", "f"]], |
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
{ "_id": "event:demo", | |
"type": "event", | |
"shortname": "demo", | |
"name": "My Cool Demo Event", | |
"phonenumber": "+15555551212", | |
"state": "on", | |
"voteoptions": [{ "id": 1, "name": "foo"}, { "id": 2, "name": "bar"}, { "id": 3, "name": "baz"}] | |
} | |
{ "_id": "vote:event:demo:+15555551111", |
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
{ "_id": "123", | |
"shortname": "demo", | |
"name": "My Cool Demo Event", | |
"phonenumber": "+15555551212", | |
"state": "on", | |
"voteoptions": [ | |
{ "id": 1, "name": "foo", "votes": 2, "numbers": ["+15555551111", "+15555552222"] }, | |
{ "id": 2, "name": "bar", "votes": 0, "numbers": [] }, | |
{ "id": 3, "name": "baz", "votes": 1, "numbers": ["+1555555333"] }] | |
} |
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
flushVotes = function() { | |
var votesToSave = _und.values(votesCache); | |
votesCache = {}; | |
if (votesToSave.length > 0) { | |
db.bulk({docs: votesToSave}, function(err, body) { | |
if (err) { | |
console.log("Failed to save votes, popping them back on the cache"); | |
votesToSave.forEach(function(v) { | |
votesCache[v._id] = v; |
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
saveVote = exports.saveVote = function(event, vote, from) { | |
// The _id of our vote document will be a composite of our event_id and the | |
// person's phone number. This will guarantee one vote per event | |
var voteDoc = { | |
_id: 'vote:' + event._id + ':' + from, | |
type: 'vote', | |
event_id: event._id, | |
event_phonenumber: event.phonenumber, | |
vote: vote, |
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
findBy = exports.findBy = function(view, params, callback) { | |
var event; | |
if (event = eventsCache[view+JSON.stringify(params)]) { | |
callback(null, event); | |
} | |
else { | |
db.view('event', view, params, function(err, body) { | |
if (err) { | |
console.log(err); |
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
findByPhonenumber = exports.findByPhonenumber = function(phonenumber, callback) { | |
findBy('byPhonenumber', {key: phonenumber}, function(err, event) { | |
if (err) { | |
callback(err, null); | |
} | |
else { | |
findBy('all', {key: [event._id], reduce: false}, callback); | |
} | |
}); | |
} |