Featured Post

Organize and rename photos by EXIF data with PowerShell

This PowerShell script organizes and renames all photos in a selected folder using EXIF data. It will also create thumbnails of the images i...

Thursday, June 26, 2014

Prevent jQuery UI dialog from blocking TinyMCE focusin

Including a TinyMCE textarea inside a jQuery UI dialog I found that I could not click or bring focus to the field in order to type in it.

A quick JavaScript solution directly from TinyMCE:


<script>
    // Prevent jQuery UI dialog from blocking focusin
    $(document).on('focusin', function(e) {
        if ($(event.target).closest(".mce-window").length) {
            e.stopImmediatePropagation();
        }
    });
</script>

Friday, June 6, 2014

How to get Bitstamp real time data through WebSocket streaming using Pusher

References:



Save the following into a file called index.html and open it in a browser, hit F12 to view the Console and that is it! You will start seeing real time Bitcoin market trading data from Bitstamp.

It uses WebSockets and Pusher to get a constant stream of data instead of the traditional method of pulling from an API every 10 seconds.

Click here to see a working sample.


<!DOCTYPE html>
<head>
  <title>Bitstamp realtime trade ticket via WebSocket Pusher</title>
  <script src="http://js.pusher.com/2.2/pusher.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    // Enable pusher logging - don't include this in production
    Pusher.log = function(message) {
      if (window.console && window.console.log) {
        window.console.log(message);
 if (message.id !== undefined)
 {
//   window.console.log('id:' + message.id + ' price: ' + message.price + ' amount: ' + message.amount);
 }
      }
    };

    // Bitstamp Live Ticker
    var pusher = new Pusher('de504dc5763aeef9ff52');
    var channel = pusher.subscribe('live_trades');
    channel.bind('trade', function(data) {
      window.console.log('id:' + data.id + ' price: ' + data.price + ' amount: ' + data.amount);
    });
  </script>
</head>