Skip to content

Instantly share code, notes, and snippets.

// Tip: You can go to any result in preview by pressiong ctrl+alt+[result number]
CmdUtils.makeSearchCommand({
name: ["rails","rails-search"],
homepage: "http://rafagarcia.net/",
author: { name: "Rafa Garcia", email: "rgo@aspgems.com"},
license: "GPL",
url: "http://apidock.com/rails/search/?query={QUERY}",
description: _("Searches Ruby on Rails terms in Apidock.com"),
icon: "http://apidock.com/images/rails_icon_16.png",
parser: {
ab -n 100 -c 4 http://localhost:3000/searches/concept_search
# ESTADO ACTUAL
Server Software: Mongrel
Server Hostname: localhost
Server Port: 3000
Document Path: /searches/concept_search
Document Length: 80751 bytes
class ActionDuck
attr_accessor :errors
def initialize(h)
h ||= {}
h.each { |k,v| send("#{k}=", v) }
self.errors = ActiveRecord::Errors.new(self)
end
module ShouldaContextExtensions
def self.included(base)
base.class_eval do
alias_method_chain :build, :fast_context
alias_method_chain :am_subcontext?, :fast_context
end
end
def fast_context(name, &blk)
@fast_subcontexts ||= []
@pacoguzman
pacoguzman / gist:217606
Created October 24, 2009 16:07 — forked from dhh/gist:45076
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName example.com
# ServerAlias *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class User < ActiveRecord::Base
before_create :create_profile
has_one :profile, :dependent => :destroy
protected
def create_profile
self.profile ||= Profile.new
end
end
@pacoguzman
pacoguzman / gist:254993
Created December 12, 2009 18:20
Without using preload associations
# Dado una variable Profile profile con datos de ejemplo
profile.graffities.all(:include => [{:user => :profile}, {:replys => {:user => :profile}}])
Comment Load (0.2ms) SELECT * FROM `comments` WHERE (`comments`.commentable_id = 3 AND `comments`.commentable_type = 'Profile' AND (parent_id IS NULL)) LIMIT 1
Comment Load (0.1ms) SELECT * FROM `comments` WHERE (`comments`.parent_id = 2) ORDER BY created_at DESC
User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 1)
Profile Load (0.2ms) SELECT `profiles`.* FROM `profiles` WHERE (`profiles`.user_id = 1)
Comment Load (0.2ms) SELECT `comments`.* FROM `comments` WHERE (`comments`.parent_id = 4) ORDER BY created_at ASC
User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` IN (1,3))
Profile Load (0.2ms) SELECT `profiles`.* FROM `profiles` WHERE (`profiles`.user_id IN (1,3))
+----+----------------+------------------+-------+---------------------+---------+---------+-----------+-----+-----+-------------------------+-------
@pacoguzman
pacoguzman / gist:255002
Created December 12, 2009 18:33
Using preload associations
class Comment < ActiveRecord::Base
def self.preload_graffities_associations(graffities)
# We want to load the following data
# associations = [{:user => :profile}, {:replys => {:user => :profile}}]
# We join graffities and replys to load its users and profile to avoid two querys
graffities_and_replys = (graffities + graffities.map(&:replys)).flatten
Comment.send(:preload_associations, graffities_and_replys, {:user => :profile})
end
end
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})