
var Firebase = require("firebase"); //pull firebase database for Node.js
var myFirebaseRef = new Firebase("https://blinding-fire-9819.firebaseio.com/");  //load firebase location


myFirebaseRef.push({name: "Hello There"})  // push() function generates a unique ID, or key, for each new child so no two posts or data will be saved over each other.-->

		myFirebaseRef.set({
		title: "Hello World!",
		author: "Firebase",
		name: "John",
		location: {
			city: "San Francisco",
			state: "California",
			zip: 94103
			}
		});


		myFirebaseRef.push({name: "YAY!"})  // push() function generates a unique ID, or key, for each new child so no two posts or data will be saved over each other.-->

		myFirebaseRef.update({title: "Hello Earth!"})



		var usersRef = myFirebaseRef.child("users");
usersRef.set({    <!-- Using set() will overwrite the data at the specified locaton, including any child nodes-->
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  },
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"
  }
});

usersRef.child("alanwasawesome").set({   //OR, you can save data directly to child location-->
  date_of_birth: "June 23, 1912",
  full_name: "Alan Turing"
});
usersRef.child("gracehopped").set({
  date_of_birth: "December 9, 1906",
  full_name: "Grace Hopper"
});

var hopperRef = myFirebaseRef.child("users/gracehop");
hopperRef.update({     // If we used set() instead, their full_name and date_of_birth would have been deleted.
  "nickname": "The Amazing Grace"
});

var hopperrRef = usersRef.child("gracehop");
hopperRef.update({     // Could use the previous function created that is already in users
  "Email": "asdf@gmail.com"
});

// Me playing around with it
var newpostref = myFirebaseRef.child("posts");
	var newpushref = newpostref.push(); // Generate a reference to a new location and add some data using push()
	newpushref.set({
	"name":"woo!"
})

// setting var for posting a push with set
var postsRef = myFirebaseRef.child("posts");
  var newPostRef = postsRef.push();
  newPostRef.set({
    author: "John",
		title: "Here is an interesting article"
  });

// we can also chain the two calls together (next command combines it)
  postsRef.push().set({
    author: "alanisawesome",
    title: "The Turing Machine"
  });

// Get the unique ID generated by push()
	var postID = newPostRef.key();


// the pattern of calling push() and then immediately calling set() is so common that you can combine them: postsref.push({...}) is the same as postsref.push(); then newpostref.set({...})
  postsRef.push({
    author: "gracehop",
    title: "Announcing COBOL, a New Programming Language"
  });

	// Record the current time immediately, and queue an event to record the tiem as which the user disconnects
	var mySessionRef = myFirebaseRef.push();
	mySessionRef.onDisconnect().update({ endedAt: Firebase.ServerValue.TIMESTAMP });
	mySessionRef.update({
		name: "Drew",
		startedAt: Firebase.ServerValue.TIMESTAMP
	});
// Record the current time without var mySessionRef
	myFirebaseRef.push().onDisconnect().update({ endedAt: Firebase.ServerValue.TIMESTAMP });
	myFirebaseRef.push().update({
		name: "Carlos",
		startedAt: Firebase.ServerValue.TIMESTAMP
	});

	// Later, retrieve the data by ordered date (Guaranteed Chronological Ordering)
	myFirebaseRef.orderByChild('date').on('child_added', function(snapshot) {
	    //Do something with ordered children
	});

	var fredRef = new Firebase("https://samplechat.firebaseio-demo.com/users/fred");
	var key = fredRef.key()  // key === "fred"
	key = fredRef.child("name/last").key()  // key === "last"

	var rootRef = new Firebase("https://samplechat.firebaseio-demo.com");
	var key = rootRef.key()  // key === null

e5c00b4cdc2d7603c670693797b3356d8b7ce913

var Firebase = require("firebase"); //pull firebase database for Node.js
var myFirebaseRef = new Firebase("https://blinding-fire-9819.firebaseio.com/");  //load firebase location


myFirebaseRef.push({name: "Hello There"})  // push() function generates a unique ID, or key, for each new child so no two posts or data will be saved over each other.-->

		myFirebaseRef.set({
		title: "Hello World!",
		author: "Firebase",
		name: "John",
		location: {
			city: "San Francisco",
			state: "California",
			zip: 94103
			}
		});


		myFirebaseRef.push({name: "YAY!"})  // push() function generates a unique ID, or key, for each new child so no two posts or data will be saved over each other.-->

		myFirebaseRef.update({title: "Hello Earth!"})



		var usersRef = myFirebaseRef.child("users");
usersRef.set({    <!-- Using set() will overwrite the data at the specified locaton, including any child nodes-->
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  },
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"
  }
});

usersRef.child("alanwasawesome").set({   //OR, you can save data directly to child location-->
  date_of_birth: "June 23, 1912",
  full_name: "Alan Turing"
});
usersRef.child("gracehopped").set({
  date_of_birth: "December 9, 1906",
  full_name: "Grace Hopper"
});

var hopperRef = myFirebaseRef.child("users/gracehop");
hopperRef.update({     // If we used set() instead, their full_name and date_of_birth would have been deleted.
  "nickname": "The Amazing Grace"
});

var hopperrRef = usersRef.child("gracehop");
hopperRef.update({     // Could use the previous function created that is already in users
  "Email": "asdf@gmail.com"
});

// Me playing around with it
var newpostref = myFirebaseRef.child("posts");
	var newpushref = newpostref.push(); // Generate a reference to a new location and add some data using push()
	newpushref.set({
	"name":"woo!"
})

// setting var for posting a push with set
var postsRef = myFirebaseRef.child("posts");
  var newPostRef = postsRef.push();
  newPostRef.set({
    author: "John",
		title: "Here is an interesting article"
  });

// we can also chain the two calls together (next command combines it)
  postsRef.push().set({
    author: "alanisawesome",
    title: "The Turing Machine"
  });

// Get the unique ID generated by push()
	var postID = newPostRef.key();


// the pattern of calling push() and then immediately calling set() is so common that you can combine them: postsref.push({...}) is the same as postsref.push(); then newpostref.set({...})
  postsRef.push({
    author: "gracehop",
    title: "Announcing COBOL, a New Programming Language"
  });

	// Record the current time immediately, and queue an event to record the tiem as which the user disconnects
	var mySessionRef = myFirebaseRef.push();
	mySessionRef.onDisconnect().update({ endedAt: Firebase.ServerValue.TIMESTAMP });
	mySessionRef.update({
		name: "Drew",
		startedAt: Firebase.ServerValue.TIMESTAMP
	});
// Record the current time without var mySessionRef
	myFirebaseRef.push().onDisconnect().update({ endedAt: Firebase.ServerValue.TIMESTAMP });
	myFirebaseRef.push().update({
		name: "Carlos",
		startedAt: Firebase.ServerValue.TIMESTAMP
	});

	// Later, retrieve the data by ordered date (Guaranteed Chronological Ordering)
	myFirebaseRef.orderByChild('date').on('child_added', function(snapshot) {
	    //Do something with ordered children
	});

	var fredRef = new Firebase("https://samplechat.firebaseio-demo.com/users/fred");
	var key = fredRef.key()  // key === "fred"
	key = fredRef.child("name/last").key()  // key === "last"

	var rootRef = new Firebase("https://samplechat.firebaseio-demo.com");
	var key = rootRef.key()  // key === null
