2012年11月6日火曜日

Raspberry Pi で OpenOffice を使う

・sudo apt-get update
・sudo apt-get install openoffice.org
--> パッケージが見つからず、エラー

後日再挑戦。

・sudo apt-get install openoffice.org
 → LibreOffice が導入された。


Raspberry Pi を日本語化する

http://d.hatena.ne.jp/a_halka/20120805/1344100384

(1) フォントを導入

日本語フォントのインストール
・sudo apt-get install ttf-takao-mincho
・sudo apt-get install ttf-takao


(2) ロケールの変更(※後回し)
・apt-get install locales
・dpkg-reconfigure locales
  ja_JPが先頭につくEUCJPとUTF-8の2つのうちから好きなものをインストール
※boot直後のコンソールも日本語表示になるが、フォントがないためか文字化けしてしまう


(3) インプットメソッド

・sudo apt-get install ibus-anthy
・reboot
・startx
・iBus Preferences で、Input Method として、Anthyを追加
・[半角/全角]キーで入力切り替え(ctrl+spaceでも)


(4) その他
・sudo apt-get install nkf
・利用例)nkf -S -w sjis.txt > utf8.txt


Raspberry Pi で svn を使う

・apt-get install subversion
 ※パッケージ名はsvnではなかった。

Raspberry Pi で Wifiを使う

最新版(10/28)のraspbianでは、特に追加パッケージなし。
GUI上の WiFi Config で設定すれば、OK

2012年11月1日木曜日

Raspberry Pi でBluetoothを使う

http://blog.livedoor.jp/whatson/archives/4267598.html

(1) Bluetoothドングルを認識させる
・lsusb で、bluetoothドングルが認識されていることを確認。

  Bus 001 Device 005: ID 0a5c:200a Broadcom Corp. BCM2035 Bluetooth dongle

・apt-get install bluetooth で必要なパッケージをインストール
・デーモンの起動を確認 /etc/init.d/bluetooth status
  [ ok ] bluetooth is running.
・hcitool dev で、デバイス(bluetooth ドングルの状況を確認)
  Devices:
          hci0    00:A0:B0:E0:0E:XX
   ※アドレスが表示されなければ、きちんと動作していない

(2) デバイス(キーボード)を認識させる
・デバイス(キーボード)を検出可能なモードに設定
・hcitool scan でスキャン
  Scanning ...
          DC:2C:26:D8:A5:XX   Macro Keyboard
→うまく認識しないので挫折。

(3) GUIツールを導入
・apt-get install bluez-utils blueman
・reboot
・startx
・Bluetooth Manager で接続

※Nintendo Wireless Keyborad は、毎回Fnを押しながら電源を入れる必要がある




Raspberry Pi に raspbian をインストール

(1) ここからダウンロード。
http://www.raspberrypi.org/downloads

現在の最新は、2012-10-28-wheezy-raspbian.zip 。


(2) SDカードにコピー
今回はMac OS Xを利用。 http://www.mztn.org/rpi/rpi02.html

・SDカードをFATでフォーマット
・df -h でボリュームを確認
 /dev/disk2s1                       7.5Gi  988Ki  7.5Gi     1%        0        0  100%   /Volumes/RASPBIAN
・SDカードをアンマウント
 diskutil unmount /dev/disk2s1
・SDカードにコピー(rawでバイスである、/dev/rdisk2を利用)
 sudo time dd bs=1m if=/Users/ora/Downloads/2012-10-28-wheezy-raspbian.img of=/dev/rdisk2
 数十秒後、
 Password:
 1850+0 records in
 1850+0 records out
 1939865600 bytes transferred in 123.454810 secs (15713163 bytes/sec)
     123.46 real         0.00 user         1.37 sys
・df -h でマウント状況を確認
 /dev/disk2s1                        56Mi   17Mi   39Mi    30%      512        0  100%   /Volumes/Untitled
・アンマウント
 diskutil unmount /dev/disk2s1

(3) Raspberry Piにさして起動
・設定画面でいろいろ設定。sudo raspi-config で、後でもできる。
・再起動
※デフォルトのユーザは、Username: pi Password: raspberry
※ root のパスワードはなし?


(4) アップデート
・sudo passwd root で、rootのパスワードを変更
・有線ネットワークを接続
・sudo dhclient -r  で、dhcpアドレスを再取得
・sudo apt-get update
・sudo apt-get upgrade
・reboot でリブート



2012年10月12日金曜日

Windows, Ruby, Sinatra (3)

sinatra で MVC

sinatraとModel

Modelは好きなものを組み合わせる
  • ActiveRecord (railsとは独立して使える)
  • Data Mapper (より抽象度が高い)
  • Sequel (より抽象度が低くシンプル)
  • sinatraのシンプルさと相性が良さそう

インストール
  • gem install seque

 ModelとRDB

 Modelを格納するには、適切なRDBが必要
  • PostgreSQL
  • MySQL
  • SQLite3 → 今回は、シンプルなこれを使う

インストール
  • ダウンロード、解凍
  • http://www.sqlite.org/
  • http://www.sqlite.org/sqlite-dll-win32-x86-3071401.zip
  • dll, def → C:\Ruby193\bin に移動

rubyから使えるように
  • gem install sqlite3

 sinatraとView

Modelは好きなものを組み合わせる
  • Erb (rails とは独立して使える)
  • Erubis (PHP, Java, JS, C, Perl, Schemaに対応)
  • Builder (rubyのメソッドを使う)
  • Haml (インデントでタグを表現。yaml的) → 今回はこれを使ってみる

インストール
  • gem install haml

 サンプル:gestbook.rb

require 'rubygems'
require 'sinatra'
require 'sequel'
require 'haml'

Sequel::Model.plugin(:schema)
Sequel.connect('sqlite://guestbook.db')

class Comments < Sequel::Model
 unless table_exists?
   set_schema do
     primary_key :id
     string :name
     string :comment
     timestamp :created_at
   end
   create_table
 end
end

get '/' do
 @comments = Comments.order_by(:created_at.desc)
 haml :index
end

post '/post_comment' do
 Comments.create({
   :name => request[:name],
   :comment => request[:comment],
   :created_at => Time.now,
 })
 redirect '/'
end

__END__

@@ index
%html
 %title Guestbook
 %body
  %h2 Guestbook
  %form{:name => 'post_comment', :action => '/post_comment', :method => 'post'}
   %label{:for => 'name'} Name:
   %input{:type => 'text', :name => 'name', :size => '20' }
   %label{:for => 'comment'} Comment:
   %input{:type => 'text', :name => 'comment', :size => '50'}
   %input{:type => 'submit', :value => 'post' }

  - @comments.each do |comment|
   %div
    %span&== [#{comment.name}]
    %span&== (#{comment.created_at}):
    %span&= comment.comment