Skip to content

Instantly share code, notes, and snippets.

@amitu amitu/demo.html
Created Mar 15, 2012

Embed
What would you like to do?
Stock Updater Hammer Application
<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>
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
You can’t perform that action at this time.