2008年 03月 20日

git

現在のワーキングツリーの .git ディレクトリの位置

$ cd ~/tmp/git/Documentation
$ git rev-parse --git-dir
/Users/cho45/tmp/git/.git

完全なコミットログ (プログラム解析するための)

$ git log --no-color -z --pretty=raw --parents
require "digest/sha1"

def git_log(data, add)
	boundary = "__#{Digest::SHA1.hexdigest(rand.to_s)}__"
	p boundary
	format = data.map {|f| "%#{f}" }.join(boundary)

	`git log --no-color -z --pretty=format:'#{format}' --parents #{add}`.split(/\0/).map {|c|
		yield c.split(boundary)
	}
end

git_log(%w(H T P an ae ai s b), "HEAD~10..") do |commit|
	commit_hash, tree_hash, parents, author_name, author_mail, author_date, subject, body = commit
	p subject
	p body
end

github (Rails っぽい?) の中の人が ruby binding かいてるみたいだ。https://rubyforge.org/projects/grit/ mojombo++ (よくしらない

gerry++

はらいたすぎる

XREA に git いれる

例によってリソースがたりないといわれて XREA 上での make ができないのでローカルで

make LDFLAGS='-static' NO_CURL=1 NO_TCLTK=1 prefix=/virtual/[username]/git

CURL つきで static link がつくれなかったので NO_CURL した。GUI はいらないので NO_TCLTK して、prefix をサーバ上のパスにあわせた。(prefix あわせないと builtin コマンド以外つかえない)

でもって XREA 上に転送して、~/git/bin において、.bashrc で PATH を通すとつかえた。

xrea:

$ mkdir -p ~/repos/foobar
$ cd ~/repos/foobar
$ git init
local:

$ git init
$ echo 'test' > test.txt
$ git add test.txt
$ git commit -m 'test test'
$ git remote add origin xrea:repos/foobar
$ git push origin master
another local

$ git clone xrea:repos/foobar
$ cd foobar
$ cat test.txt
test

この状態で xrea にログインして ls ~/repos/foobar してもなんもみえないけど関係ない。git pull するまでたぶん表にでてこない (でも git pull はリソース不足で失敗するっていう)

2008年 03月 19日

30boxes

つかってみる。最近 Hiveminder + todo.pl (braindump/editdump) に感動したのでそっち系に

2008年 03月 16日

LDR バックエンドの OpenFL のレート同期するやつ

今までは、LDR 側でログインしていない状態でレート設定すると LD のログイン画面が開くだけで、レートの設定自体はもう一回やらないといけなかったけど、もっかい操作しなくてもログインしたら勝手に再試行してほしかったのでやってみた。なんとなくぼーっと横になってたら、簡単にできそうな方法が思い浮かんだだけだけど

  1. GM_getValue をループさせ ApiKey がセットされるのを待つ
  2. Livedoor のログイン画面を別ウィンドウで表示させる ( http://www.livedoor.com/close に飛されるようにしとく)
  3. /close にフックして ApiKey を再度取得し、GM_setValue
  4. ログインウィンドウを閉じる
  5. OpenFL 側の GM に制御が戻り、継続が実行される

ツカッテテヨカッタ JSDeferred

2008年 03月 12日

Perl のリスト、ハッシュのマージ、reduce メモ

Ruby での

require "pp"

data = [
	{ :name => "foo", :value => 1 },
	{ :name => "bar", :value => 2 },
	{ :name => "baz", :value => 3 },
]


pp data.inject(0) {|r,i| r + i[:value] }

pp data.inject({}) {|r,i| r.update( i[:name] => i ) }

__END__
6
{"baz"=>{:value=>3, :name=>"baz"},
 "foo"=>{:value=>1, :name=>"foo"},
 "bar"=>{:value=>2, :name=>"bar"}}
use List::Util qw/reduce/;

use Data::Dumper;
sub p ($) { print Dumper shift }

my $data = [
	{ name => "foo", value => 1 },
	{ name => "bar", value => 2 },
	{ name => "baz", value => 3 },
];

p reduce { $a + $b->{value} } 0, @$data;

p reduce { +{ %$a, $b->{name} => $b } } {}, @$data;

__END__
$VAR1 = 6;
$VAR1 = {
          'bar' => {
                     'value' => 2,
                     'name' => 'bar'
                   },
          'baz' => {
                     'value' => 3,
                     'name' => 'baz'
                   },
          'foo' => {
                     'value' => 1,
                     'name' => 'foo'
                   }
        };

引数のとりかた的に Perl は初期値の与えかたが自然な感じがする。

2008年 03月 11日

List::Enumerator

慣れるために書いてみる

package List::Enumerator;

use strict;
use warnings;

use base qw/Exporter/;
our @EXPORT = qw/E/;

use Exception::Class ( "StopEnumeration ");

sub E {
	List::Enumerator->new(@_);
}


sub new {
	my ($class, @args) = @_;

	my $self = {};
	bless $self, $class;

	$self->_init(@args);

	$self;
}

sub _init {
	my ($self, @args) = @_;

	my $i = 0;
	$self->_init_with_fun(sub {
		$i < @args ? $args[$i++] : StopEnumeration->throw;
	});
}

sub _init_with_fun {
	my ($self, $fun) = @_;
	$self->{fun} = $fun;
}

sub next {
	my $self = shift;
	$self->{fun}->();
}

sub each {
	my ($self, $fun) = @_;
	eval {
		while (1) {
			local $_ = $self->next;
			$fun->($_);
		}
	}; if (my $e = Exception::Class->caught('StopEnumeration')) {
	}
}

sub map {
	my ($self, $fun) = @_;
	my @ret = ();
	$self->each(sub {
		push @ret, $fun->($_);
	});
	wantarray ? @ret : List::Enumerator->new(@ret);
}
use Data::Dumper;
sub p { print Dumper shift }

use List::Enumerator;


E(1, 2, 3)->each(sub {
	p shift;
	p $_;
});

p [ E(1, 2, 3)->map(sub { $_ * $_; }) ];

E(1, 2, 3)->map(sub {
	$_ * $_;
})->each(sub {
	p $_;
});

cycle かくまえに眠くなった

もうちょっと経ったら (謎) autobox さわってみよう

2008年 03月 10日

Open Fastladder / MySQL

なんか開いてから表示されるまでクソおそくてどうしたもんかなぁ、と思っていたけど、slow_log を有効にして観察したら 10 秒とか 40 秒とかかかるクエリがあったのでインデックスはってみた。劇的にはやくなった。更めて、自分で DB のことわかってないなぁ……と気付かされた (超ごく最近まで slow_log をとれることすら知らなかった)。

実際に実行したやつ (phpmyadmin からもごもごやってた)

ALTER TABLE `items` ADD INDEX `feed_id_stored_on_created_on` ( `feed_id` , `stored_on` , `created_on` , `id` )  

ためしてないけど、Migration:

# db/migrate/009_add_items_index.rb
class AddItemsIndex < ActiveRecord::Migration
	def self.up
		add_index :items, [:feed_id, :stored_on, :created_on, :id], :name => :items_search_index
	end

	def self.down
		remove_index :items_search_index
	end
end


問題のログ

# Time: 080310  9:59:22
# User@Host: root[root] @ localhost []
# Query_time: 47  Lock_time: 0  Rows_sent: 10  Rows_examined: 3511
SELECT * FROM `items`   WHERE (items.feed_id = 36 AND (stored_on >= '2008-03-10 01:31:30'))  ORDER BY created_on DESC, id DESC LIMIT 10;

はったあとの EXPLAIN

$ mysql -u root fastladder
mysql> EXPLAIN SELECT * FROM `items`   WHERE (items.feed_id = 36 AND (stored_on >= '2008-03-10 01:31:30'))  ORDER BY created_on DESC, id DESC LIMIT 10;
+----+-------------+-------+-------+--------------------------------------------------------------+------------------------------+---------+------+------+-----------------------------+
| id | select_type | table | type  | possible_keys                                                | key                          | key_len | ref  | rows | Extra                       |
+----+-------------+-------+-------+--------------------------------------------------------------+------------------------------+---------+------+------+-----------------------------+
|  1 | SIMPLE      | items | range | index_items_on_feed_id_and_link,feed_id_stored_on_created_on | feed_id_stored_on_created_on | 13      | NULL |  115 | Using where; Using filesort | 
+----+-------------+-------+-------+--------------------------------------------------------------+------------------------------+---------+------+------+-----------------------------+
1 row in set (0.06 sec)
2008年 03月 09日

pl

OpenFL 用の Plagger がずっとうごきっぱで鯖が重かったので 30min ごとのクロールじゃなくて 1h ごとにした。

TODO ドメインの更新

やばいわすれそうだ