Skip to content

Instantly share code, notes, and snippets.

@anantn
anantn / firebase_first_item.js
Last active March 4, 2016 00:04
Firebase: Get the first item in a list. This snippet retrieves only the first item in a list.
function makeList(ref) {
var fruits = ["banana", "apple", "grape", "orange"];
for (var i = 0; i < fruits.length; i++) {
ref.push(fruits[i]);
}
}
function getFirstFromList(ref, cb) {
ref.startAt().limit(1).once("child_added", function(snapshot) {
cb(snapshot.val());
@THEtheChad
THEtheChad / Defer.js
Created May 3, 2012 16:24
Defers execution of the callback until exec is run. At that point, all future calls are executed immediately.
function Defer(callback){
if(!this instanceof Defer)
return new Defer(callback);
var queue = []
, callback = callback
, slice = Array.prototype.slice
, changeling = function(){
queue.push({
'context': this,
@apneadiving
apneadiving / users_controller.rb
Created January 20, 2012 00:25
gmaps4rails: Don't show map by default and load markers with ajax
class UsersController < ApplicationController
respond_to :html, :json
def index
@json = User.all.to_gmaps4rails
respond_with @json
end
end
require "time"
require "date"
class Date
def to_time
Time.local(year, month, day)
end
end
class Time