<commit_before><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/style/favicon.ico">

<title>Popular Subreddits</title>

<!-- Bootstrap core CSS -->
<link href="./css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/jumbotron.css" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="./js/ie-emulation-modes-warning.js"></script>

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#"></a>
    </div>
  </div>
</div>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
    <h1>Popular Subreddits</h1>
  </div>
</div>
<div class="container">

  <!--
  <% subreddits.each_with_index do |subreddit, index| %>
    <% if index % 3 == 0 %><div class="row"><% end %>

    <div class="col-md-4">
      <h2><%= subreddit.display_name %></h2>
      <ul>
        <% subreddit.hot.each do |topic| %>
          <li><a href="<%= topic.url %>" title="<%= topic.title %>"><%= topic.title.truncate(40, separator: /\s/) %></a></li>
      <% end %>
      </ul>
      <p><a href="<%= subreddit.url %>" class="btn btn-default" href="#" role="button">Visit <%= subreddit.display_name %> &raquo;</a></p>
    </div>

    <% if (index+1) % 3 == 0 || index == subreddits.length-1%></div><% end %>
<% end %>
-->

  <hr>

  <footer>
    <p>&copy; <NAME> 2015</p>
  </footer>
</div> <!-- /container -->


<!-- Bootstrap core JavaScript
    ================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="./js/jquery-1.11.2.js"></script>
<script src="./js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="./js/ie10-viewport-bug-workaround.js"></script>

<script>
// http://www.reddit.com/dev/api
// 
// listings
// 
// Many endpoints on reddit use the same protocol for controlling pagination and filtering.
// These endpoints are called Listings and share five common parameters: after / before,
// limit, count, and show.
// 
// Listings do not use page numbers because their content changes so frequently. Instead,
// they allow you to view slices of the underlying data. Listing JSON responses contain after
// and before fields which are equivalent to the "next" and "prev" buttons on the site and in
// combination with count can be used to page through the listing.
// 
// The common parameters are as follows:
// 
// after / before - only one should be specified. these indicate the fullname of an item in the
//                  listing to use as the anchor point of the slice.
// limit - the maximum number of items to return in this slice of the listing.
// count - the number of items already seen in this listing. on the html site, the builder uses
//         this to determine when to give values for before and after in the response.
// show - optional parameter; if all is passed, filters such as "hide links that I have voted on"
//        will be disabled.
// To page through a listing, start by fetching the first page without specifying values for after
// and count. The response will contain an after value which you can pass in the next request. It
// is a good idea, but not required, to send an updated value for count which should be the number
// of items already fetched.

var base_url = 'http://www.reddit.com/';

function getLimitQS(max) {
  return (max === undefined ? '' : '?limit=' + max);
}

function asyncPopularSubreddits(max) {
  var limit = getLimitQS(max);

  $.getJSON(base_url + 'subreddits/popular.json' + limit, function(response){
    var subreddits = $.map(response.data.children, function(child){
      var subreddit = child.data.display_name;
      return {
        subreddit: subreddit,
        topics: hotTopicsDeferred(subreddit, 4)
      };
    });

    $.when.apply(null, subreddits).done(function(){
      for (var i = 0; i < arguments.length; i++) {
        console.log(arguments[i]);
      }
      console.log('all done');
    });
  });
}

function hotTopicsDeferred(subreddit, max) {
  var limit = getLimitQS(max);
  var promise = $.Deferred();

  $.getJSON(base_url + '/r/' + subreddit + '/hot.json' + limit , function(response){
    var topics = $.map(response.data.children, function(child){
      return {
        subreddit: subreddit,
        title: child.data.title,
        url: child.data.url
      };
    });
    promise.resolve(topics);
  });

  return promise;
}

$(document).ready(function(){
  asyncPopularSubreddits(3);
});

</script>

</body>
</html>
<commit_msg>Successfully retrieving subsequent Reddit data sets.<commit_after><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/style/favicon.ico">

<title>Popular Subreddits</title>

<!-- Bootstrap core CSS -->
<link href="./css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/jumbotron.css" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="./js/ie-emulation-modes-warning.js"></script>

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#"></a>
    </div>
  </div>
</div>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
    <h1>Popular Subreddits</h1>
  </div>
</div>
<div class="container">

  <!--
  <% subreddits.each_with_index do |subreddit, index| %>
    <% if index % 3 == 0 %><div class="row"><% end %>

    <div class="col-md-4">
      <h2><%= subreddit.display_name %></h2>
      <ul>
        <% subreddit.hot.each do |topic| %>
          <li><a href="<%= topic.url %>" title="<%= topic.title %>"><%= topic.title.truncate(40, separator: /\s/) %></a></li>
      <% end %>
      </ul>
      <p><a href="<%= subreddit.url %>" class="btn btn-default" href="#" role="button">Visit <%= subreddit.display_name %> &raquo;</a></p>
    </div>

    <% if (index+1) % 3 == 0 || index == subreddits.length-1%></div><% end %>
<% end %>
-->

  <hr>

  <footer>
    <p>&copy; <NAME> 2015</p>
  </footer>
</div> <!-- /container -->


<!-- Bootstrap core JavaScript
    ================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="./js/jquery-1.11.2.js"></script>
<script src="./js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="./js/ie10-viewport-bug-workaround.js"></script>

<script>
// http://www.reddit.com/dev/api
// 
// listings
// 
// Many endpoints on reddit use the same protocol for controlling pagination and filtering.
// These endpoints are called Listings and share five common parameters: after / before,
// limit, count, and show.
// 
// Listings do not use page numbers because their content changes so frequently. Instead,
// they allow you to view slices of the underlying data. Listing JSON responses contain after
// and before fields which are equivalent to the "next" and "prev" buttons on the site and in
// combination with count can be used to page through the listing.
// 
// The common parameters are as follows:
// 
// after / before - only one should be specified. these indicate the fullname of an item in the
//                  listing to use as the anchor point of the slice.
// limit - the maximum number of items to return in this slice of the listing.
// count - the number of items already seen in this listing. on the html site, the builder uses
//         this to determine when to give values for before and after in the response.
// show - optional parameter; if all is passed, filters such as "hide links that I have voted on"
//        will be disabled.
// To page through a listing, start by fetching the first page without specifying values for after
// and count. The response will contain an after value which you can pass in the next request. It
// is a good idea, but not required, to send an updated value for count which should be the number
// of items already fetched.

var base_url = 'http://www.reddit.com/';
var count = 0;
var after = null;

function buildQS(options) {
  var data = $.extend({
    after: after,
    count: count,
    limit: 25
  }, options);

  var qs = '?';

  for (var key in data) {
    if (data[key] !== undefined) {
      qs += key + '=' + data[key] + '&'
    }
  }

  console.log(qs);
  return qs;
}

function asyncPopularSubreddits(limit) {
  var qs = buildQS({limit: limit});

  $.getJSON(base_url + 'subreddits/popular.json' + qs, function(response){

    after = response.data.after
    count += response.data.children.length;

    console.log('after: ' + after);
    console.log('count: ' + count);

    var subreddits = $.map(response.data.children, function(child){
      var subreddit = child.data.display_name;
      return {
        subreddit: subreddit,
        topics: hotTopicsDeferred(subreddit, 4)
      };
    });

    $.when.apply(null, subreddits).done(function(){
      for (var i = 0; i < arguments.length; i++) {
        console.log(arguments[i]);
      }
      console.log('all done');
      if (count < 9) {
        asyncPopularSubreddits(3);
      }
    });
  });
}

function hotTopicsDeferred(subreddit, limit) {
  var qs = buildQS({limit: limit});
  var promise = $.Deferred();

  $.getJSON(base_url + '/r/' + subreddit + '/hot.json' + qs , function(response){
    var topics = $.map(response.data.children, function(child){
      return {
        subreddit: subreddit,
        title: child.data.title,
        url: child.data.url
      };
    });
    promise.resolve(topics);
  });

  return promise;
}

$(document).ready(function(){
  asyncPopularSubreddits(3);
});

</script>

</body>
</html>

{'fraction_non_alphanumeric': 0.17601694915254237, 'fraction_numerical': 0.008220338983050848, 'mean_word_length': 3.1670197740112993, 'pattern_counts': {'":': 0, '<': 224, '<?xml version=': 0, '>': 221, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '6019626', 'n_tokens_mistral': 3826, 'n_tokens_neox': 3659, 'n_words': 1120}