2009年8月21日金曜日

QRコードをAS3とかJavaScriptとかで実装したライブラリ

これは便利かも。
AS3JavaScript

virtualboxの仮想HDDをwritethroughにしてみた

VirtualBoxの仮想HDDは3つのモードがある。
GUIでは操作できないみたいだけど、コマンドラインで簡単に変更できる。
  • 普通のモード
  • スナップショットを作成できないモード
  • 再起動するともとに戻るモード
VBoxManage modifyhd --type [normal|writethrough|immutable]

仮想化したときのメリットとして、なんでも試してみて気に入らなければ気軽にロールバックしちゃうなんて使い方がある。
でも、ホームディレクトリなんかはロールバックしちゃったらもったいない状況も多々ある訳で、そんなときにスナップショットを作成できないモードにしておく。writethroughモード。

2009年8月19日水曜日

SELinuxのせいでreadline.soをロード失敗してみた

CentOS 5.2 で ruby-1.8.7-p174 をビルド&インストールした時のこと。
irb -rirb/completionしたら下記のエラー。

/usr/local/lib/ruby/1.8/i686-linux/readline.so: /usr/local/lib/ruby/1.8/i686-linux/readline.so: cannot restore segment prot after reloc: Permission denied - /usr/local/lib/ruby/1.8/i686-linux/readline.so (LoadError)

これはSELinuxの設定が原因。

ls -lZ /usr/local/lib/ruby/1.8/i686-linux/*.so

してみたところ、

-rwxr-xr-x 1 user_u:object_r:lib_t root root 116642 8月 19 17:14 readline.so

とのこと。

chcon system_u:object_r:textrel_shlib_t zlib.so

このコマンドを実行して設定を正しくする。

-rwxr-xr-x 1 system_u:object_r:textrel_shlib_t root root 116642 8月 19 17:14 readline.so

2009年8月7日金曜日

壁のばし方で迷路を作ってみた

maze.rb
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-

require 'rubygems'
require 'win32console'
require 'term/ansicolor'

include Win32::Console::ANSI
include Term::ANSIColor

class Maze
PATHWAY = 1
WALL = 2

attr_accessor :width, :height

def initialize(width, height)
@width = width * 2 + 1
@height = height * 2 + 1
@map = [ PATHWAY ] * @width * @height
@console = Win32::Console.new(STD_OUTPUT_HANDLE)

prologue
dig
epilogue
end

def prologue
@console.Cls
print on_white
dig_edge
end

def epilogue
print reset
@console.Cursor(0, 1)
print ' '
@console.Cursor(@width - 1, @height - 2)
print ' '
@console.Cursor(0, @height + 1)
end

def dig
loop do
w0, w1 = select_next
break unless w0
set_wall(*w0)
set_wall(*w1)
loop do
w0, w1 = candidates(*w1)
break unless w0
set_wall(*w0)
set_wall(*w1)
sleep 0
end
end
end

def select_next
r = walls
loop do
i = rand(r.size)
x, y = r[i]
r.delete_at(i)
z = candidates(x, y)
return z if z
break if r.empty?
end
end

def candidates(x, y)
c = []
f0(c, x + 1, y, x + 2, y)
f0(c, x - 1, y, x - 2, y)
f0(c, x, y + 1, x, y + 2)
f0(c, x, y - 1, x, y - 2)
c[rand(c.size)] unless c.empty?
end

def f0(z, x, y, x1, x2)
if PATHWAY == self[x1, x2]
z << [ [x, y], [x1, x2] ]
end
end

def walls
r = []
0.step(@height - 1, 2) do |y|
0.step(@width - 1, 2) do |x|
r << [x, y] if WALL == self[x, y]
end
end
r
end

def dig_edge
x = @width - 1
@height.times do |y|
set_wall(0, y)
set_wall(x, y)
end

y = @height - 1
@width.times do |x|
set_wall(x, 0)
set_wall(x, y)
end
end

def set_wall(x, y)
@map[x + y * @width] = WALL
@console.Cursor(x, y)
print ' '
end

def [](x, y)
return nil if x < 0 || @width <= x
return nil if y < 0 || @height <= y
@map[x + y * @width]
end
end

m = Maze.new(39, 30)

2009年8月5日水曜日

穴掘り法で迷路を作ってみた

maze.rb
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-

require 'rubygems'
require 'win32console'
require 'term/ansicolor'

include Win32::Console::ANSI
include Term::ANSIColor

class Maze
OUTSIDE = -1
PATHWAY = 0
WALL = 1

def initialize(width, height)
@console = Win32::Console.new(STD_OUTPUT_HANDLE)
@width = width * 2 + 1
@height = height * 2 + 1
@data = [WALL] * @width * @height
draw_bg
dig
finish
end

def finish
@console.Cursor(0, 1)
print ' '
@console.Cursor(@width + 1, @height)
print ' '
@console.Cursor(0, @height + 1)
end

def dig
x = rand(@width / 2) * 2
y = rand(@height / 2) * 2
loop do
dig_path(x, y)
r = select_next(x, y)
break unless r
set_pathway(*r[0])
x, y = r[1]
end
end

def select_next(x, y)
r = walk(x, y)
until r.empty?
i = rand(r.size)
x, y = r[i]
r.delete_at(i)
s = candidates(x, y)
return s[rand(s.size)] unless s.empty?
end
end

def walk(tx, ty, x = nil, y = nil, fx = nil, fy = nil, r = [])
return if fx == tx && fy == ty
return if PATHWAY != self[tx, ty]
r << [tx, ty] if tx % 2 == 0 && ty % 2 == 0
walk(tx + 1, ty, tx, ty, x, y, r)
walk(tx - 1, ty, tx, ty, x, y, r)
walk(tx, ty + 1, tx, ty, x, y, r)
walk(tx, ty - 1, tx, ty, x, y, r)
r
end

def dig_path(x, y)
set_pathway(x, y)
loop do
s = candidates(x, y)
break if s.empty?
s = s[rand(s.size)]
set_pathway(*s[0])
set_pathway(*s[1])
x, y = s[1]
end
end

def candidates(x, y)
r = []
try_dig(x, y, 1, 0, r)
try_dig(x, y, -1, 0, r)
try_dig(x, y, 0, 1, r)
try_dig(x, y, 0, -1, r)
r
end

def try_dig(x, y, dx, dy, r)
x += dx
y += dy
s = x + dx
t = y + dy
if WALL == self[s, t]
r << [[x, y], [s, t]]
end
end

def [](x, y)
return OUTSIDE if x < 0 || @width <= x
return OUTSIDE if y < 0 || @height <= y
@data[x + y * @width]
end

def set_pathway(x, y)
@data[x + y * @width] = PATHWAY
@console.Cursor(x + 1, y + 1)
print ' '
end

def draw_bg
@console.Cls
(@height + 2).times do
print on_white
print ' ' * (@width + 2)
print reset
puts
end
end
end

#Maze.new(38, 30)
Maze.new(10, 10)

PassengerTempDirを設定したほうが幸せ?

Apache + PassengerをCentOS 5.2で稼働させているのだけれど、たまに、落ちる。
Apacheのerror_logには

The spawn server has exited unexpectedly.

とか

Exception Errno::ENOENT in PhusionPassenger::Rack::ApplicationSpawner (No such file or directory ...

と記録されている。

/tmp/passenger.????

を見てみたら・・・あれ?なんだかキレイ・・・

/tmpなのでファイルを消されちゃっても文句は言えないのかも?

ってなわけで、httpd.conf で PassengerTempDir を勝手にいじられるはずがないところに変更してみた。
この設定でしばらく様子を見てみよう。

せっかくなので、PassengerTempDirは、アプリと同じパーティションのディレクトリを指定。
ファイルアップロードでコピーじゃなくてリネームを使えるかも~?

2009年8月4日火曜日

エラーハンドリングフレームワーク

[cppll:13411] エラーハンドリングフレームワーク
便利かな~
最近C++書いてないなぁ

2009年8月2日日曜日

iPhoneアプリ開発に惹かれてる

Macを手にしてからずいぶん時間が経ってるなぁ。
いまさらだけど、iPhoneアプリ開発に興味が出てきた。
エキスパートの前にまずはビギナーから…