macportsのdb46でshell command failed

MacBookAirをクリーンインストールしたあと、
macportsでgit-coreとかpython27とかインストールしようと思ったら
db46がインストールできなくて色々困った

パッと見のログではshell command failedとか言われてなんのことだかサッパリ。
内部を見てくとjni.hがないといわれていた。

$ cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_db46/build_unix
$ sudo /usr/bin/make -j2 all
<省略>
../dist/../libdb_java/db_java_wrap.c:123:17: error: jni.h: No such file or directory

どうやら10.6 update3でAppleJDKヘッダが/System以下のJDKから消えた模様。
Java for Mac OS X 10.6 Update 3 and 10.5 Update 8 Release Notes
L'eclat des jours(2010-10-24)

http://connect.apple.comから「Java for Mac OS X 10.6 Update 3 Developer Package」をいれたらOK。
詳しくは、artonさんの記事へ。

以下はスマートじゃない解決方法。

    • -

/Developer以下にはJDKのヘッダがあるので、/System以下のJDKにリンクを張ったらうまくいった。

$ sudo ln -s /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/.
$ sudo port clean --all db46
--->  Cleaning db46
Warning: Distfiles directory '/opt/local/var/macports/distfiles/db4/4.6.21_6' may contain distfiles needed for other ports, use the -f flag to force removal
$ sudo port install db46
--->  Computing dependencies for db46
--->  Fetching db46
--->  Attempting to fetch db-4.6.21.tar.gz from http://download-uk.oracle.com/berkeley-db/
--->  Verifying checksum(s) for db46
--->  Extracting db46
--->  Applying patches to db46
--->  Configuring db46
--->  Building db46
--->  Staging db46 into destroot
--->  Installing db46 @4.6.21_6
--->  Activating db46 @4.6.21_6
--->  Cleaning db46

もっとスマートなやり方はあるかもしれない。

ちょっとAppleが嫌いになった。

spanやdivやaタグをボタンにするjQuery pluginを書いてみた

jQuery Pluginの書き方 - KAYAC engineers' blog を参考にして、

tttbuttonという、spanやdivやaタグをボタンにするjQuery pluginを書いてみました。

GitHub - junish/tttbutton: Riding button of span or div with jQuery.

しかし、jQuery UIに最近追加されたbuttonプラグインが、aやbuttonやradioやinputをボタンにしてくれるっぽいという罠。

書いたjQuery plugin以上に使いやすげなので非常に萎えました。

・参考
jQuery Pluginの書き方 - KAYAC engineers' blog

simple-build-toolが便利そう

simple-build-toolというツールを簡単に使ってみた。


Google Code Archive - Long-term storage for Google Code Project Hosting.
「Setup」と「Basic Usage」あたりを試してみた。


  • 概要

scalaのビルドツールらしい。
JavaのビルドツールであるMavenscala版という感じ。
プロジェクトに必要なjarの依存関係を解決してくれるのが便利だと思った。
その辺は、Apache Ivyというツールを使っているよう。

  • インストール
# wget http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.4.jar -O /usr/local/bin/sbt-launch-0.7.4.jar
# ln -s /usr/local/bin/sbt-launch-0.7.4.jar /usr/local/bin/sbt-launch.jar
# cat << _EOD_ > /usr/local/bin/sbt
#!/bin/sh
java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"
_EOD_
# chmod u+x /usr/local/bin/sbt
  • 使い方
# sbt help
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
You may execute any project action or method or one of the commands described below.
Available Commands:
   <action name> : Executes the project specified action.
   <method name> <parameter>* : Executes the project specified method.
   <processor label> <arguments> : Runs the specified processor.
   ~ <command> : Executes the project specified action or method whenever source files change.
   < file : Executes the commands in the given file.  Each command should be on its own line.  Empty lines and lines beginning with '#' are ignored
   + <command> : Executes the project specified action or method for all versions of Scala defined in crossScalaVersions.
   ++<version> <command> : Changes the version of Scala building the project and executes the provided command.  <command> is optional.
   * : Prefix for commands for managing processors.  Run '*help' for details.
   ! : Prefix for history commands.  Run '!' for history command help.
   actions : Shows all available actions.
   reload : Reloads sbt, picking up modifications to sbt.version or scala.version and recompiling modified project definitions.
   help : Displays this help message.
   current : Shows the current project, Scala version, and logging level.
   debug, info, warn, error : Set logging for the current project to the specified level.
   trace 'on', 'nosbt', 'off', or <integer> : Configures stack trace logging. 'nosbt' prints stack traces up to the first sbt frame.  An integer gives the number of frames to show per exception.
   project <project name> : Sets the currently active project.
   projects : Shows all available projects.
   exit, quit : Terminates the build.
   set <property> <value> : Sets the value of the property given as its argument.
   get <property> : Gets the value of the property given as its argument.
   console-project : Enters the Scala interpreter with the current project definition bound to the variable 'current' and all members imported.
   builder : Set the current project to be the project definition builder.
   shell : Enters the sbt interactive shell
[info] 
[info] Total session time: 1 s, completed 2010/09/05 0:54:39
[success] Build completed successfully.

# sbt actions
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
        -empty
        clean: Deletes all generated files (the target directory).
        clean-cache: Deletes the cache of artifacts downloaded for automatically managed dependencies.
        clean-lib: Deletes the managed library directory.
        clean-plugins
        compile: Compiles main sources.
        console: Starts the Scala interpreter with the project classes on the classpath.
        console-quick: Starts the Scala interpreter with the project classes on the classpath without running compile first.
        copy-resources: Copies resources to the target directory where they can be included on classpaths.
        copy-test-resources: Copies test resources to the target directory where they can be included on the test classpath.
        deliver
        deliver-local
        doc: Generates API documentation for main Scala source files using scaladoc.
        doc-all: Generates both main and test documentation.
        doc-test: Generates API documentation for test Scala source files using scaladoc.
        exec
        graph-pkg
        graph-src
        increment-version: Increments the micro part of the version (the third number) by one. (This is only valid for versions of the form #.#.#-*)
        javap
        make-pom
        package: Creates a jar file containing main classes and resources.
        package-all: Executes all package tasks except package-project.
        package-docs: Creates a jar file containing generated API documentation.
        package-project: Creates a zip file containing the entire project, excluding generated files.
        package-src: Creates a jar file containing all main source files and resources.
        package-test: Creates a jar file containing test classes and resources.
        package-test-src: Creates a jar file containing all test source files and resources.
        publish
        publish-local
        release: Compiles, tests, generates documentation, packages, and increments the version.
        run: Runs the main class for the project with the provided arguments.
        sh
        test: Runs all tests detected during compilation.
        test-compile: Compiles test sources.
        test-failed: Runs the tests provided as arguments if they have not succeeded.
        test-javap
        test-only: Runs the tests provided as arguments.
        test-quick: Runs the tests provided as arguments if they have not succeeded or their dependencies changed.
        test-run: Runs a test class with a main method with the provided arguments.
        update: Resolves and retrieves automatically managed dependencies.
  • プロジェクト作成
# mkdir hw
# echo 'object Hi { def main(args: Array[String]) { println("Hi!") } }' > hw.scala
# sbt
Project does not exist, create new project? (y/N/s) s
Getting Scala 2.7.7 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
        confs: [default]
        2 artifacts copied, 0 already retrieved (9911kB/77ms)
Getting org.scala-tools.sbt sbt_2.7.7 0.7.4 ...
:: retrieving :: org.scala-tools.sbt#boot-app
        confs: [default]
        15 artifacts copied, 0 already retrieved (4096kB/63ms)
[success] Successfully initialized directory structure.
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
> run
[info]
[info] == compile ==
[info]   Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Compilation successful.
[info]   Post-analysis: 2 classes.
[info] == compile ==
[info]
[info] == copy-resources ==
[info] == copy-resources ==
[info]
[info] == run ==
[info] Running Hi
Hi!
[info] == run ==
[success] Successful.
[info]
[info] Total time: 5 s, completed 2010/09/05 0:19:16
> quit
[info]
[info] Total session time: 135 s, completed 2010/09/05 0:21:12
[success] Build completed successfully.
  • 外部ライブラリのインストール

外部ライブラリはリポジトリに登録されている必要がある。
http://scala-tools.org/repo-releases/

# mkdir project/build
# cat << _EOD_ > project/build/HelloWoldProject.scala
import sbt._

class HelloWorldProject(info: ProjectInfo) extends DefaultProject(info)
{
  val scalatools_release = "Scala Tools Snapshot" at
  "http://scala-tools.org/repo-releases/"

  val liftVersion = "2.0"

  override def libraryDependencies = Set(
    "net.liftweb" % "lift-mapper" % liftVersion % "compile->default",
    "net.liftweb" % "lift-wizard" % liftVersion % "compile->default",
    "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
    "junit" % "junit" % "4.5" % "test->default",
    "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test->default",
    "com.h2database" % "h2" % "1.2.121"
  ) ++ super.libraryDependencies
}
_EOD_
# sbt update
[info] Building project test 1.0 against Scala 2.7.7
[info]    using HelloWorldProject with sbt 0.7.4 and Scala 2.7.7
[info] 
[info] == update ==
[info] :: retrieving :: test#test_2.7.7 [sync]
[info]  confs: [compile, runtime, test, provided, system, optional, sources, javadoc]
[info]  2 artifacts copied, 24 already retrieved (1218kB/79ms)
[info] == update ==
[success] Successful.
[info] 
[info] Total time: 33 s, completed 2010/09/05 2:39:24
[info] 
[info] Total session time: 34 s, completed 2010/09/05 2:39:24
[success] Build completed successfully.

# find lib_managed
lib_managed
lib_managed/scala_2.7.7
lib_managed/scala_2.7.7/test
lib_managed/scala_2.7.7/test/junit-4.5.jar
lib_managed/scala_2.7.7/test/servlet-api-2.5-20081211.jar
lib_managed/scala_2.7.7/test/jetty-util-6.1.22.jar
lib_managed/scala_2.7.7/test/jetty-6.1.22.jar
lib_managed/scala_2.7.7/test/specs-1.6.2.1.jar
lib_managed/scala_2.7.7/compile
lib_managed/scala_2.7.7/compile/h2-1.2.134.jar
lib_managed/scala_2.7.7/compile/lift-webkit-2.0.jar
lib_managed/scala_2.7.7/compile/lift-wizard-2.0.jar
lib_managed/scala_2.7.7/compile/slf4j-api-1.5.11.jar
lib_managed/scala_2.7.7/compile/commons-codec-1.3.jar
lib_managed/scala_2.7.7/compile/paranamer-2.0.jar
lib_managed/scala_2.7.7/compile/lift-common-2.0.jar
lib_managed/scala_2.7.7/compile/lift-actor-2.0.jar
lib_managed/scala_2.7.7/compile/lift-testkit-2.0.jar
lib_managed/scala_2.7.7/compile/activation-1.1.jar
lib_managed/scala_2.7.7/compile/lift-json-2.0.jar
lib_managed/scala_2.7.7/compile/lift-util-2.0.jar
lib_managed/scala_2.7.7/compile/log4j-1.2.14.jar
lib_managed/scala_2.7.7/compile/slf4j-log4j12-1.5.11.jar
lib_managed/scala_2.7.7/compile/mail-1.4.1.jar
lib_managed/scala_2.7.7/compile/lift-mapper-2.0.jar
lib_managed/scala_2.7.7/compile/joda-time-1.6.jar
lib_managed/scala_2.7.7/compile/commons-httpclient-3.1.jar
lib_managed/scala_2.7.7/compile/commons-fileupload-1.2.1.jar
lib_managed/scala_2.7.7/compile/derby-10.5.3.0_1.jar
lib_managed/scala_2.7.7/compile/commons-logging-1.0.4.jar
  • 参考

Google Code Archive - Long-term storage for Google Code Project Hosting.
Lift :: Home

.bashrcメモ

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias em='emacs'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

PS1="[\u@\h \W]# "

if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

function ereg(){
    local _reg=$1
    local _text=$2
    echo "${_text}" | grep -E -q "${_reg}"
    if [ $? -ne 0 ]; then
        return 1
    fi
    return 0
}

function check_ipaddres(){
    local _text=$1

    ereg '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' "${_text}"
    if [ $? -ne 0 ]; then
        return 1
    fi
    return 0
}

function ssh_screen(){
    eval server=\${$#}
    
    check_ipaddres "${server}" 
    if [ $? -eq 0 ]; then
        server=$(echo ${server})
    else
        server=$(echo ${server} | cut -d . -f 1)
    fi
    screen -t ${server} ssh "$@"
}

if [ "$TERM" = "screen" ]; then
  alias ssh=ssh_screen
fi

scalaの勉強会に行ったのでとりあえず、scalaを触ってみた

東京でscalaの勉強会に参加してきました。
http://www.kaigai-engineer.com/blog/?p=59

完全にノリで参加したのですが、
LL Tiger関数型言語がえらく取り上げられていたこともあるし、
勉強会に参加することでscalaをさわってみよう!という取っ掛かりができた。

ということで、チュートリアルでも読んでみる。
英語はわからないので和訳で。
Tutorial和訳 - プログラミング言語 Scala Wiki - アットウィキ

# cat << _EOD_ > HelloWorld.scala
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}
_EOD_
# scalac HelloWorld.scala
# ls
HelloWorld$.class  HelloWorld.class  HelloWorld.scala
# scala -classpath . HelloWorld
Hello, world!
# cat << _EOD_ > JavaAndScala.scala
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._

object FrenchDate {
  def main(args: Array[String]) {
    val now = new Date
    val df = getDateInstance(LONG, Locale.FRANCE)
    println(df format now)
  }
}
_EOD_
# scalac JavaAndScala.scala
# scala -classpath . FrenchDate
2 septembre 2010
# scala
Welcome to Scala version 2.7.7.final (OpenJDK Client VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 
scala> val x = 2
x: Int = 2

scala> 1+2*3/x
res1: Int = 4

scala> (1).+(((2).*(3))./(x))          
res4: Int = 4

scala> 1.+(2)                
res5: Double = 3.0

scala> (1).+(2)
res6: Int = 3
  • 関数
# cat << _EOD_ > FuncIsObject.scala
object Timer {
  def oncePerSecond(callback: () => Unit) {
    while (true) { callback(); Thread sleep 1000 }
  }
  def timeFlies() {
    println("time flies like an arrow...")
  }
  def main(args: Array[String]) {
    oncePerSecond(timeFlies)
  }
}
_EOD_
# scalac FuncIsObject.scala 
# scala -classpath . Timer.class 
error: IO error while decoding /root/work_scala/Timer.class with UTF-8
Please try specifying another one using the -encoding option

TODO:エンコーディング周りでエラー。あとで調べる。
→解決 .classが付いていたw

# scala -classpath . Timer
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
^C
  • 無名関数
# cat << _EOD_ > NoNameFunc.scala
object TimerAnonymous {
  def oncePerSecond(callback: () => Unit) {
    while (true) { callback(); Thread sleep 1000 }
  }
  def main(args: Array[String]) {
    oncePerSecond(() =>
      println("time flies like an arrow..."))
  }
}
_EOD_
# scalac NoNameFunc.scala 
# scala -classpath . TimerAnonymous
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
time flies like an arrow...
^C

今日はここまで!

追記!

  • クラス
# cat Klass.scala 
class Complex(real: Double, imaginary: Double) {
  def re() = real
  def im() = imaginary
}

object ComplexNumbers {
  def main(args: Array[String]) {
    val c = new Complex(1.2, 3.4)
    println("real part: " + c.re())
    println("imaginary part: " + c.im())
  }
}
# scalac Klass.scala 
# scala ComplexNumbers
real part: 1.2
imaginary part: 3.4
  • 引数なしメソッド
# cat NoArgMethod.scala 
class Complex(real: Double, imaginary: Double) {
  def re = real
  def im = imaginary
}

object ComplexNumbers {
  def main(args: Array[String]) {
    val c = new Complex(1.2, 3.4)
    println("real part: " + c.re)
    println("imaginary part: " + c.im)
  }
}
# scalac NoArgMethod.scala 
# scala ComplexNumbers
real part: 1.2
imaginary part: 3.4
  • 継承とオーバーライド
# cat Inheritance.scala 
class Complex(real: Double, imaginary: Double) {
  def re = real
  def im = imaginary
  override def toString() =
    "" + re + (if (im < 0) "-" else "+") + im + "i"
}

object ComplexNumbers {
  def main(args: Array[String]) {
    val c = new Complex(1.2, 3.4)
    println("toString: " + c.toString())
  }
}
# scalac Inheritance.scala 
# scala ComplexNumbers
toString: 1.2+3.4i

今日はここまで!

CentOSでscreenのクリップボードとXのクリップボードを共有する

epelリポジトリからxclipをインストール

# yum --enablerepo=epel -y install xclip

http://d.hatena.ne.jp/Shinnya/20100623/1277279977 を参考に以下を.screnrcに追加。

bindkey -m ' ' eval 'msgwait 0' 'stuff \040' writebuf 'exec !!! xclip /tmp/screen-exchange' 'msgwait 2'
bindkey -m Y eval 'msgwait 0' 'stuff Y' writebuf 'exec !!! xclip /tmp/screen-exchange' 'msgwait 2'
bindkey -m y eval 'msgwait 0' 'stuff y' writebuf 'exec !!! xclip /tmp/screen-exchange' 'msgwait 2'
bindkey -m W eval 'msgwait 0' 'stuff W' writebuf 'exec !!! xclip /tmp/screen-exchange' 'msgwait 2'

.screenrcの再読み込み

Ctrl+<コマンド文字>
:
source ${HOME}/.screenrc
  • 環境
# rpm -q centos-release
centos-release-5-5.el5.centos
# screen -v
Screen version 4.00.03jw4 (FAU) 2-May-06
# xclip -version
xclip version 0.08
Copyright (C) 2001 Kim Saunders
Distributed under the terms of the GNU GPL
  • 参考

http://d.hatena.ne.jp/Shinnya/20100623/1277279977

「インストール済み(ただし未伸張)ファイルが見つかりました」の対処

rpmファイルをビルドするとき、SPECファイルの%filesセクションと、
BUILDディレクトリのファイルに差異があると、以下のようなエラーが出力される。
要は、インストールしたけど、パッケージングしていないファイルがあるよ!、ってこと。

# rpmbuild -bb plugin_pack.spec
<省略>
伸張ファイルの検査中: /usr/lib/rpm/check-files /var/tmp/purple-plugin_pack-2.6.3-0-root-root
エラー: インストール済み(ただし未伸張)ファイルが見つかりました:
   /usr/share/pixmaps/pidgin/protocols/16/napster.png
   /usr/share/pixmaps/pidgin/protocols/22/napster.png
   /usr/share/pixmaps/pidgin/protocols/48/napster.png


RPM ビルドエラー:
    インストール済み(ただし未伸張)ファイルが見つかりました:
   /usr/share/pixmaps/pidgin/protocols/16/napster.png
   /usr/share/pixmaps/pidgin/protocols/22/napster.png
   /usr/share/pixmaps/pidgin/protocols/48/napster.png

以下のチェックコマンドがマクロに定義されているためっぽい。

# rpmbuild --showrc | grep __check
-14: __check_files      /usr/lib/rpm/check-files %{buildroot}

--defineオプションで定義されているマクロを消してあげれば、OK。

# rpmbuild -bb --define="__check_files %{nil}" plugin_pack.spec