Skip to content

Instantly share code, notes, and snippets.

@chischaschos
chischaschos / resque_tools.rb
Created April 7, 2011 15:21
Removes loner idle keys
module Resque
module Tools
extend self
def remove_idle_keys
affected = 0
if ::Resque.info[:pending] == 0
keys = ::Resque.redis.keys.grep(/loners/)
affected = keys.reduce(affected) do |r,key|·
@chischaschos
chischaschos / stub_instances.rb
Created March 3, 2011 21:16
RSpec stubbing all instances from a User
new_method = User.method(:new)
User.stub(:new).and_return do |*args|
instance = new_method.call *args
instance.stub(:project_changes).with(@project.to_param).and_return(@changes_array)
instance
end
@chischaschos
chischaschos / .gitignore
Created January 24, 2011 20:09
Mongo mapper examples
*.log
@chischaschos
chischaschos / .gitignore
Created January 2, 2011 02:23
A callbacks DSL creation example with ruby metaprogramming
*.swp
@chischaschos
chischaschos / Gemfile
Created December 13, 2010 17:12
Redis examples
source :gemcutter
@chischaschos
chischaschos / saludador.rb
Created December 10, 2010 01:59
rubyc rspec intro
class Saludador
def initialize(*user)
@user = user[0]
raise "An user has to be provided" unless @user
end
def saluda
"Hola amigo"
end
We couldn’t find that file to show.
@chischaschos
chischaschos / analyzer.rb
Created December 3, 2010 03:15
rubyc example data
headers = nil
rows = []
File.open(ARGV[0] || 'data.csv', 'r') do |file|
headers = file.gets.split(',')
while(line = file.gets) do
cols = line.split(',')
rows << cols
end
@chischaschos
chischaschos / .gitignore
Created November 26, 2010 19:13
A Playfair Cypher ruby example from the ruby core rubylearning.org course
*.swp
@chischaschos
chischaschos / class1.rb
Created November 16, 2010 19:16
Metaprogramming basics post code
class A
end
puts "--" + A.instance_methods(false).join(', ')
class A
def otro
end
end