Skip to content

Instantly share code, notes, and snippets.

View jmk2142's full-sized avatar

Jin Kuwata jmk2142

  • Teachers College, Columbia University
View GitHub Profile
@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 / 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 / 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": {