Skip to content

Instantly share code, notes, and snippets.

@katowulf
katowulf / 0_reuse_code.js
Created May 19, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 Aug 27, 2014
Extend AngularFire's $FirebaseObject, adding a forEach method onto the prototype, which ignores the "ignore" key. This works with angular.forEach and ng-repeat.
View foreach_factory.js
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 Sep 18, 2014
Explain the unknown provider <-- a error that occurs in dist files created with ngMin
View the_problem.js
// 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) {
});
});
View TypeTester.java
// 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 Dec 17, 2014
Override AngularFire's $save method to do an update, if a list of fields is provided.
View override_save.js
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 Aug 29, 2015
Watching child of child in Flashlight for Firebase.
View NestedPathMonitor.js
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 Oct 13, 2015
Reset method on a $FirebaseArray in AngularFire
View reset_method.js
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 Mar 21, 2015
Example of infinite scroll using ui-grid and Firebase (uses http://firebase.github.io/firebase-util/)
View app.js
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'},
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>
You can’t perform that action at this time.