Skip to content

Instantly share code, notes, and snippets.

View davideast's full-sized avatar
💜
Working on Project IDX (and Firebase too)

David East davideast

💜
Working on Project IDX (and Firebase too)
View GitHub Profile
@katowulf
katowulf / extend.js
Created September 17, 2013 18:06
A simple extend function for JavaScript
function extend(base) {
var parts = Array.prototype.slice.call(arguments, 1);
parts.forEach(function (p) {
if (p && typeof (p) === 'object') {
for (var k in p) {
if (p.hasOwnProperty(k)) {
base[k] = p[k];
}
}
}
@katowulf
katowulf / 1_query_timestamp.js
Last active September 21, 2023 20:28
Get only new items from Firebase
// assumes you add a timestamp field to each record (see Firebase.ServerValue.TIMESTAMP)
// pros: fast and done server-side (less bandwidth, faster response), simple
// cons: a few bytes on each record for the timestamp
var ref = new Firebase(...);
ref.orderByChild('timestamp').startAt(Date.now()).on('child_added', function(snapshot) {
console.log('new record', snap.key());
});
@anantn
anantn / firebase_snapshot_parent.js
Last active April 14, 2021 15:29
Firebase: Get the parent of a snapshot.
function getParent(snapshot) {
// You can get the reference (A Firebase object) from a snapshot
// using .ref().
var ref = snapshot.ref();
// Now simply find the parent and return the name.
return ref.parent().name();
}
var testRef = new Firebase("https://example.firebaseIO-demo.com/foo/bar");
testRef.once("value", function(snapshot) {
@anantn
anantn / firebase_detect_data.js
Created December 18, 2012 00:54
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
@rondevera
rondevera / css-to-select-range-of-children.html
Last active February 8, 2023 11:29
CSS selector for a range of children
<!DOCTYPE html>
<html>
<head>
<style>
/* How to select a range of children
* (Here, 3rd-7th children, inclusive):
*/
ul li:nth-child(n+3):nth-child(-n+7) {
outline: 1px solid #0f0;
}