Skip to content

Instantly share code, notes, and snippets.

$ heroku pg:cachehit --remote production
name | ratio
----------------+------------------------
index hit rate | 0.99929808820146663449
cache hit rate | 1.00
@r38y
r38y / dms.rb
Created October 31, 2012 17:02
module Dms
def self.last_checked_at
value = Setting.get('last_checked_at')
Time.parse(value) if value
end
def self.checked!
last_checked_at = Time.now.utc
Setting.set('last_checked_at', last_checked_at)
end
class Checking
def run
Rails.logger.info "Checking #{snitch.id} (#{snitch.name})..."
unless checkable?
Rails.logger.error "Snitch #{snitch.id} is not checkable"
return false
end
... more stuff
end
end
# passes (from different app)
it "should associate with a location with location_ids" do
location = create(:location)
vendor = create(:vendor, location_ids: [location.id])
vendor.reload
vendor.locations.should include(location)
end
# fails
@r38y
r38y / randy_store.rb
Created September 1, 2012 21:41
What I came up with for rack-attack
class RandyStore
def initialize(options={})
@data = if options.is_a?(Redis)
options
else
Redis.new options
end
end
attr_reader :data
@r38y
r38y / delete_resource_route.rb
Created July 29, 2012 21:23
Override resources to include a delete action
module DeleteResourceRoute
def resources(*args, &block)
super(*args) do
yield if block_given?
member do
get :delete
delete :delete, action: :destroy
end
end
end
1.9.3p194 :003 > 0.0 / 0.0
=> NaN
@r38y
r38y / resizeio_helper.rb
Created July 26, 2012 18:06
Ruby ResizeIO Client
module ResizeioHelper
def resizeio_image_tag(original, options={})
rio_options = extract_resizeio_options(options)
image_tag resizeio_url(original, rio_options), options
end
def extract_resizeio_options(options)
retina = !!options.delete(:retina)
multiplier = retina ? 2 : 1
class Dossi.Models.Photo extends Backbone.Model
paramRoot: 'photo'
preload: =>
tempImg = new Image()
tempImg.src = @largeUrl()
tempImg.src = @smallUrl()
largeUrl: ->
@resizeioURL({w: 64, h: 64, t: 'crop'})
@r38y
r38y / application_controller.rb
Created May 17, 2012 18:21 — forked from robotmay/application_controller.rb
Examples of low level caching
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter do
@categories = Rails.cache.fetch("global/categories", expires_in: 10.minutes) do
Category.where("posts_count > 0").all
end
end
end