Skip to content

Instantly share code, notes, and snippets.

View takuyan's full-sized avatar
🎯
Focusing

Takuya Kato / katton takuyan

🎯
Focusing
View GitHub Profile
@takuyan
takuyan / gist:796595
Created January 26, 2011 11:48
gem install spork
$ gem install spork
Building native extensions. This could take a while...
ERROR: Error installing spork:
ERROR: Failed to build gem native extension.
c:/ruby187/bin/ruby.exe mkrf_conf.rb
Actually, there aren't any native extensions. I'm just dynamically installing de
pendencies based off of your operating system
installing windows dependencies
Failed to install necessary dependency gem win32-process: ERROR: Failed to build
@takuyan
takuyan / gist:940331
Created April 25, 2011 10:06
parent method ch
class MyClass
after_create :check_parent
def check_parent
self.parent.do_something
end
end
# spec
@takuyan
takuyan / aws.rb
Created July 14, 2011 09:52
If you are using S3 in Tokyo Region, add this file, to config/initializers.
#config/initializers/aws.rb
AWS::S3::DEFAULT_HOST.replace "s3-ap-northeast-1.amazonaws.com"
@takuyan
takuyan / figure.rb
Created July 15, 2011 01:18
paperclip sample
# app/models/figure.rb
class Figure < ActiveRecord::Base
has_attached_file :image,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :s3,
:s3_host_name => "s3-us-west-1.amazonaws.com",
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style/:filename"
end
@takuyan
takuyan / s3.yml
Created July 15, 2011 01:22
how to use paperclip :region option
# config/s3.yml
development:
bucket: sample-dev
access_key_id: xxxxxxxxxxxxxxxx
secret_access_key: yyyyyyyyyyyyyyyyy
region: tokyo
production:
bucket: sample-production
access_key_id: iiiiiiiiiiiiiiiii
secret_access_key: jjjjjjjjjjjjjjjjj
module Paperclip
module Storage
module S3
#
# ...
#
@s3_host_name = @options[:s3_host_name] || @s3_credentials[:s3_host_name]
#
# ...
#
@takuyan
takuyan / s3.yml
Created July 19, 2011 02:07
If you useing S3 except default, add this to config/s3.yml. For paperclip/S3.
# config/s3.yml
development:
bucket: sample-dev
access_key_id: xxxxxxxxxxxxxxxx
secret_access_key: yyyyyyyyyyyyyyyyy
s3_host_name: s3-ap-northeast-1.amazonaws.com
production:
bucket: sample-production
access_key_id: iiiiiiiiiiiiiiiii
secret_access_key: jjjjjjjjjjjjjjjjj
@takuyan
takuyan / kaminari_array_issue_sample.rb
Created November 18, 2011 02:17
kaminari Array issue
# app/models/medium.rb
has_many :stories
# app/models/stories.rb
belongs_to :medium
scope :newer, order("created_at desc")
scope :entries, where("entry = ?", true)
Life::Application.routes.draw do
scope ":locale", locale: /en|ja/ do
root to: "main#index"
resources :provider_users, only: [:destroy]
resources :contacts
resources :messages
resources :recipients, only: [:create, :destroy] do
collection do
get :search
end
a1 = Article.build
uid: 10
title: 'Awesome Article'
body: 'Lorem Ipsum...'
user_id: 8
a1.isNewRecord() # => true
a1.save()