Skip to content

Instantly share code, notes, and snippets.

Anant Narayanan anantn

Block or report user

Report or block anantn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
anantn / firebase_detect_data.js
Created Dec 18, 2012
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
View firebase_detect_data.js
function go() {
var userId = prompt('Username?', 'Guest');
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
anantn / firebase_player_assignment.js
Last active Jan 17, 2020
Firebase: Assigning players in a multiplayer game. This snippet assigns you a spot in a game if the game isn't full yet.
View firebase_player_assignment.js
function go() {
var userId = prompt('Username?', 'Guest');
// Consider adding '/<unique id>' if you have multiple games.
var gameRef = new Firebase(GAME_LOCATION);
assignPlayerNumberAndPlayGame(userId, gameRef);
// The maximum number of players. If there are already
// NUM_PLAYERS assigned, users won't be able to join the game.
var NUM_PLAYERS = 4;
anantn / getusermedia_picture.html
Created Feb 17, 2012
Take a picture with getUserMedia
View getusermedia_picture.html
<video id="v" width="300" height="300"></video>
<input id="b" type="button" disabled="true" value="Take Picture"></input>
<canvas id="c" style="display:none;" width="300" height="300"></canvas>
navigator.getUserMedia({video: true}, function(stream) {
var video = document.getElementById("v");
var canvas = document.getElementById("c");
anantn / firebase_snapshot_parent.js
Last active Sep 30, 2019
Firebase: Get the parent of a snapshot.
View firebase_snapshot_parent.js
function getParent(snapshot) {
// You can get the reference (A Firebase object) from a snapshot
// using .ref().
var ref = snapshot.ref();
// Now simply find the parent and return the name.
return ref.parent().name();
var testRef = new Firebase("");
testRef.once("value", function(snapshot) {
anantn / firebase_remove_pushed.js
Last active Feb 19, 2019
Firebase: Removing an item you've pushed. This snippet shows how to remove an object that you just added using push().
View firebase_remove_pushed.js
function pushSomething(ref) {
// Let's push something. push() returns a reference that you can hold onto!
var justPushed = ref.push({test: "push"});
// We return a reference, but you can also return the name of the newly
// created object with .name().
return justPushed;
function removeItem(ref) {
// Now we can get back to that item we just pushed via .child().
anantn / firebase_create.js
Last active Feb 1, 2019
Firebase: Creating data if it doesn't exist. This snippet creates a user only if it doesn't already exist.
View firebase_create.js
function go() {
var userId = prompt('Username?', 'Guest');
var userData = { name: userId };
tryCreateUser(userId, userData);
function userCreated(userId, success) {
if (!success) {
anantn / firebase_chat.html
Created May 6, 2013
A simple, plugin-free chat room - build with Firebase
View firebase_chat.html
<script src=""></script>
<ul id="chat-list">
<input type="text" id="msg"/>
<input type="button" id="send" value="Send"/>
anantn / datachannels.js
Created Oct 31, 2012
Data Channel Example
View datachannels.js
* Assume we've connected a PeerConnection with a friend - usually with audio
* and/or video. For the time being, always at least include a 'fake' audio
* stream - this will be fixed soon.
* connectDataConnection is a temporary function that will soon disappear.
* The two sides need to use inverted copies of the two numbers (eg. 5000, 5001
* on one side, 5001, 5000 on the other)
pc.connectDataConnection(5001, 5000);
anantn / firebase_workers.js
Created Dec 27, 2012
Firebase: Implementing a worker queue pattern using firebase_queue_pop.js
View firebase_workers.js
var Firebase = require("./firebase-node.js");
function Queue(ref) {
this._ref = ref;
Queue.prototype.pop = function(cb) {
this._ref.startAt().limit(1).once("child_added", this._pop.bind(this, cb));

Keybase proof

I hereby claim:

  • I am anantn on github.
  • I am anant ( on keybase.
  • I have the public key with fingerprint 42DD 4F90 7C5F 4576 D6F4  2202 C31C 2D8C 7B4B 6B02

To claim this, I am signing this object:

You can’t perform that action at this time.