Amazon EBSを使う方法のメモ。

Elasticfox拡張 を使い、 EBSボリュームを作成し、適当なインスタンスにアタッチする。 仮にここでは、/dev/sdhにアタッチしたとする。

その後、ボリュームをアタッチしたインスタンスにSSHでログインし、 以下のコマンドでボリューム上にファイルシステムを構築する。

   1  # yes | mkfs -t ext3 /dev/sdh

続いて、適当なディレクトリを作成し、マウントする

   1  # mkdir /mnt/foo
   2  # mount /dev/sdh /mnt/foo

後は普通に/mnt/fooにアクセスすればOk。

See Also

posted by Png genki on Fri 22 Aug 2008 at 21:46

色々奥が深いと思った(not http://0xcc.net/misc/bad-knowhow.html 笑)

■前提:記事←関連テーブル→ユーザというモデル関係がある。

   1  # has_many :throughのパターン
   2  class Article< ActiveRecord::Base
   3    has_many :articles_users
   4    has_many :users, :through => :articles_users
   5  end
   6  
   7  class User < ActiveRecord::Base
   8    has_many :articles_users, :dependent => :destroy
   9    has_many :articles, :through => :articles_users
  10  end
  11  
  12  # 関連テーブルを実テーブルで持つ
  13  class ArticlesUsers < ActiveRecord::Base
  14    belongs_to :article
  15    belongs_to :user
  16  end

■関連テーブルの操作

あるユーザの関連をごそっと別の関連に切り替えたいような場合!

User.articles_users.destroy_allして作り直すという方法もあるが User.articles_users.replace()という便利なメソッドがある。

AWD第二版(AgileWebDevelopment)で言うとP308。 「○orders.replace(order1,...) この顧客に関連付けられた注文のセットを、新しいセットに置き換える。現在の子のセットと新しいセットの違いを検出し、それに応じてデータベースの変更を最適化する。」という奴。

   1   /ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb
   2  
   3        # Replace this collection with +other_array+
   4        # This will perform a diff and delete/add only records that have changed.
   5        def replace(other_array)
   6          other_array.each { |val| raise_on_type_mismatch(val) }
   7  
   8          load_target
   9          other   = other_array.size < 100 ? other_array : other_array.to_set
  10          current = @target.size < 100 ? @target : @target.to_set
  11  
  12          @owner.transaction do
  13            delete(@target.select { |v| !other.include?(v) })
  14            concat(other_array.select { |v| !current.include?(v) })
  15          end
  16        end
これは便利。

1.配列を放り込むだけ

「Replace this collection with +other_array+」ということで検索結果、あるいはセッションなどで生成した新しい関連の配列を放り込むだけで使える。

2.以前の関連との差分をチェックして差分だけ反映してくれる。

「This will perform a diff and delete/add only records that have changed.」ということで必要な差分だけチェックして必要なdelete/addをしてくれる。

ちなみにdeleteだと「Railsレシピブック」のP157「Entryオブジェクトobjectとの関連を削除する。Entryオブジェクトobjectの外部キー(blog_id)をNULLにし、関連を削除する。複数の参照元オブジェクトを同時に指定できる。」にある通り、関連テーブルの実レコードは削除されない(外部キーがNULLになるだけ)。関連テーブルにごみが残って気持ち悪い場合は上記モデルのように「:dependent => :destroy」を付けると物理的に削除される。

posted by Face ysakaki on Fri 22 Aug 2008 at 15:54

最近全然JavaScriptを書いていなかったので、少し書いてみる。

お題は、どう書く.org - LL Golf Hole 6 - 10進数を2進数に基数変換する です。

ブックマークレットにしてみた。

   1  javascript: n=window.prompt("10進数を入力すると、2進数にしてくれるよ!",  ""); alert(parseInt(n, 10).toString(2));

上のコードをアドレスバーに貼り付ければ実行できます。

コードの内容は、

  1. window.promptで数字を得る。(これは文字列)
  2. parseInt(n, 10)で、さっき得た文字列を数値(10進数)に変換
  3. 得た数値を2進数(文字列)に変換
  4. 表示

文字列を1度、数値に変換しないといけないのが少し気にいらないなぁ。

何かいい方法があるだろうか。

posted by Png y_tsuda on Fri 22 Aug 2008 at 11:41

http://comments.deasil.com/2008/08/18/iphone-ssh-review-issh-v-pterm-v-touchterm/

iSSH(1.0), pTerm(1.1), TouchTerm(2.0)の3つを比較したエントリなのですが、2.0になったばかりのTouchTermが良さそうです。というわけでTouchTermのところをザクっと挙げてみます。ちなみにお値段:$2.99。

TouchTerm2.0

appStoreはここから

カスタマイズ可能な設定

  • フォントサイズ
  • 色:背景
  • 色:テキスト
  • 色:カーソル
  • その他

バッファーmode、immediate sending mode

バッファでまとめて入力してから、サーバコマンドを送るモードがあります。複雑なコマンドを発行したい場合に便利。です。また、immediate sending modeにすることでバッファmode offにもできる。

画面を広くできる

メインスクリーンをタッチすることで、キーボードが非表示になり、全画面がターミナルになる。

画面上部にある固定キー(hard keys bar)

clear, ctrl, tab, esc, arrows, settingsのボタンがあって、1タッチでスクリーンをクリアできる(小さな画面のiPhoneではとても便利!)。

キー管理、認証ができる

キーの生成、publicキーをメールで送ることで、privateキーと連携したコネクションが使えるようになる。

コネクションの設定が保存(サーバ名、ポート、ユーザ名、password(optional)、key(optional))可能。またQuick Connectでは最後の設定を"one-time connection"(one-timeといいつつも先の設定を保存してくれている)として使えるのが便利。

より詳細なTouchTerm2の新機能:pdf

http://www.jbrink.net/touchterm/TouchTerm2.pdf

posted by Png satoko on Fri 22 Aug 2008 at 06:13

EC2でパッケージのRubyではなく、srcからRubyを入れて使う場合、 イメージの状態によってはAMI-toolsがLOAD_PATH不足で正しく起動できない場合がある。

その場合、以下のようにAMI-toolsのスクリプトを書き換える。

/usr/local/bin/ec2-bundle-vol

   1  #!/bin/bash
   2  ruby -I/usr/lib/site_ruby /usr/lib/site_ruby/aes/amiutil/bundlevol.rb $*

-IオプションでLOAD_PATHを補っている。

posted by Png genki on Fri 22 Aug 2008 at 04:17
Contents
Amazon Elastic Block Storeを使う
Railsの多対多で関連テーブルの操作色々
どう書く.org - LL Golf Hole 6 - 10進数を2進数に基数変換する
iPhoneのsshクライアント:iSSH, pTerm, TouchTerm
EC2でsrcからRubyを入れるときのAMI-toolsの修正メモ
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ