Skip to content

Instantly share code, notes, and snippets.

@katowulf
katowulf / jquery.tabslideout.1.3.js
Created May 10, 2012
jquery.tabslideout.1.3.js
View 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:
View firebase_queue_pop.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));
}
@katowulf
katowulf / index.html
Created Jan 6, 2013
A CodePen by katowulf. Interactive image nodes - Interactive nodes built from image data. Play with your mouse :)
View index.html
<canvas id='canvas'></canvas>
View _updateMethod-enhancement.js
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 Oct 28, 2020
Firebase security rules for a simple chat room model
View gist:4741111
{
"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 Sep 9, 2018
Example of promise contracts for Firebase (using jQuery.Deferred)
View firebase_promise_wrapper.js
/*
* Promise wrapper for Firebase
*
* Requires jQuery and underscore.js
*************************************/
(function ($) {
"use strict";
var undefined;
var FIREBASE_URL = 'https://YOURINSTANCE.firebaseio.com';
View moneys.me
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 Apr 20, 2020
Move or copy a Firebase path to a new location
View firebase_copy.js
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 Dec 20, 2015
Using a simple update counter to maintain precise ordering of records in Firebase
View precise_ordered_records.js
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 Jun 24, 2018
Security rules for creating an incremental, numeric ID in Firebase. See http://jsfiddle.net/firebase/xLq7grcc/
View inc_id_rules.js
{
"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"
},
You can’t perform that action at this time.