<commit_before><!DOCTYPE html>
<html>
<head>
  <title>Event Handling</title>
  <!--
    using jquery here as an example to show how a bigger site would
    handle this. For the simple example, we certainly don't need
    jquery
  -->
  <script src="/jquery.min.js"></script>
  <style type="text/css">

    ul {
        border: 1px solid #6f6f6f;
        height: 100px;
        overflow: auto;
        padding: 15px 40px 15px 40px;
        list-style-type: none;
        margin-bottom: 50px;
    }
    ul li:before {
        display: inline-block;
        width: 2em;
        text-align: center;
        content: "🐄";
    }
  </style>
</head>
<body>
<h1>Event Handling</h1>

<h2>Web Sockets</h2>
<ul id="websockets">
</ul>

<h2>Long Polling</h2>
<ul id="long-polling">
</ul>

<script src="/underscore-min.js"></script>
<script src="/web-sockets.js"></script>
<script src="/long-polling.js"></script>
<script>
    (function(){
        var channel_ws = new EventChannelWs();
        var log_ws = $('#websockets');
        $(channel_ws).bind('cheese_created', function(e){
            log_ws.prepend($('<li>').text(e.pieces + ' pieces of ' + e.cheese_type));
        });

        var channel_lp = new EventChannelLongPoll(
          'cheese',
          (new Date).getTime() / 1000, // good enough
          'foobar'
        );
        var log_lp = $('#long-polling');
        channel_lp.setEnabled(true);
        $(channel_lp).bind('cheese_created', function(e, data){
            log_lp.prepend($('<li>').text(data.pieces + ' pieces of ' + data.cheese_type));
        });

    })();
</script>
</body>
</html><commit_msg>add EventSource support to the frontend<commit_after><!DOCTYPE html>
<html>
<head>
  <title>Event Handling</title>
  <!--
    using jquery here as an example to show how a bigger site would
    handle this. For the simple example, we certainly don't need
    jquery
  -->
  <script src="/jquery.min.js"></script>
  <style type="text/css">

    ul {
        border: 1px solid #6f6f6f;
        height: 100px;
        overflow: auto;
        padding: 15px 40px 15px 40px;
        list-style-type: none;
        margin-bottom: 50px;
    }
    ul li:before {
        display: inline-block;
        width: 2em;
        text-align: center;
        content: "🐄";
    }
  </style>
</head>
<body>
<h1>Event Handling</h1>

<h2>Web Sockets</h2>
<ul id="websockets">
</ul>

<h2>Long Polling</h2>
<ul id="long-polling">
</ul>

<h2>Server-Sent-Events</h2>
<ul id="eventsource">
</ul>

<script src="/underscore-min.js"></script>
<script src="/web-sockets.js"></script>
<script src="/long-polling.js"></script>

<script>
    (function(){
        var channel_ws = new EventChannelWs();
        var log_ws = $('#websockets');
        $(channel_ws).bind('cheese_created', function(e){
            log_ws.prepend($('<li>').text(e.pieces + ' pieces of ' + e.cheese_type));
        });

        var channel_lp = new EventChannelLongPoll(
          'cheese',
          (new Date).getTime() / 1000, // good enough
          'foobar'
        );
        var log_lp = $('#long-polling');
        channel_lp.setEnabled(true);
        $(channel_lp).bind('cheese_created', function(e, data){
            log_lp.prepend($('<li>').text(data.pieces + ' pieces of ' + data.cheese_type));
        });
        var url = [
            '/events/cheese',
            '/?last_event_id=rt-',
            ""+(new Date).getTime() / 1000,
            '&flavor=eventsource'
        ].join('');
        var cheese_channel = new EventSource(url);
        var log_source = $('#eventsource');
        cheese_channel.addEventListener('cheese_created', function(e){
            var data = JSON.parse(e.data);
            log_source.prepend($('<li>').text(data.pieces + ' pieces of ' + data.cheese_type));
        })
    })();
</script>
</body>
</html>
{'fraction_non_alphanumeric': 0.17295597484276728, 'fraction_numerical': 0.016247379454926623, 'mean_word_length': 2.3989314336598397, 'pattern_counts': {'":': 0, '<': 76, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5186073', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1269, 'n_words': 279}