Magick::ImageMagickError (Postscript delegate failed `/tmp/magick-Zb2G2URF': No such file or directory @ error/ps.c/ReadPSImage/833: `(null)')
# IP/Path関連 puts request.ip puts request.remote_ip # http://192.168.1.1/my/project/1 # にアクセスした場合 puts request.url # => http://192.168.1.1/my/project/1 puts request.fullpath # => /my/project/1 # HTTP METHOD関連 puts request.request_method puts request.get? puts request.post? puts request.put? puts request.delete?
# 安定板を入れるならrvm get stable rvm get latest # 呼ばなくても大丈夫そうですが rvm reload # Ruby 2.0.0のインストール rvm install 2.0.0 # 2.0.0に切り替えて、バージョン確認 rvm 2.0.0 ruby -v => ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
class MyClass def hello puts "Hello World!" end end MyClass.new.instance_eval do hello end
require 'RMagick' require 'tempfile' # アップロードされたファイル uploaded_file = params[:file] # TempfileからImageを作成する # from_blobはArrayを返すので、shiftして先頭の要素を取得 image = Magick::Image.from_blob(File.read(uploaded_file.path)).shift # 画像フォーマットの確認 puts image.format # なんかいろんな処理 # Tempfileの作成 tempfile = Tempfile.open(temp_filename) # Tempfileへの書き込み # フォーマットの指定が便利 image.write("png:" + tempfile.path) # なんかいろんな処理 # Tempfileの削除 tempfile.close!
module FinalClass class << self def included(base) base.extend ClassMethods end end module ClassMethods def method_added(name) remove_method name raise TypeError, "You cannot define a new method!" end def inherited(subklass) raise TypeError, "You cannot define a subclass!" end end end class A include FinalClass end
gem install amazon-ecs
require 'amazon/ecs' Amazon::Ecs.options = { :associate_tag => '[your associate tag]', :AWS_access_key_id => '[your developer token]', :AWS_secret_key => '[your secret access key]' } # API呼び出し res = Amazon::Ecs.item_lookup("4088767624", :response_group => 'Small, ItemAttributes, Images', :country => 'jp') # 返ってきたXMLを表示(res.doc.to_sでも多分OK) puts res.marshal_dump
amazon_tag = '[your associate tag]' res.items.each do |item| element = item.get_element('ItemAttributes') data = { :asin => item.get('ASIN'), :title => element.get("Title"), :page_url => "http://www.amazon.co.jp/dp/#{item.get('ASIN')}?tag=#{amazon_tag}", :isbn => element.get("ISBN"), :author => element.get_array("Author").join(", "), :product_group => element.get("ProductGroup"), :manufacturer => element.get("Manufacturer"), :publication_date => element.get("PublicationDate"), # URL, Width, Heightの要素を持っている :small_image => item.get_hash("SmallImage"), :medium_image => item.get_hash("MediumImage"), :large_image => item.get_hash("LargeImage") } end # dataを表示する(省略)
bundle gem hello-akasata
# -*- encoding: utf-8 -*- require File.expand_path('../lib/hello-akasata/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["akasata"] gem.email = ["*@*.*"] gem.description = %q{Test Gem.} gem.summary = %q{Hello World!} gem.homepage = "" gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "hello-akasata" gem.require_paths = ["lib"] gem.version = Hello::Akasata::VERSION # 依存するgemがある場合 # gem.add_dependency('log4r', '>= 1.0.5') gem.add_development_dependency('rspec') end
module Hello module Akasata VERSION = "0.0.1" end end
require "hello-akasata/version" module Hello module Akasata def self.hello "Hello akasata World!" end end end
rake build # ビルドします rake install # ビルドしてシステムにインストールします rake release # これでRubyGems.orgに公開されます。今回はやってませんw
require 'rubygems' require 'bundler/setup' require 'hello-akasata' RSpec.configure do |config| config.mock_framework = :rspec end
require 'spec_helper' describe Hello::Akasata, "::hello" do it "should return 'Hello akasata World!'" do Hello::Akasata.hello.should eq("Hello akasata World!") end end
rspec
gem install aws-sdk
# encoding: utf-8 require 'rubygems' require 'aws-sdk' require 'nkf' ses = AWS::SimpleEmailService.new( :access_key_id => 'YOUR_ACCESS_KEY_ID', :secret_access_key => 'YOUR_SECRET_ACCESS_KEY') body_text = NKF.nkf '-jw', <<-EOS こんにちは。 このメールはテストメールです。 おしまい EOS subject = NKF.nkf('-Mw', 'サブジェクトです') from_email = "FROM_EMAIL_ADDRESS" to_email = "TO_EMAIL_ADDRESS" p "Verified?(FROM Email): " + ses.identities[from_email].verified?.to_s p "Verified?(TO Email): " + ses.identities[to_email].verified?.to_s p "Verified?(Domain): " + ses.identities['YOUR_DOMAIN'].verified?.to_s ses.send_email( :subject => subject, :to => to_email, :from => from_email, :body_text => body_text, :body_text_charset => 'ISO-2022-JP' )
gem install aws-sdk
require 'aws-sdk' AWS.config( :access_key_id => 'YOUR_ACCESS_KEY_ID', :secret_access_key => 'YOUR_SECRET_ACCESS_KEY') s3 = AWS::S3.new # 以下も可 # s3 = AWS::S3.new( # :access_key_id => 'YOUR_ACCESS_KEY_ID', # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
bucket = s3.buckets['yourbucketname'] filename = "fullpath/filename.ext" basename = File.basename(filename) o = bucket.objects[basename] o.write(:file => filename)
# キーの生成 my_key = OpenSSL::Cipher.new("AES-256-ECB").random_key # オブジェクトの取得 o = bucket.objects[name] # 暗号化して書込 o.write("MY TEXT", :encryption_key => my_key) # 復号化して読込 puts o.read(:encryption_key => my_key)
# キーの生成 my_key = OpenSSL::PKey::RSA.new(1024) # オブジェクトの取得 o = bucket.objects[name] # 暗号化して書込 o.write("MY TEXT", :encryption_key => my_key) # 復号化して読込 puts o.read(:encryption_key => my_key)
o = bucket.objects[name] # Canned ACL o.acl = :public_read # writeメソッドに渡すことも可能 o.write(:file => filename, :acl => :public_read)
o.acl.change do |acl| acl.grant(:full_control).to(:canonical_user_id => "...") end