<commit_before>$( document ).ready(function() {
  console.log( "Ready!" );
  var myFirebaseRef = new Firebase("https://haunted.firebaseio.com/");
  var roomSession = $( "#room-session" ).val();
  var myFirebaseRoom = myFirebaseRef.child(roomSession);
  var myFirebaseChat = myFirebaseRoom.child("chat")
  myFirebaseChat.on("child_added", function(snapshot) {
    var message = snapshot.val().message;
    $( "#msg-output" ).append(message.name + " said: " + message.content + "<br>");
  });

  $( "#chat-form" ).submit(function( event ) {
    event.preventDefault();
    
    var userName = $('#user-name').val()
    var messageContent = $('#msg-input').val()
    $( "#msg-input" ).val("");

    myFirebaseChat.push({
      message : {
        name: userName,
        content: messageContent,
        timestamp: Firebase.ServerValue.TIMESTAMP
      }
    });
  });
});<commit_msg>extract some functionality into setup, send, and recieve functions<commit_after>$(document).ready(function() {

  // Setup
  var roomSession = $("#room-session").val();
  if (typeof roomSession !== "undefined") {
    var firebase = new firebaseSetup(roomSession);
  }

  // Recieve a message
  firebase.chat.on("child_added", recieveMessage);

  // Send a message
  $("#chat-form").submit(function(event) {
    event.preventDefault();
    var name = $("#user-name").val()
    var message = $("#msg-input").val()
    $("#msg-input").val("");
    sendMessage(firebase, name, message);
  });

});

function firebaseSetup(roomSession) {
  this.ref = new Firebase("https://haunted.firebaseio.com/");
  this.room = this.ref.child(roomSession);
  this.chat = this.room.child("chat");
}

var recieveMessage = function(snapshot) {
  var message = snapshot.val().message;
  $("#msg-output").append(message.name + " said: " + message.content + "<br>");
}

var sendMessage = function(firebase, name, content) {
  firebase.chat.push({
    message : {
      name: name,
      content: content,
      timestamp: Firebase.ServerValue.TIMESTAMP
    }
  });
}
{'fraction_non_alphanumeric': 0.1835724888668976, 'fraction_numerical': 0.0, 'mean_word_length': 3.6164383561643834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4126524', 'n_tokens_mistral': 631, 'n_tokens_neox': 634, 'n_words': 122}