This file contains 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
class User < ActiveRecord::Base | |
def subscribe_mailchimp_list(client = Gibbon.new) | |
if ENV["MAILCHIMP_LIST_ID"] | |
logger.info "add #{self.email} to list #{ENV["MAILCHIMP_LIST_ID"]}" | |
client.list_subscribe(id: ENV["MAILCHIMP_LIST_ID"], | |
email_address: self.email, | |
double_optin: false, | |
send_welcome: false, | |
update_existing: true, | |
merge_vers: {:FNAME => self.first_name, |
This file contains 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}'" |
This file contains 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 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 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 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 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 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 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 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) |
NewerOlder