さようなら TRECK、ようこそ ルイガノ
自転車を買いました。小径タイプのものにしました。当初折り畳みがいいな、と思っていたけれどね。フォルムがよかった。
タイプは LGS-MV 2 です。梅雨でしばらく雨の日が続きそうで、ゆっくりサイクリングを楽しむのはもう少し先になりそう。
RubyForge News の新着通知 BOT を作ってみた
BOT を作ってみたくて、RubyForge News の新着を Wassr の RubyForge チャンネルに通知するようなものを作りました。
http://wassr.jp/channel/rubyforge
全体に乗せるのは邪魔くさいので、チャンネルへの発言になっています。
更新確認は 30 分くらいの間隔で行っています。
BOT 本体はこちら。http://wassr.jp/user/rubyforge
Ruby で Web::Service
get を実装してみたのでリボジトリに登録した。名前も WebAPI::Base から WebService::Simple に変更しました。
やっぱりこういうツールがあると楽かもね。考えた人はすごい。
http://xry.googlecode.com/svn/trunk/ruby/WebService/
使い方はこちら。前の記事の再掲です。
メインソース
#!/usr/bin/ruby
require 'kconv'
require 'webapi'
class Wassr < WebService::Simple
basic_auth('めーるあどれす or ゆーざめい', 'ぱすわーど')
base_url 'http://api.wassr.jp/statuses/'
end
w = Wassr.new
puts w.post('update.json', {:source => 'WebService::Simple(Ruby)', :status => "Ruby でも WebService::Simple したい".toutf8})
select() と epoll() のコード比較
標準入力からの入力を指定した秒数だけ待つ関数を、select() と epoll() を使って書いてみた。最初 epoll_wait() に指定する時間はミリ秒とは気づかずに設定してしまっていた。
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <fcntl.h>
int set_non_block(int fd);
int test_select(int fd, int timeout);
int test_epoll(int fd, int timeout);
int main(int argc, char *argv[])
{
printf("Hello! World\n");
test_select(0, 3);
test_epoll(0, 3);
return 0;
}
int set_non_block(int fd)
{
int flg;
flg = fcntl(fd, F_GETFD);
if (flg != -1) {
flg = fcntl(fd, F_SETFL, flg | O_NONBLOCK);
}
return flg;
}
int test_select(int fd, int timeout)
{
fd_set read_fds;
struct timeval tv;
int ret;
char s[8];
set_non_block(fd);
FD_ZERO(&read_fds);
FD_SET(fd, &read_fds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
ret = select(fd + 1, &read_fds, NULL, NULL, &tv);
if (ret == -1) {
printf("select() failed\n");
} else if (ret == 0) {
printf("select() timeout\n");
} else if (ret) {
read(fd, s, sizeof(s));
printf("select() success\n");
}
return 0;
}
int test_epoll(int fd, int timeout)
{
int epfd;
int nfd;
struct epoll_event event;
struct epoll_event events;
char s[8];
epfd = epoll_create(1);
if (epfd < 0) {
printf("epoll_create() failed\n");
return -1;
}
set_non_block(fd);
memset(&event, 0, sizeof(event));
event.events = EPOLLIN | EPOLLET;
event.data.fd = fd;
if (epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &event) < 0) {
printf("epoll_ctl() failed\n");
return -1;
}
nfd = epoll_wait(epfd, &events, 1, timeout * 1000);
if (nfd < 0) {
printf("epoll_wait() failed\n");
} else if (nfd == 0) {
printf("epoll_wait() timeout\n");
} else if (nfd) {
read(fd, s, sizeof(s));
printf("epoll_wait() success\n");
}
return 0;
}
C 言語のテストフレームワーク
wassr の TL でテストの話があったので、C 言語で使えそうなテストフレームワークを探してみた。CUnit があるのは知っていたけれど。
それぞれの特徴や使い方はこれから調べる。
Effective CUnit は最近も更新されているし、機能改善などはこれからも期待できるのかな。CSpec も最近のブームからできたものだろうから、これから続いていくような気がする。
- [[Cutter|http://cutter.sourceforge.net/index.html.ja]]
- [[Cunit|http://sourceforge.net/projects/cunit/]]
- [[Effective CUnit|http://kaeru-lab.sakura.ne.jp/cunit/]]
- [[CSpec|http://github.com/arnaudbrejeon/cspec/tree/master]]
- [[WinUnit|http://msdn.microsoft.com/ja-jp/magazine/cc136757.aspx]]
Google の C++ 用のテストフレームワークを見つけた。
- [[googletest|http://code.google.com/p/googletest/]]