hgwebでリビジョングラフを表示

1.0.2の最新のリリース版には入っていませんが、trunk(?)というかmainでは、hgwebでリビジョングラフの表示ができるようです。

このサンプルでは、paperというstyleを使っています。gitwebに比べてシンプルでMercurialらしいですね。結構好みです。

The Game of Life

http://d.hatena.ne.jp/giveup/20080505

もう少し練ってみた。

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

void l(_Bool mas[2][10][10],int o,int n) {
  for(int x=0;x<10;x++)
    for(int c,y=0;c=0,y<10;mas[n][x][y]=c==3||(c==4&&mas[o][x][y]),y++)
      for(int xx=MAX(x-1,0);xx<=MIN(x+1,9);xx++)
        for(int yy=MAX(y-1,0);yy<=MIN(y+1,9);yy++)
          c+=mas[o][xx][yy];
}

void p(_Bool (*o)[10],int step) {
  printf("\x1b\x5b\x32\x4a\x1b\x5b\x48%d step\n",step);
  for(int x=0;x<10;x++,putchar('\n'))
    for(int y=0;y<10;y++)
      putchar("-O"[o[x][y]]);
}

int main(void) {
  _Bool mas[2][10][10] = {
    {
      {0,1,0,0,1,0,0,1,0,0},
      {0,0,1,0,0,0,1,1,0,0},
      {0,1,1,1,0,0,0,1,1,0},
      {0,1,0,0,0,1,1,0,1,0},
      {0,0,0,1,1,0,0,0,0,0},
      {0,1,1,1,0,0,0,0,1,1},
      {0,0,1,0,1,0,0,1,0,0},
      {1,1,1,0,0,0,1,0,1,0},
      {0,0,0,0,1,0,0,0,0,1},
      {0,0,1,1,1,0,0,1,0,0},
    },
  };

  for(int i=0,o=0,n=1;i<100&&memcmp(mas[0],mas[1],100*sizeof(_Bool));i++,n^=o^=n^=o) {
    l(mas,o,n);
    p(mas[o],i);
    usleep(100000);
  }
  return 0;
}

『ビューティフルコード』

ビューティフルコード (THEORY/IN/PRACTICE)

ビューティフルコード (THEORY/IN/PRACTICE)

  • 4/18 Amazonからおすすめのメールがくる。
  • 4/20 注文する。
  • 4/25 Amazonから在庫がないというメールがくる。
  • 4/29 Amazonの注文をキャンセルする。
  • 4/29 紀伊国屋で注文する。
  • 5/2 届く。

今年のゴールデンウィークはこれで退屈せずに済む。

29章の『エッセイのごときプログラム』はなかなか興味深い。特にRakefileの文法の話の中で、文法を既存のRubyにあわせる『シンプルさ』を追求するよりも、『人間の書くプログラムのシンプルさ』を選んだとあった。

(a)

task({:default => [:test]})
task(:test, lambda(){
        ruby "test/unittest.rb"
     })

こう書くよりも

(b)

task :default => [:test]
task :test do
  ruby "test/unittest.rb"
end

こう書く方がより人間が書くコードとしてはシンプルになるということだ。

(b)の方がシンプルであるというより、(b)の方が『自然な表現』であると思った。

本の中でrakeのRakefileDSL(Domain Specific Language)と言っていたが、DSLというのは、特定の目的のために最適化された言語という意味で、これはその目的にあった表現の『自然さ』の追求なのではないかと思う。

dformatプラグインを作って遊んでみた

これを改造して、

{{{#!dformat
style bitwid .3
PDP-8 Instr
        0-2 Op Code
        3 Indirect Bit
        4 Page-Zero Bit
        5-11 Page Address
}}}

こう書くと……

こんな画像に変換するMoinMoinのプラグインを作ってみた。

dformatはpicに変換するawkスクリプト(Bentleyの資料にあるやつ)で、そこからgpicでPostScriptに。またそこからGhostScriptでpngに変換しています。

もちろんpicプラグラインも。

{{{#!pic
.ps -2
		circle "DISK"
		arrow "character" "defns"
CPU:	box "CPU" "(16-bit mini)"
		{ arrow <- from top of CPU up "input " rjust }
		arrow
CRT:	"   CRT" ljust
		line from CRT - 0,0.075 up 0.15 \
				then right 0.5 \
				then right 0.5 up 0.25 \
				then down 0.5+0.15 \
				then left 0.5 up 0.25 \
				then left 0.5
Paper:	CRT + 1.05,0.75
		arrow <- from Paper down 1.5
		" ...  paper" ljust at end of last arrow + 0, 0.25
		circle rad 0.05 at Paper + (-0.055, -0.25)
		circle rad 0.05 at Paper + (0.055, -0.25)
		"   rollers" ljust at Paper + (0.1, -0.25)
.ps +2
}}}

こう書くと……

こんな感じに。