2012/02/09


たとえばこういう XML があったとして、
<status><created_at>Mon Feb 06 21:07:52 +0000 2012</created_at><id>166629198054690816</id><text>Post-Bowl Twitter analysis http://t.co/OYYSRSew http://t.co/M0AtLQVd</text><source>web</source><truncated>false</truncated><favorited>false</favorited><in_reply_to_status_id></in_reply_to_status_id><in_reply_to_user_id></in_reply_to_user_id><in_reply_to_screen_name></in_reply_to_screen_name><retweet_count>454</retweet_count><retweeted>false</retweeted><user><id>783214</id><name>Twitter</name><screen_name>twitter</screen_name><location>San Francisco, CA</location><description>Always wondering what's happening. </description><profile_image_url>http://a0.twimg.com/profile_images/1124040897/at-twitter_normal.png</profile_image_url><profile_image_url_https>https://si0.twimg.com/profile_images/1124040897/at-twitter_normal.png</profile_image_url_https><url>http://blog.twitter.com/</url><protected>false</protected><followers_count>7625563</followers_count><profile_background_color>ACDED6</profile_background_color><profile_text_color>333333</profile_text_color><profile_link_color>038543</profile_link_color><profile_sidebar_fill_color>F6F6F6</profile_sidebar_fill_color><profile_sidebar_border_color>EEEEEE</profile_sidebar_border_color><friends_count>822</friends_count><created_at>Tue Feb 20 14:35:54 +0000 2007</created_at><favourites_count>16</favourites_count><utc_offset>-28800</utc_offset><time_zone>Pacific Time (US &amp; Canada)</time_zone><profile_background_image_url>http://a1.twimg.com/profile_background_images/378245879/Twitter_1544x2000.png</profile_background_image_url><profile_background_image_url_https>https://si0.twimg.com/profile_background_images/378245879/Twitter_1544x2000.png</profile_background_image_url_https><profile_background_tile>true</profile_background_tile><profile_use_background_image>true</profile_use_background_image><notifications>false</notifications><geo_enabled>true</geo_enabled><verified>true</verified><following>true</following><statuses_count>1266</statuses_count><lang>en</lang><contributors_enabled>true</contributors_enabled><follow_request_sent>false</follow_request_sent><listed_count>68708</listed_count><show_all_inline_media>true</show_all_inline_media><default_profile>false</default_profile><default_profile_image>false</default_profile_image><is_translator>false</is_translator></user><geo/><coordinates/><place/><possibly_sensitive>false</possibly_sensitive><contributors><user_id>7694352</user_id></contributors></status>
見づらいので vimrc に1行書いてあげると、 map <Leader>x !python -m BeautifulSoup<CR>
範囲選択してから <Leader> x でキレイに整形してくれます。 <status>
 <created_at>
  Mon Feb 06 21:07:52 +0000 2012
 </created_at>
 <id>
  166629198054690816
 </id>
 <text>
  Post-Bowl Twitter analysis http://t.co/OYYSRSew http://t.co/M0AtLQVd
 </text>
 <source>
  web
 </source>
 <truncated>
  false
 </truncated>
 <favorited>
  false
 </favorited>
 <in_reply_to_status_id>
 </in_reply_to_status_id>
 <in_reply_to_user_id>
 </in_reply_to_user_id>
 <in_reply_to_screen_name>
 </in_reply_to_screen_name>
 <retweet_count>
  454
 </retweet_count>
 <retweeted>
  false
 </retweeted>
 <user>
  <id>
   783214
  </id>
  <name>
   Twitter
  </name>
  <screen_name>
   twitter
  </screen_name>
  <location>
   San Francisco, CA
  </location>
  <description>
   Always wondering what's happening.
  </description>
  <profile_image_url>
   http://a0.twimg.com/profile_images/1124040897/at-twitter_normal.png
  </profile_image_url>
  <profile_image_url_https>
   https://si0.twimg.com/profile_images/1124040897/at-twitter_normal.png
  </profile_image_url_https>
  <url>
   http://blog.twitter.com/
  </url>
  <protected>
   false
  </protected>
  <followers_count>
   7625563
  </followers_count>
  <profile_background_color>
   ACDED6
  </profile_background_color>
  <profile_text_color>
   333333
  </profile_text_color>
  <profile_link_color>
   038543
  </profile_link_color>
  <profile_sidebar_fill_color>
   F6F6F6
  </profile_sidebar_fill_color>
  <profile_sidebar_border_color>
   EEEEEE
  </profile_sidebar_border_color>
  <friends_count>
   822
  </friends_count>
  <created_at>
   Tue Feb 20 14:35:54 +0000 2007
  </created_at>
  <favourites_count>
   16
  </favourites_count>
  <utc_offset>
   -28800
  </utc_offset>
  <time_zone>
   Pacific Time (US &amp; Canada)
  </time_zone>
  <profile_background_image_url>
   http://a1.twimg.com/profile_background_images/378245879/Twitter_1544x2000.png
  </profile_background_image_url>
  <profile_background_image_url_https>
   https://si0.twimg.com/profile_background_images/378245879/Twitter_1544x2000.png
  </profile_background_image_url_https>
  <profile_background_tile>
   true
  </profile_background_tile>
  <profile_use_background_image>
   true
  </profile_use_background_image>
  <notifications>
   false
  </notifications>
  <geo_enabled>
   true
  </geo_enabled>
  <verified>
   true
  </verified>
  <following>
   true
  </following>
  <statuses_count>
   1266
  </statuses_count>
  <lang>
   en
  </lang>
  <contributors_enabled>
   true
  </contributors_enabled>
  <follow_request_sent>
   false
  </follow_request_sent>
  <listed_count>
   68708
  </listed_count>
  <show_all_inline_media>
   true
  </show_all_inline_media>
  <default_profile>
   false
  </default_profile>
  <default_profile_image>
   false
  </default_profile_image>
  <is_translator>
   false
  </is_translator>
 </user>
 <geo>
  <coordinates>
   <place>
    <possibly_sensitive>
     false
    </possibly_sensitive>
    <contributors>
     <user_id>
      7694352
     </user_id>
    </contributors>
   </place>
  </coordinates>
 </geo>
</status>

ネタ元: http://wozozo.hatenablog.com/entry/2012/02/08/121504

ちなみに-mだけでやる場合は細かい制御はできなさそう。
Posted at by



2012/02/06


さっそく作ってみた。
Google Japan Blog: Google マップが携帯でも表示できるようになりました
HTTP::MobileAgent::Plugin::Locatorを使って緯度経度を取り、GoogleMapの静的画像を表示するサンプルを作ってみた。
ただGoogleMapの座標指定は測地系だったので
http://minken.net/mt/archives/locations.pl の一部を使わせて頂きました。
Perlで投影系変換出来るモジュール誰か知りませんか?

ソースは以下の様な感じ。
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use HTTP::MobileAgent;
use HTTP::MobileAgent::Plugin::Locator;


my $google_map_api_key = "ABQIAAAAS_2fKEdj-fsDOrnYqd4nthTGTkG1t9CC6WQns4yK382vvQcY9RS5JGW4WA0hwZKxfIpKeCjuMOMPIA";

sub geoconv {
    ...
}

sub llh2xyz { # 楕円体座標 -> 直交座標
    ...
}

sub xyz2llh { # 直交座標 -> 楕円体座標
    ...
}

sub deg2dms {
    ...
}

sub dms2deg {
    ...
}

my $q = CGI->new;
my $agent;
my $lat = '';
my $lng = '';
my $location = '';
eval {
  $agent = HTTP::MobileAgent->new;
  $location = $agent->get_location( $q );
  ($lng, $lat) = geoconv($location->lng, $location->lat, $location->datum)
};

print $q->header(-charset=>'Shift_JIS'),<<END;
<html>
<head>
<title>GoogleMap from GPS</title>
</head>
<body>
<h1>What is this?</h1>
Show the Google Map static image from your GPS location.<br />
END

if ($agent && $agent->is_non_mobile) {
  print "<b>Are not mobile agent?</b>";
} else {
  print "<a href=\"device:location?url=gmobile_map.cgi\" lcs>Where?</a>"
    if ($agent->is_docomo);
  print "<a href=\"device:location?url=gmobile_map.cgi\">Where?</a>"
    if ($agent->is_ezweb);
  print "<a href=\"gmobile_map.cgi\" z>Where?</a>"
    if ($agent->is_softbank && !$agent->is_type_3gc);
  print "<a href=\"location:auto?url=gmobile_map.cgi\">Where?</a>"
    if ($agent->is_softbank && $agent->is_type_3gc);
  if ($lat && $lng) {
    print << "END";
<img src="http://maps.google.com/staticmap?center=$lat,$lng&markers=$lat,$lng,red&zoom=18&size=300x200&key=$google_map_api_key"><br />
latitude: $lat<br />
longitude $lng<br />
END
  }
}

print "</body>\n</html>";
若干ずれるのはしょうがないか...
で、動いてる物は
http://mattn.kaoriya.net/cgi-bin/gmobile_map.cgi
携帯端末からアクセス下さい。
キャリア毎のアンカー作ってくれるモジュールも欲しいなぁ...

AWSWORD:google_map
Posted at by



2012/01/25


やっぱり最初はhello worldって事で...

Rust

RustRust a safe, concurrent, practical language Rust is a curly-brace, block-structured expression langu...
Rust is a curly-brace, block-structured expression language. It visually resembles the C language family, but differs significantly in syntactic and semantic details. Its design is oriented toward concerns of “programming in the large”, that is, of creating and maintaining boundaries – both abstract and operational – that preserve large-system integrity, availability and concurrency.

http://www.rust-lang.org/
windowsのインストーラがダウンロード出来なかったのでgithubからダウンロードしてビルドした。
mozilla/rust - GitHub

a safe, concurrent, practical language

https://github.com/mozilla/rust
ビルドはmingw/msysで./configure && make install
LLVM上のコンパイラなのでビルドは結構リソースを食う。かなり食う。

ただ単にfizzbuzz出してもdanさんの真似になって面白く無かったのでメッセージボックス出してみた。
use std;
import std::io;

#[abi = "stdcall"]
native mod user32 {
  fn MessageBoxA(h: ctypes::c_uint,
      message: str::sbuf, title: str::sbuf, flag: ctypes::c_uint)
        -> ctypes::c_uint;
}

fn main() {
  str::as_buf("hello", { |message|
    str::as_buf("world", { |title|
      user32::MessageBoxA(0u, message, title, 0u);
    })
  })
}
abiとしてcdeclやstdcallが指定出切る。rustcコマンドはuser32に対してちゃんと-luser32というリンクオプションを足してくれるので、コマンドラインでガチャガチャやるイメージはあまりない。
なお、CARGO_ROOTという環境変数にc:/rust/binc:/rust/libでいう所のc:/rustを指定しておくと、ちゃんとリンカが判断してファイルを探してくれる。
vim編集中に簡単に実行出切る様に、quickrunにもプルリクエストを送っておいた。(マージされた)
#22: support mozilla rust. by mattn for thinca/vim-quickrun - Pull Request - GitHub
https://github.com/thinca/vim-quickrun/pull/22

環境が揃うユーザならば、vimでファイル開いて<leader>rとタイプすればメッセージボックスが出る様になります。
rust-win32
所感としては、str::as_bufがブロック式なので、rubyっぽく思えると同時に引数2つの場合めんどくさ過ぎる!と思った。言語というか、仕組み的にはGo言語が近いなーとか思ってたら、Dubheadさんから教えてもらったリンクに既に書いてあった。
Doc language FAQ - GitHub

Have you seen this Google language, Go? How does Rust compare?

面白そうなのでしばらく触ってみる。
Posted at by