Skip to content

Instantly share code, notes, and snippets.

test = ['example']
#!/usr/bin/ruby
def t2m(target)
command = "./t2m.pl -d #{target}.td >> export.file"
p command
system command
end
"2007".upto("2009") do |y|
"01".upto("12") do |m|
require File.dirname(__FILE__) + '/../spec_helper'
class Foo
def self.hello
"hello"
end
end
class FooBar < Foo
def self.konnichiwa
namespace :security do
# ====
# Usage:
# rake security:add_attr_accessible => edit all models which are not called either attr_accessible or attr_protected.
# rake security:att_attr_accessible models="blog,article" => update only blog and article. it doesn't check whether there are attr_accessible or attr_protected.
desc "defines attr_accessible listing all attributes but associations into model(s)"
task :add_attr_accessible => :environment do
models = ENV["models"]
if models.to_s.size==0
models = risky_models
a = lambda {|src| src.map { |v| v.is_a?(Fixnum) ? v + 1 : v.is_a?(Array) ? a.call(v) : v } }
a.call [1, 2, 3, ["a", 1, 2, 3, ["a", 1, 2, 3], "a"]]
@ono
ono / resque_without_queue.rb
Created February 12, 2010 12:30
Allow you to develop codebase using Resque without running worker and setting up redis
# Some developers (or designers) in your project might not need resque running in local nor want to hasstle to set up redis.
# For helping such lazy people, I give you a option.
# Put and customize this code from Rails initializers, Sinatra configuration block, or wherever.
require 'resque'
if ENV["RAILS_ENV"]=="development" # <= Change this condition as you like
module Resque
# Performs job immediately without queueing.
def perform_immediately(queue, item)
item = decode(encode(item))
# BaseJob is a super class of Resque jobs which you want to track with RPM
class BaseJob
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
# This is called from Resque.
# To be wrapped with the common operation, please describe job in the instance's perform method.
def self.perform(*args)
NewRelic::Control.instance['forked_job'] = true
self.new.perform_wrapper(*args)
ensure
@ono
ono / rspec.bundler.rake
Created June 10, 2010 20:46
get lib directory from bundler. (you can add this logic into rspec.rake)
# Bundler support
rspec_gem_dir = Bundler::SPECS.select{|s| s.name == 'rspec'}[0].require_paths[0]
require 'rmagick'
dir = File.dirname(__FILE__)
Dir.glob "#{dir}/**/*.jpg" do |filename|
image = Magick::Image.read(filename)[0]
# note: there is another useful method which you can use to resize and crop square
# image.resize_to_fill(200)
# You have to define Gemspec files for Rails 2.3 libraries. A commit bellow will help it:
# http://github.com/jpzwarte/rails/commit/55ede36d8907f481b18fcefa21d099f69ae9965b
# Load rails from github
git 'git://github.com/reallyenglish/rails.git', :branch => '2-3-re', :ref => '1760b049f43ba2ab32eb47fdc42f5638115aeb8a' do
%w(active_support active_record action_pack action_mailer active_resource).each { |lib| gem lib.sub(/_/,''), '2.3.8', :require=>lib}
gem 'rails', '2.3.8'
end
# Load rails from your local