Created
August 5, 2013 12:10
-
-
Save radiosilence/6155463 to your computer and use it in GitHub Desktop.
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
# Search for 'keywords' in parallel, then callback | |
# 'cb' with an array of the parallel results | |
parallelSearch = (keywords, cb) -> | |
out = [] | |
await | |
for k,i in keywords | |
search k, defer out[i] | |
cb out | |
rankPopularity = (keywords, cb) -> | |
await parallelSearch keywords, defer results | |
times = for r,i in results | |
last = r[r.length - 1] | |
[(new Date last.created_at).getTime(), i] | |
times = times.sort (a,b) -> b[0] - a[0] | |
cb (keywords[tuple[1]] for tuple in times) | |
# Search for the most popular food and the most | |
# popular weather pattern in parallel. | |
w_list = [ "sun", "rain", "snow", "sleet" ] | |
f_list = [ "tacos", "burritos", "pizza", "shrooms" ] | |
await | |
rankPopularity w_list, defer weather | |
rankPopularity f_list, defer food | |
# If we got results for both, do a final search | |
if weather.length and food.length | |
await search "#{weather[0]}+#{food[0]}", defer tweets | |
msg = tweets[0]?.text | |
# Alert the results to the browser | |
alert if msg? then msg else "<nothing found>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment