Skip to content

Instantly share code, notes, and snippets.

View trevorh's full-sized avatar

Trevor Hart trevorh

View GitHub Profile
@eric
eric / require_tracking.rb
Created December 28, 2009 02:18
A simple tool to gather memory usage when files are required. More info at: http://bitmonkey.net/post/308322913
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
# WHAT: Provides a simple overview of memory allocation occuring during a
# require.
#
# For a longer explanation, see my post at:
#
# http://bitmonkey.net/post/308322913/tracking-initial-memory-usage-by-file-in-ruby
#
require 'sunspot'
require 'sunspot/session_proxy/abstract_session_proxy'
require 'resque'
require 'resque-retry'
class SunspotResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
attr_reader :session
delegate :config, :delete_dirty?, :dirty?,
:new_search, :search,
require 'sunspot'
require 'sunspot/session_proxy/abstract_session_proxy'
require 'resque'
require 'resque-retry'
class SunspotResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
attr_reader :session
delegate :config, :delete_dirty?, :dirty?,
:new_search, :search,
class BackgroundSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
class <<self
def async?
!!Thread.current[:background_session_proxy_async]
end
def with_async
self.async = true
begin
yield
@nz
nz / gist:1132809
Created August 8, 2011 21:30
Sunspot - Retry search on partialResults
# Sample code using Sunspot 1.2.1 to retry a search when partialResults=true
#
# I hope this code will be somewhat deprecated in Sunspot 1.2.2, since we have to
# use instance_eval to access the otherwise inaccessible @solr_response instance variable.
#
class Post
# ...
@nz
nz / sunspot_resque.rb
Last active July 10, 2023 21:35
Sunspot with Resque
# app/models/post.rb
class Post
searchable :auto_index => false, :auto_remove => false do
text :title
text :body
end
after_commit :resque_solr_update, :if => :persisted?
module Sunspot
class ResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
attr_reader :original_session
delegate :config, :delete_dirty?, :dirty?,
:new_search, :search,
:new_more_like_this, :more_like_this,
:remove, :remove!,
module Sunspot
class ResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
attr_reader :original_session
delegate :config, :delete_dirty?, :dirty?,
:new_search, :search,
:new_more_like_this, :more_like_this,
:remove, :remove!,
@thenbrent
thenbrent / switch-subscription-link.php
Created November 13, 2013 19:27
Output a link to switch a subscription for the current user.
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote