Fork me on GitHub

2011/05/29


このエントリーをはてなブックマークに追加
Go言語がGoogle App Engineで動くようになった事を先日の記事でご紹介しました。
僕に取っては大きな出来事でした。
さて、Go言語用にSDKが提供されていますが、このSDKに含まれるgo-moustachioはアップロードされた画像にヒゲを付けるWebアプリケーションで、以下のURLでも公開されています。
Welcome to Moustachio - Moustachio
http://moustach-io.appspot.com/
仕組みとしては、アップロードされた画像に対してJSON APIから受け取ったパラメータを元に、ヒゲの位置、ヒゲの上向き下向き度合いを変更出来ます。HTML上で合成するのではなく、freetypeを使った画像合成が行われています。
出来上がった画像はGoogle Buzzやtwitterで公開出来るリンクが用意されています。

とても面白いサンプルなのですが、一つ大きな問題が起こりました。
そう、ヒゲが回転出来ないんです。
moustachio1
どう考えても、時計周りに回転が必要ですよね。これでは全世界のヒゲマニアが安眠出来ません。そこでパッチを書きました。
a820df2a6dda - mattnjp-appengine-go - fork of appengine-go - Google Project Hosting

Log message rotate moustachio.

https://code.google.com/r/mattnjp-appengine-go/source/detail?r=a820df2a6ddab19d7c22fe66f8fc76fc41690018&name=default
仕組みとしては、これまで画像イメージに対してfreetypeでヒゲを描いていたのに対して、同じ大きさのRGBA領域に対してヒゲを描画し、ヒゲ画像を回転して元の画像に移しています。
メインとなる部分のコードは以下。
// transcribe points to image from rotated moustache
ra := math.Pi * 2 * float64(angle) / 360
for i := 0; i < h; i++ {
    for j := 0; j < w; j++ {
        xx := int(float64(j-x)*math.Cos(-ra)-float64(i-y)*math.Sin(-ra)) + x
        yy := int(float64(j-x)*math.Sin(-ra)+float64(i-y)*math.Cos(-ra)) + y
        c := mp.At(xx, yy)
        cr, cg, cb, ca := c.RGBA()
        if cr != 0 || cg != 0 || cb != 0 || ca != 0 {
            mrgba.Set(j, i, c)
        }
    }
}
一般的に画像の回転は各ポイントを回転させるのではなく、回転後のポイントに対して元のポイントを求める事で穴の開かない画像が得られます。 本来ならば、オンラインで公開したい所ですが、先日の「appengineにgoをデプロイ出来る権利50名様プレゼント」に外れてしまいましたので、試したい方はローカルサーバでお楽しみ下さい。
moustachio2
ちゃんと綺麗にヒゲが生えました。
Posted at 22:04 in ソフトウェア::lang::go
Tagged as: appengine, golang, moustachio
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2011/05/11


このエントリーをはてなブックマークに追加
僕にとってデカいニュースが飛び込んできた。
Goの開発プロジェクトに関わってて良かった。今日はそう思える日になりそうだ。
まだGoogle App Engine Blogにもエントリされてないが、Google App EngineにGo言語が仲間入りした。
Downloads - Google App Engine - Google Code

Google App Engine SDK for Go

http://code.google.com/intl/en/appengine/downloads.html#Google_App_Engine_SDK_for_Go
Go言語は元々Google社員が開発している言語で、コンパイル型言語とは言えDuckTypingを前面に押し出した、スクリプト言語に近い仕様になっています。またWebに関するAPIは豊富で短いコードで簡単にWebアプリケーションを書く事が出来る様になっています。
例えば、先日書いたコマンドライン向けTwitter Clientであれば、OAuthライブラリこそ他に頼っているがメインのコードは350行だ。

さて今回公開されたGoogle App Engine for Goだが仕組みはGoが元々持っているWebサーバ機能を使っている。ソースはコンパイルせずに配置しapp.yamlファイルは以下の様に書く。
application: helloworld
vesion: 1
runtime: go
api_version: 1

handlers:
url: .*
  script: _go_app
この _go_app は固定。実行すると内部でコンパイルされ、applicationで指定したパッケージのinit関数が呼び出される。アプリケーションはあくまでパッケージとして提供し、main関数は書かない。なのでinitでハンドラを登録する。
極端に簡単なアプリケーションを書くとすると、以下の様になる。
package helloworld

import "http"

func init() {
    http.HandleFunc("/"func(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Content-Type""text/plain")
        w.Write([]byte("Hello, World"))
    })
}
まぁ簡単。もちろんGoogle App Engine上で動く言語 Python や Java と同様に appspot.com でホストする場合はローカルディスクにはアクセス出来ない。ただし既に
  • blobstore
  • datastore
  • mail
  • memcache
  • taskque
  • urlfetch
  • user
という他の言語と同じだけのAPIは既に用意されている。Goにはポインタやアドレスという概念がある為にメモリに直接アクセスする様な事も出来るが、Goはその全てをランタイムを介して行っているのでそれらを例外として扱う事が出来る。
なお、appengine向けのGoランタイム上で動作する為、appspot.com でホストする場合にはコンパイル済みのモジュールを配置する事が出来ない。こちらは python で pyd が置けないのと同じですね。

まさかPerlよりも先にGoogle App Engine向け言語として採用されるとは思ってませんでした。ようやく日の目を浴びる事になりますね。

Go言語はじまったな

Posted at 10:13 in ソフトウェア::lang::go
Tagged as: appengine, golang, googleappengine
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2009/02/16


このエントリーをはてなブックマークに追加
さらに朗報は続く
Google App Engine Blog: The sky's (almost) the limit! "High CPU" is no more.

We're very excited today to announce that we've raised limits on several App Engine operations:

  • No more "High CPU Requests"! App Engine Apps were once allowed no more than 2 CPU-intensive requests per minute. We've made some adjustments to the way we handle requests, and have eliminated this limitation altogether. To learn more about how this works and the implications for your app, see our documentation.
  • Response deadline raised to 30 seconds. The amount of time an App Engine app can take to respond to an incoming request has been raised from 10 to 30 seconds! There are limits on the number of simultaneous active requests an application can process at any given moment--see our docs to learn more.
  • Size limits on code files, static files, and requests/responses raised to 10MB! App Engine apps can now receive requests and send responses of up to 10MB in size, and users can upload 10MB code and static files as well. Note that API requests (e.g. memcache.set(), db.put()) are still limited to 1MB in size.
http://googleappengine.blogspot.com/2009/02/skys-almost-limit-high-cpu-is-no-more.html
Google App Engineに1分あたり2CPU以上負荷を掛ける様なリクエストが許される事になりました。
またレスポンスのデッドラインが10秒から30秒にまで引き上げられました。
さらにコード、静的ファイル、および要求/応答におけるサイズ制限が10MBに引き上げられました(但しmemcache.set()、db.put()はまだ1MBに制限されています)。

これで例えば、デカいクエリを投げる様な処理でもエラーで落ちるって事が少なくなるんじゃないですかね。
もうすぐすると、Google App Engineでタイマ発動処理をサポートするという噂もあるので、よりインタラクティブな処理が作れるんじゃないですかね。

2009/02/10


このエントリーをはてなブックマークに追加
これは朗報。
Google App Engine Blog: SDK version 1.1.9 Released
  • You can now use the Python standard libraries urllib, urllib2 or httplib to make HTTP requests. This has been a frequent request on our issue tracker.
  • We've been working on a set of tools that will make the process of uploading and downloading data from App Engine applications easier. Today we're excited to announce an early release of our new bulk uploading client. You can try it out here. Let us know what you think in our Google Group!
  • Several updates to our datastore, including the automatic generation of single property indexes and the addition of IN and != operators to db.Query. See the Datastore API docs for more details.
  • A bunch of additional bugfixes and enhancements, listed in our Release Notes.
http://googleappengine.blogspot.com/2009/02/sdk-version-119-released.html
試しに以下の様なコードを書いて
import urllib2

f = urllib2.urlopen('http://www.google.com/')
print "Content-Type: text/plain;"
print
print f.read()

実行させてみた。

おー動いてる。これで今までGoogle App Engineのurlfetch API様にパッチを当ててきた物が要らなくなる。