Skip to content

Instantly share code, notes, and snippets.

View schoefmann's full-sized avatar

Maximilian Schoefmann schoefmann

View GitHub Profile

Keybase proof

I hereby claim:

  • I am schoefmann on github.
  • I am schoefmann (https://keybase.io/schoefmann) on keybase.
  • I have a public key ASCmn4wXvVYvrt8cxJ8L3HtFPvNz1iA4RLRrsHH2q8Jwvwo

To claim this, I am signing this object:

@schoefmann
schoefmann / upload_changed.rb
Created November 30, 2011 16:16
upload changed files to staging
#!/usr/bin/env ruby
lines = `git st`
files = []
lines.each do |line|
if line =~ /#\s+modified:\s+(.*)\s*$/
files << $1 if File.file?($1)
end
end
#!/usr/local/ruby-enterprise/bin/ruby
# This should be run every 2 minutes from cron
# Checks the passenger processes for ones which take too much
# memory and kills those
LOCK_FILE = '/tmp/.passenger_watcher.lock'
REE_HOME = '/usr/local/ruby-enterprise/bin'
# [memory, sequence] - higher limit come first! (we check actual > limit ?)
SHUTDOWN = [
[380, [['USR1', 2], ['TERM', 2], ['KILL', 1]]], # = 5 seconds
# show maintenance page when present
error_page 503 /system/maintenance.html;
location /system/maintenance.html { }
location / {
if (-f $document_root/system/maintenance.html ) { return 503; }
}
module FindOrdered
# Finds the records with the given +ids+ and returns
# them in the order specified in the +ids+-array.
# MySQL will by default return them in their natural order
# (which is the order of their primary keys)
#
# raises ActiveRecord::RecordNotFound if not all records exist.
def find_ordered(*args)
args << {} unless args.last.kind_of?(Hash)
# A immutable, write-once hash.
# will raise an error if one tries to read an unset value or if one
# tries to override an existing value.
#
# Example:
# CONFIG = ConfigHash.new :foo => "bar"
class ConfigHash < Hash
class InvalidKey < StandardError; end
def initialize(hash, message = nil)
module ActsAsSolr::ClassMethods
def paginate_by_solr(query, opts)
page = opts.delete(:page)
per_page = opts.delete(:per_page)
WillPaginate::Collection.create(page, per_page) do |pager|
results = find_by_solr(query, opts.merge(:offset => pager.offset, :limit => pager.per_page))
pager.total_entries = results.total
pager.replace(results.docs)
pager.instance_variable_set('@facets', results.facets)
def pager.facets; @facets end