Skip to content

Instantly share code, notes, and snippets.

@katowulf
katowulf / jquery.tabslideout.1.3.js
Created May 10, 2012 20:50
jquery.tabslideout.1.3.js
/*
tabSlideOUt v1.3 (altered by katowulf)
Originally by William Paoli: http://wpaoli.building58.com
To use you must have an image ready to go as your tab
Make sure to pass in at minimum the path to the image and its dimensions:
example:
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));
}
@katowulf
katowulf / index.html
Created January 6, 2013 21:51
A CodePen by katowulf. Interactive image nodes - Interactive nodes built from image data. Play with your mouse :)
<canvas id='canvas'></canvas>
function _updateModel(model, options) {
var firebase = this.firebase;
var changes = model.changedAttributes();
if( changes ) {
setTimeout(function() { // make sure change events fire before Firebase notifies on() listener
firebase.child(model.id).update(changes);
}, 0);
}
}
@katowulf
katowulf / gist:4741111
Last active April 11, 2024 12:07
Firebase security rules for a simple chat room model
{
"chat": {
// the list of chats may not be listed (no .read permissions here)
// a chat conversation
"$key": {
// if the chat hasn't been created yet, we allow read so there is a way
// to check this and create it; if it already exists, then authenticated
// user (specified by auth.id) must be in $key/users
@katowulf
katowulf / firebase_promise_wrapper.js
Last active January 6, 2024 04:19
Example of promise contracts for Firebase (using jQuery.Deferred)
/*
* Promise wrapper for Firebase
*
* Requires jQuery and underscore.js
*************************************/
(function ($) {
"use strict";
var undefined;
var FIREBASE_URL = 'https://YOURINSTANCE.firebaseio.com';
var authClient = new FirebaseAuthClient(db, function(error, user) {
if (error) {
alert(error);
} else if (user) {
$(body).removeClass("noAuth").addClass("auth");
@katowulf
katowulf / firebase_copy.js
Last active July 29, 2022 15:58
Move or copy a Firebase path to a new location
function copyFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.value(), function(error) {
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
@katowulf
katowulf / precise_ordered_records.js
Last active December 20, 2015 10:20
Using a simple update counter to maintain precise ordering of records in Firebase
var sequenceRef = new Firebase(...+'/entries');
var updateCounter = new Firebase(...+'/counter');
updateCounter.transaction(function(currentValue) {
return currentValue+1;
}, function(error, committed, snap) {
if( error ) { ... }
else if( committed ) {
var updateCounter = snap.val();
sequenceRef.push().setWithPriority({
@katowulf
katowulf / inc_id_rules.js
Last active June 24, 2018 17:08
Security rules for creating an incremental, numeric ID in Firebase. See http://jsfiddle.net/firebase/xLq7grcc/
{
"rules": {
".read": true,
".write": false,
"incid": {
"counter": {
// this counter is set using a transaction and can only be incremented by 1
// the total number of records must be less than 10,000 simply for demo purposes
".write": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || newData.val() === data.val()+1) && newData.val() <= 10000"
},