Skip to content

Instantly share code, notes, and snippets.

View ubiquity.tmp-4.js
// 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: {
View gist:176919
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
View action_duck.rb
class ActionDuck
attr_accessor :errors
def initialize(h)
h ||= {}
h.each { |k,v| send("#{k}=", v) }
self.errors = ActiveRecord::Errors.new(self)
end
View fast_context.rb
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 ||= []
View gist:217606
# 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
View gist:254989
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 Dec 12, 2009
Without using preload associations
View gist:254993
# 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 Dec 12, 2009
Using preload associations
View gist:255002
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
View gist:263076
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
View gist:265895
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})