Skip to content

Instantly share code, notes, and snippets.

# Author: Maksim Horbul
#
# This patch allows to use :expires_in option with the FileStore Cache
#
# Example:
# <% cache :expires_in => 10.minutes %>
# <div>Cool fragment which is going to be expired in 10 minutes.</div>
# <% end %>
#
require 'rubygems'
require 'net/http'
require 'uri'
require 'hpricot'
require 'optparse'
require 'set'
def timed(&block)
s = Time.now
yield
require 'time'
def deg2rad(d)
(d/180.0)*Math::PI
end
def rad2deg(r)
(r/Math::PI)*180
end
@mhorbul
mhorbul / mem_cache_store.rb
Created March 4, 2010 00:52
ActiveSupport::Cache::MemCacheStore extension
#
# MemCacheStore extension which allows to find and delete the objects from cache by keys matched regexp.
#
# Idea was taken from http://github.com/martincik/memcache_store_with_delete_matched/
module ActiveSupport
module Cache
class MemCacheStore < Store
cattr_accessor :keys_key_name
namespace :benchmark do
namespace :find do
desc "Benchmarking find by id"
task :simple => :environment do
Benchmark.bm(20) do |bm|
bm.report 'find-by-id' do
5_000.times do
Person.find(100)
end
# .gitignore file for XCode projects
build/*
*.pbxuser
*.perspectivev3
Database/*.sqlite3.db
# Mac OS X Finder and whatnot
.DS_Store
# XCode (and ancestors) per-user config (very noisy, and not relevant)
# Rails
# Different interfaces for the similar methods
# Why ?
ruby-1.8.7-p299 > now = Time.now
=> Thu Aug 26 14:16:31 -0700 2010
ruby-1.8.7-p299 > now.ago(10)
=> Thu Aug 26 14:16:21 -0700 2010
ruby-1.8.7-p299 > now.advance(:seconds => 10)
=> Thu Aug 26 14:16:41 -0700 2010
# Maksim Horbul
# AWS Import API test
#
# Error response all the time
#
# <ErrorResponse xmlns="http://importexport.amazonaws.com/doc/2010-06-01/">
# <Error>
# <Type>Sender</Type>
# <Code>SignatureDoesNotMatch</Code>
# <Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
@mhorbul
mhorbul / gist:671507
Created November 10, 2010 20:59
resque-schedule yaml config template generator
require 'yaml'; Dir.glob("app/jobs/*").map {|j| File.basename(j, ".rb")}.reduce({}) { |r,k| r[k] = {"cron" => "* * * * *", "custom_job_class" => k.gsub(/(_(.)|^(.))/) {|m| m.gsub(/_/,"").upcase}, "queue" => "resque", "description" => k.gsub(/(_(.)|^(.))/) {|m| "#{m.gsub(/_/," ").upcase}"} }; r }.to_yaml
__END__
---
awesome_worker_one:
cron: "* * * * *"
custom_job_class: AwesomeWorkerOne
queue: resque
description: Awesome Worker One
ruby-1.9.1-p378 > class A
ruby-1.9.1-p378 ?> def foo
ruby-1.9.1-p378 ?> yield
ruby-1.9.1-p378 ?> end
ruby-1.9.1-p378 ?> def zoo
ruby-1.9.1-p378 ?> puts "zoo"
ruby-1.9.1-p378 ?> end
ruby-1.9.1-p378 ?> end
=> nil
ruby-1.9.1-p378 > a = A.new