This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Security pacth for Rails 2.3.9 | |
# put this file on ROOT/config/initializers | |
# http://weblog.rubyonrails.org/2010/10/15/security-vulnerability-in-nested-attributes-code-in-ruby-on-rails-2-3-9-and-3-0-0 | |
# http://weblog.rubyonrails.org/assets/2010/10/15/2-3-nested_attributes.patch | |
module ActiveRecord | |
module NestedAttributes #:nodoc: | |
def assign_nested_attributes_for_one_to_one_association(association_name, attributes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Group -has_many-> Participation | |
# Group.joined ==> defined named_scope | |
# Group.user_id_not_null ==> genarated named_scope by searchlogic | |
g = Group.find(1) | |
# SQL) SELECT * FROM `groups` WHERE (`groups`.`id` = 1) | |
g.participations | |
# SQL) SELECT * FROM `participations` WHERE (`participations`.group_id = 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/http" | |
require "uri" | |
http = Net::HTTP.new("www.youroom.local", "3000") | |
http.send_request('CONNECT', "/") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Need to install gems heroku, newrelic_rpm | |
$ gem install heroku newrelic_rpm | |
Set your apps setting | |
app_name : heroku's app_name of auto scaling | |
license_key : NewRelic api key. You can get heroku's NewRelic admin console. "App setting" and "Agent configuration" | |
execute with cron every minutes | |
$ ruby ./adjust_dynos_with_newrelic.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ajaxSend(function(e, xhr, options) { | |
var token = $("meta[name='csrf-token']").attr("content"); | |
xhr.setRequestHeader("X-CSRF-Token", token); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionController | |
module RequestForgeryProtection | |
protected | |
def verify_authenticity_token | |
verified_request? || handle_unverified_request | |
end | |
# Process logout | |
def handle_unverified_request | |
reset_session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require "rubygems" | |
require "fb_graph" | |
app_id = "" | |
csecret = "" | |
app = FbGraph::Application.new(app_id, :secret => csecret) | |
# ユーザ作って友達にするとか |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "capybara-webkit" | |
require "mini_magick" | |
class WebkitScreenshot | |
def initialize | |
@browser = Capybara::Driver::Webkit::Browser.new | |
end | |
def browser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_record" | |
require "sqlite3" | |
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}} | |
ActiveRecord::Base.establish_connection('test') | |
class CreateAllTables < ActiveRecord::Migration | |
def self.up | |
create_table :locales do |t| | |
t.string :name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'right_aws' | |
aws_access_key_id, aws_secret_access_key = "key_id", "access_key" | |
old_bucket_name = 'from-bucket' | |
new_bucket_name = "to-bucket" | |
s3 = RightAws::S3.new(aws_access_key_id, aws_secret_access_key) | |
bucket = s3.bucket(old_bucket_name) | |
puts "Copy S3 files from '#{old_bucket_name}' to '#{new_bucket_name}'" |