Skip to content

Instantly share code, notes, and snippets.

@katowulf
katowulf / 0_reuse_code.js
Created May 19, 2014 19:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@katowulf
katowulf / foreach_factory.js
Created August 27, 2014 16:33
Extend AngularFire's $FirebaseObject, adding a forEach method onto the prototype, which ignores the "ignore" key. This works with angular.forEach and ng-repeat.
var Factory = $FirebaseObject.extendFactory({
forEach: function(callback, context) {
var self this;
$firebaseUtils.each(self, function(v, k) {
if( k !== "ignore" ) {
callback.call(context, v, k, self);
}
});
});
});
@katowulf
katowulf / the_problem.js
Created September 18, 2014 15:44
Explain the unknown provider <-- a error that occurs in dist files created with ngMin
// ngmin can handle this fine; if not using ngmin, then
// we'd do ['$provide', function($provide) { ... }]
app.config(function($provide) {
// however, ngmin does not know how to preserve the injected dependencies here!
$provide.decorator('SomeFactory', function($delegate, $timeout) {
});
});
// inspiration: http://stackoverflow.com/questions/3993982/how-to-check-type-of-variable-in-java/16717058#16717058
class TypeTester {
void printType(Byte x) {
System.out.println(x + " is a byte");
}
void printType(Boolean x) {
System.out.println(x + " is a boolean");
}
void printType(Integer x) {
@katowulf
katowulf / override_save.js
Created December 17, 2014 16:09
Override AngularFire's $save method to do an update, if a list of fields is provided.
var SmartSaveFactory = $FirebaseArray.$extendFactory({
$save: function(indexOrItem, listOfFields) {
if( !listOfFields ) {
// do a normal save if no list of fields is provided
return $FirebaseArray.prototype.$save.apply(this, arguments);
}
else {
// this is a bit risky since we're using an internal method that could change
// we could remove this coupling by always passing the item instead of allowing
@katowulf
katowulf / NestedPathMonitor.js
Last active August 29, 2015 14:18
Watching child of child in Flashlight for Firebase.
var DynamicPathMonitor = require('./DynamicPathMonitor');
// call this instead of new PathMonitor inside PathMonitor.process
function NestedPathMonitor(ref, factory) {
this.factory = factory;
this.paths = {};
ref.on('child_added', this._add, this);
ref.on('child_removed', this._remove, this);
}
@katowulf
katowulf / reset_method.js
Last active October 13, 2015 13:43
Reset method on a $FirebaseArray in AngularFire
var ResetFactory = $FirebaseArray.$extendFactory({
reset: function(itemOrIndex) {
var self = this;
var key = self.$keyAt(itemOrIndex);
self.$inst().$ref().once('value', function(snap) {
self.$$updated(snap);
});
}
@katowulf
katowulf / app.js
Created March 21, 2015 15:34
Example of infinite scroll using ui-grid and Firebase (uses http://firebase.github.io/firebase-util/)
var app = angular.module('app', ['firebase', 'ui.grid', 'ui.grid.infiniteScroll']);
app.controller('ctrl', function($scope, $firebaseArray) {
var baseRef = new Firebase('https://fbutil.firebaseio.com/paginate');
var scrollRef = new Firebase.util.Scroll(baseRef, 'number');
//$scope.data = $firebaseArray(scrollRef);
$scope.opts = {
columnDefs: [
{name: '$id', displayName: 'ID'},
@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);
}
}