Created
March 15, 2012 06:40
-
-
Save amitu/2042557 to your computer and use it in GitHub Desktop.
Stock Updater Hammer Application
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
<script src="/static/hammerlib.min.js"></script> | |
<script> | |
$(function(){ | |
hammerlib.bind("hammerlib", "opened", function(data) { | |
hammerlib.subscribe("stock_ticker"); | |
}); | |
hammerlib.bind("stock_ticker", "updated", function(data) { | |
$.each(["hammer", "gamma", "spacemonkey", "unicorn"], function(i, stock) { | |
var key = stock + "_ticker"; | |
if(data[key]) $("#" + key).text(data[key]); | |
}); | |
}); | |
hammerlib.initialize("http://ws.gethammer.co/", "demo.gethammer.co", "user_anon"); | |
}); | |
</script> |
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
import hammerlib, time, random | |
hammerlib.init_hha("demo.gethammer.co", "<<secret key>>") | |
def send_updates(): | |
hammerlib.send_message_to_channel( | |
"js.stock_ticker", "stock_ticker", "updated", { | |
stock + "_ticker": "%.2f" % (random.random() * 100) | |
for stock in random.sample( | |
["hammer", "gamma", "spacemonkey", "unicorn"], | |
random.randint(1, 4) | |
) | |
} | |
) | |
while True: | |
try: | |
send_updates() | |
except Exception, e: | |
print e, "retrying" | |
time.sleep(random.random() * 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment