Skip to content

Instantly share code, notes, and snippets.

@meetbryce
meetbryce / Stop Permssion Errors on Firebase & AngularFire Logout - README.md
Last active February 22, 2019 03:08
Prevent permission denied errors from Firebase on logout (caused by active $firebaseArray & $firebaseObject connections not being destroyed). Example code follows John Papa's style guide.
@thgreasi
thgreasi / firebaseCheckpointArray.js
Last active September 20, 2017 17:28
firebase.checkpointArray
/*
Implemented by katowulf at:
https://jsfiddle.net/katowulf/1dfyz2rq/
Discussed in:
https://github.com/firebase/angularfire/issues/687
https://github.com/angular-ui/ui-sortable/issues/421
*/
angular.module('firebase.checkpointArray', ['firebase'])
.factory('firebaseCheckpointArray', function($firebaseArray) {
@katowulf
katowulf / rules.js
Created March 3, 2016 00:05
Search for users by email address in Firebase, without exposing everyone's email address to the world in a bulk-readable format.
{
"rules": {
"users": {
"$user_id": {
// email address is required
".validate": "newData.hasChildren(['email'])",
}
},
"emails_to_users": {
@katowulf
katowulf / example_rules.js
Created February 10, 2016 00:25
A list of example patterns for security rules validations
{
"rules": {
// REQUIRED FIELDS
"example1" : {
"$record": {
// foo and bar are required fields that must always exist
// this will reject writes to $record, as well as directly to $record/foo or $record/bar if they are null
".validate": "newData.hasChildren(['foo', 'bar'])"
}
@katowulf
katowulf / global.js
Last active May 30, 2016 21:27
Overriding error handling in AngularFire by extending and decorating $$error
// this will remove all error logging globally
angular.config(function($provide) {
$provide.decorator("$firebaseObject", function($delegate) {
$delegate.prototype.$$error = function(err) {
this.$destroy(err);
};
return $delegate;
});
$provide.decorator("$firebaseArray", function($delegate) {
@katowulf
katowulf / normalize_record.js
Last active January 5, 2018 00:08
Normalize a "post" record by adding "user" data from another Firebase path in AngularFire
app.factory('NormalizedPosts', function($firebaseArray, userCache) {
var PostsWithUsers = $firebaseArray.$extend({
// override $$added to include users
$$added: function(snap) {
// call the super method
var record = $firebaseArray.prototype.$$added.call(this, snap);
userCache.$load( record.user ).$loaded(function( userData ) {
record.userData = userData;
});
angular.module('qAllSettled', []).config(function($provide) {
$provide.decorator('$q', function($delegate) {
var $q = $delegate;
$q.allSettled = function(promises) {
return $q.all(promises.map(function(promise) {
return promise.then(function(value) {
return { state: 'fulfilled', value: value };
}, function(reason) {
return { state: 'rejected', reason: reason };
});
@iamkirkbater
iamkirkbater / autoSizr.js
Created August 6, 2014 13:45
Simple jQuery Plugin that auto resizes text to fill a specific sized div (great for responsive slideshows that utilize large banner text with variable lengths), derived from https://gist.github.com/iam4x/5015270
$.fn.autoSizr = function () {
var el, elements, _i, _len, _results;
elements = $(this);
if (elements.length < 0) {
return;
}
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push((function(el) {
@6174
6174 / Random-string
Created July 23, 2013 13:36
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@mjackson
mjackson / color-conversion-algorithms.js
Last active April 14, 2024 08:46
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation