Skip to content

Instantly share code, notes, and snippets.

@amitu
Created March 15, 2012 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitu/2042557 to your computer and use it in GitHub Desktop.
Save amitu/2042557 to your computer and use it in GitHub Desktop.
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