<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ゆーすけぶろぐ &#187; ruby</title>
	<atom:link href="http://yusukezzz.net/blog/archives/tag/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://yusukezzz.net/blog</link>
	<description>yusukezzz&#039;s weblog... ぷろぐらむとか ruby, android, java, thinkpad, milestone2</description>
	<lastBuildDate>Wed, 28 Dec 2011 13:21:54 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>bot source</title>
		<link>http://yusukezzz.net/blog/archives/1757</link>
		<comments>http://yusukezzz.net/blog/archives/1757#comments</comments>
		<pubDate>Thu, 15 Apr 2010 10:32:03 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1757</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<pre class="brush: ruby; title: ; notranslate">
#!/usr/bin/env ruby
require 'rubygems'
require 'rss'
require 'logger'
require 'twitter'

log = Logger.new('feed.log')
log.level = Logger::DEBUG

def shorten(long_url)
  id = 'YOUR_BITLY_ID'
  api_key = 'BITLY_API_KEY'
  version = '2.0.1'

  query = &quot;version=#{version}&amp;longUrl=#{long_url}&amp;login=#{id}&amp;apiKey=#{api_key}&quot;
  result = JSON.parse(Net::HTTP.get(&quot;api.bit.ly&quot;, &quot;/shorten?#{query}&quot;))
  result['results'].each_pair {|long_url, value|
    return value['shortUrl']
  }
end

feeds = []
feeds &lt;&lt; {
  'author' =&gt; 'yusukezzz',
  'url' =&gt; 'http://yusukezzz.net/blog/feed'}

$KCODE = 'u'
latest = 0
httpauth = Twitter::HTTPAuth.new('twitter_account', 'password')
client = Twitter::Base.new(httpauth)
begin
  File.open('latest.dat'){ |f| latest = f.gets }
rescue =&gt; e
  log.debug(e.message)
end
feeds.each do |feed|
  rss = RSS::Parser.parse(feed['url'])
  rss.channel.items.reverse.each do |i|
    if latest.to_i &lt; i.pubDate.to_i
      post = &quot;#{feed['author']} &gt; #{i.title} #{shorten(i.link)}&quot;
      begin
        client.update(post)
      rescue =&gt; e
        log.debug(e.message)
      end
      File.open('latest.dat', 'w') do |f|
        f.puts i.pubDate.to_i.to_s
        log.debug('update latest date')
      end
    end
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1757/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyで隠しファイルへのシンボリックリンクを作る</title>
		<link>http://yusukezzz.net/blog/archives/1742</link>
		<comments>http://yusukezzz.net/blog/archives/1742#comments</comments>
		<pubDate>Mon, 15 Feb 2010 08:06:47 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1742</guid>
		<description><![CDATA[実行したディレクトリ内の&#8221;.&#8221;で始まるファイル・ディレクトリのシンボリックリンクを ホームディレクトリ以下に作ります File.globの第2引数にFile::FNM_DOTMATCHで隠しファイ [...]]]></description>
			<content:encoded><![CDATA[<p>実行したディレクトリ内の&#8221;.&#8221;で始まるファイル・ディレクトリのシンボリックリンクを<br />
ホームディレクトリ以下に作ります</p>
<pre class="brush: ruby; title: ; notranslate">
Dir.glob('*', File::FNM_DOTMATCH){|f|
  if f =~ /^\.\w+/
    s = File.symlink(File.expand_path(f), File.expand_path(&quot;~/#{f}&quot;))
    puts &quot;#{f} OK&quot; if s == 0
  end
}
</pre>
<p>File.globの第2引数にFile::FNM_DOTMATCHで隠しファイルがマッチするようになります<br />
これでdropboxに置いてるLinux用設定ファイルを一括でインストール出来るようになりました</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1742/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyでmemcacheを使う</title>
		<link>http://yusukezzz.net/blog/archives/1733</link>
		<comments>http://yusukezzz.net/blog/archives/1733#comments</comments>
		<pubDate>Mon, 08 Feb 2010 05:17:15 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1733</guid>
		<description><![CDATA[ubuntu9.10 gemのmemcacheは入れない（入れてたらuninstall） 使い方]]></description>
			<content:encoded><![CDATA[<p>ubuntu9.10</p>
<pre class="brush: bash; title: ; notranslate">
sudo aptitude install memcached
sudo gem install memcache-client system_timer
</pre>
<p>gemのmemcacheは入れない（入れてたらuninstall）</p>
<p>使い方</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'memcache'

CACHE = MemCache.new 'localhost:11211', :namespace =&gt; 'hoge'
CACHE['cached'] = 'value'
p CACHE['cached']
</pre>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1733/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyでgmailの送受信をする</title>
		<link>http://yusukezzz.net/blog/archives/1691</link>
		<comments>http://yusukezzz.net/blog/archives/1691#comments</comments>
		<pubDate>Mon, 18 Jan 2010 10:32:28 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1691</guid>
		<description><![CDATA[gmailはssl必須なので面倒かと思ったのですが、意外と簡単でした まずは以下のライブラリを入れましょう ＃以下はruby1.8系の場合. ruby1.9系はsmtpがssl対応してるのでtlsmailは要りません t [...]]]></description>
			<content:encoded><![CDATA[<p>gmailはssl必須なので面倒かと思ったのですが、意外と簡単でした</p>
<p>まずは以下のライブラリを入れましょう<br />
＃以下はruby1.8系の場合. ruby1.9系はsmtpがssl対応してるのでtlsmailは要りません</p>
<pre class="brush: plain; title: ; notranslate">
sudo gem install tmail tlsmail
</pre>
<p>tmailはメールをparse、tlsmailはsmtpのssl化をしてくれます</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'tmail'
require 'tlsmail'
require 'net/smtp'
require 'net/pop'
require 'kconv'

mail = TMail::Mail.new
mail.to = 'recieve@some.domain'
mail.from = 'your@gmail.com'
mail.subject = '件名'.tojis
mail.date = Time.now
mail.mime_version = '1.0'
mail.set_content_type 'text', 'plain', {'charset =&gt; 'iso-2022-jp''}
mail.body = 'うんたらかんたら'.tojis
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
# port = 587はtlsの場合. ruby1.9系でenable_sslしている場合はport = 465になると思われます
Net::SMTP.start('smtp.gmail.com', 587, 'localhost.localdomain',
                 'your@gmail.com', 'your_gmail_password') do |smtp|
  smtp.sendmail(mail.encoded, mail.from, mail.to)
  puts 'send mail.'
end

Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
Net::POP3.start('pop.gmail.com', 995, 'your@gmail.com',
                'your_gmail_password') do |pop|
  unless pop.mails.empty?
    pop.mails.each do |m|
      mail = TMail::Mail.parse(m.pop)
      # toutf8はterminalなんかで表示する場合. windowsならtosjis
      puts &quot;#{mail.from}:[#{mail.subject}] #{mail.body.toutf8}&quot;
    end
  end
end
</pre>
<p>マルチバイト文字が入るところには忘れずにtojisしないと文字化けします</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1691/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyでFlickrに自動アップロード</title>
		<link>http://yusukezzz.net/blog/archives/1649</link>
		<comments>http://yusukezzz.net/blog/archives/1649#comments</comments>
		<pubDate>Fri, 04 Dec 2009 18:07:05 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/?p=1649</guid>
		<description><![CDATA[今までキャプチャにはgyamblr（矩形選択してtumblrにアップ）というソフトを使っていたのですが、 Vista64bitでは動きませんでした（単にtumblr側の仕様変更かもしれませんが） 最新版は2008年のもの [...]]]></description>
			<content:encoded><![CDATA[<p>今までキャプチャにはgyamblr（矩形選択してtumblrにアップ）というソフトを使っていたのですが、<br />
Vista64bitでは動きませんでした（単にtumblr側の仕様変更かもしれませんが）<br />
最新版は2008年のものなのでこのソフトはあきらめ、別の方法を採りました</p>
<p>今回は矩形選択可能なキャプチャソフトとrubyスクリプトでキャプチャするだけで自動的にファイルをアップロードするようにしました<br />
事前にflickrのAPI認証を行ってトークンキーを書き出しておきます（flickr.dat）<br />
詳細はrflickrに同梱のサンプルを見てください<br />
今回使用したスクリプトはこちら<br />
説明は必要ないかと思いますが、このスクリプトのあるフォルダを監視して拡張子がjpe?gかpngのファイルがあったらアップロードし、完了したら削除します</p>
<pre class="brush: ruby; title: ; notranslate">
#flickr_uploader.rb
require 'rubygems'
require 'flickr'

flickr = Flickr.new('flickr.dat',
                    API_KEY,
                    SECRET
                   )

while(1)
  Dir.glob('*.{jpg,jpeg,png}').each do |f|
    begin
      flickr.photos.upload.upload_file(f, f)
      puts &quot;#{Time.now} upload success #{f}&quot;
      File.delete('./' + f)
    rescue
      puts &quot;#{Time.now} error raised&quot;
    end
  end
  sleep 10
end
</pre>
<p><a href="http://ruby.morphball.net/note/blog.cgi/entries/1254840201-11c6" taget="_blank">[Tips] WindowsやLinuxで標準ブラウザを開く方法 &#8211; tetralabo</a><br />
ここの方法でアップロードしたらブラウザを開くようにしてもいいかもしれません</p>
<p>で、Linuxだと問題なくこいつを&#038;つけてバックグラウンドで動かせばいいのですが（Linuxはキャプチャソフトのほうが問題？）、<br />
windowsだとrubyスクリプトをバックグラウンド（ウィンドウのない状態）で動かす方法がなく（？）、<br />
仕方なくexerb（rubyスクリプトをexeで書き出す）を使うことにしました</p>
<p>今回一番難しかったのはexerbでexeを書き出すことです<br />
flickrの依存でmimeというgemも一緒に入るのですが、これのmime/types.rb.dataというファイルが拡張子がrbじゃないせいかexerbで読み込まれず、<br />
仕方なくmime側を直接書き換えてtypes.rbの中にtypes.rb.dataを追記しました；<br />
これで、<br />
ActiveScriptRubyでruby環境を構築している場合、コマンドプロンプトから<br />
mkexy flickr_uploader.rb<br />
Ctrl+C（スクリプトを終了させる）<br />
exerb -c gui flickr_uploader.exy <- rbじゃないので注意<br />
でflickr_uploader.exeというファイルが出力されます<br />
こいつはウィンドウも何も持たず、キー操作を受け付けないのでタスクマネージャから終了する必要があります<br />
ちなみに矩形選択可能なキャプチャソフトはWinShotを使っています</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1649/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>twitterに位置情報を埋め込む</title>
		<link>http://yusukezzz.net/blog/archives/1643</link>
		<comments>http://yusukezzz.net/blog/archives/1643#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:51:29 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1643</guid>
		<description><![CDATA[先日、twitterが正式に位置情報に対応しましたが、自分も試してみました rubyのtwitterというgemでやってみました こんな感じでoptionを渡してやるだけです twitter_gemのドキュメントにはop [...]]]></description>
			<content:encoded><![CDATA[<p>先日、twitterが正式に位置情報に対応しましたが、自分も試してみました<br />
rubyのtwitterというgemでやってみました</p>
<pre class="brush: ruby; title: ; notranslate">
# access_token, access_token_secretはあらかじめ準備しているものとします
twitter_oauth = Twitter::OAuth.new(CONSUMER_KEY, SECRET_KEY)
twitter_oauth.authorize_from_access(
access_token, access_token_secret)
@twitter = Twitter::Base.new(twitter_oauth)
@twitter.update('hoge', {:lat =&gt; latitude, :long =&gt; longtitude})
</pre>
<p>こんな感じでoptionを渡してやるだけです<br />
twitter_gemのドキュメントにはoptionがin_reply_to_status_idしか書いてないのですが、ちゃんと投稿してくれます<br />
ちなみに埋め込んだ座標をtweetdeckで表示するとこんな感じ<br />
<div id="attachment_1642" class="wp-caption alignnone" style="width: 194px"><a href="http://yusukezzz.net/blog/wp-content/uploads/2009/12/2bfc96a45921677282a36721a07709ca.png" rel="shadowbox[sbpost-1643];player=img;" title="NY maps overlay on tweetdeck"><img src="http://yusukezzz.net/blog/wp-content/uploads/2009/12/2bfc96a45921677282a36721a07709ca-184x300.png" alt="NY maps overlay on tweetdeck" title="NY maps overlay on tweetdeck" width="184" height="300" class="size-medium wp-image-1642" /></a><p class="wp-caption-text">NY maps overlay on tweetdeck</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1643/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rackでsessionをclearする</title>
		<link>http://yusukezzz.net/blog/archives/1627</link>
		<comments>http://yusukezzz.net/blog/archives/1627#comments</comments>
		<pubDate>Thu, 12 Nov 2009 06:30:04 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1627</guid>
		<description><![CDATA[session.clear でsession[:hoge]みたいなのは全部消えるようだ これだけで本当にsessionが初期化されているのかイマイチ自身が無い;]]></description>
			<content:encoded><![CDATA[<p>session.clear</p>
<p>でsession[:hoge]みたいなのは全部消えるようだ<br />
これだけで本当にsessionが初期化されているのかイマイチ自身が無い;</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1627/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyのTwitter::Base.new().verify_credentialsのメソッド？一覧</title>
		<link>http://yusukezzz.net/blog/archives/1625</link>
		<comments>http://yusukezzz.net/blog/archives/1625#comments</comments>
		<pubDate>Wed, 11 Nov 2009 07:48:18 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1625</guid>
		<description><![CDATA[verify_credentialsメソッドは認証したユーザについての情報を返す Mashとかいうhashっぽいので定義されていて、何故かメソッドのごとく&#8221; . &#8220;でアクセス出来る 例）Twitt [...]]]></description>
			<content:encoded><![CDATA[<p>verify_credentialsメソッドは認証したユーザについての情報を返す<br />
Mashとかいうhashっぽいので定義されていて、何故かメソッドのごとく&#8221; . &#8220;でアクセス出来る<br />
例）Twitter::Base.new(oauth).verify_credentials.screen_name</p>
<pre class="brush: ruby; title: ; notranslate">
created_at
description
favorited
favourites_count
followers_count
following
friends_count
geo_enabled
href
id
in_reply_to_screen_name
in_reply_to_status_id
in_reply_to_user_id
location
name
notifications
profile_background_color
profile_background_image_url
profile_background_tile
profile_image_url
profile_link_color
profile_sidebar_border_color
profile_sidebar_fill_color
profile_text_color
protected
rel
screen_name
source
status
statuses_count
text
time_zone
truncated
url
utc_offset
verified
</pre>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1625/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rubyのTwitter::Base.newで得られるメソッド一覧</title>
		<link>http://yusukezzz.net/blog/archives/1618</link>
		<comments>http://yusukezzz.net/blog/archives/1618#comments</comments>
		<pubDate>Wed, 11 Nov 2009 07:05:27 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1618</guid>
		<description><![CDATA[使い方は気合いで 以上]]></description>
			<content:encoded><![CDATA[<p>使い方は気合いで</p>
<pre class="brush: ruby; title: ; notranslate">
require 'twitter' # ver 0.7.0

==
===
=~
__id__
__send__
b64encode
blank?
block
class
client
clone
dclone
decode64
decode_b
delete
direct_message_create
direct_message_destroy
direct_messages
direct_messages_sent
disable_notifications
display
dup
enable_notifications
encode64
enum_for
eql?
equal?
extend
favorite_create
favorite_destroy
favorites
follower_ids
followers
freeze
friend_ids
friends
friends_timeline
friendship_create
friendship_destroy
friendship_exists?
frozen?
get
hash
help
id
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
is_list_member?
kind_of?
list
list_add_member
list_create
list_delete
list_members
list_remove_member
list_subscribe
list_subscribers
list_timeline
list_unsubscribe
list_update
lists
memberships
method
methods
nil?
object_id
post
private_methods
protected_methods
public_methods
put
rate_limit_status
replies
respond_to?
send
singleton_methods
status
status_destroy
taguri
taguri=
taint
tainted?
tap
to_a
to_enum
to_json
to_s
to_yaml
to_yaml_properties
to_yaml_style
type
unblock
untaint
update
update_delivery_device
update_profile
update_profile_colors
user
user_timeline
verify_credentials
</pre>
<p>以上</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1618/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu9.10でruby環境構築</title>
		<link>http://yusukezzz.net/blog/archives/1604</link>
		<comments>http://yusukezzz.net/blog/archives/1604#comments</comments>
		<pubDate>Fri, 06 Nov 2009 00:03:01 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1604</guid>
		<description><![CDATA[9.10がリリースされたので入れ直したら色々忘れてたのでメモ sinatra可愛いよsinatra]]></description>
			<content:encoded><![CDATA[<p>9.10がリリースされたので入れ直したら色々忘れてたのでメモ</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo aptitude install ruby ruby-dev libsqlite3-dev swig
$ sudo gem install sinatra sequel sqlite3-ruby
</pre>
<p>sinatra可愛いよsinatra</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1604/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

