2013年10月30日水曜日

Emacsを開くとエラーが発生

Symbol's function definition is void: defun*

というエラーが発生。
emacs開く際に、--debug-initをつけて問題を見ると、rsense(Rubyの補完をしてくれるやつ)を入れた時に問題があったようだ。

rsenseのファイル(何だったか忘れたが、emacsのデバッグモード出て来たファイル)を開いて、defun*でサーチしたら1カ所だけヒット。

ここをコメントアウトして問題解消。


2013年9月10日火曜日

2013年8月24日土曜日

RVMの基本コマンド

こちらのサイト様がとてもよくまとまっていたので。

http://blog.asial.co.jp/371

2013年8月7日水曜日

twitter-bootstrapを入れたときの各GemのVersion

Using rake (10.1.0)
Using i18n (0.6.4)
Using multi_json (1.7.8)
Using activesupport (3.2.8)
Using builder (3.0.4)
Using activemodel (3.2.8)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.3)
Using tilt (1.4.1)
Using sprockets (2.1.3)
Using actionpack (3.2.8)
Using mime-types (1.23)
Using polyglot (0.3.3)
Using treetop (1.4.14)
Using mail (2.4.4)
Using actionmailer (3.2.8)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.8)
Using activeresource (3.2.8)
Installing bootstrap-sass (2.0.3.1)
Using bundler (1.2.3)
Using coffee-script-source (1.6.3)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.3)
Using json (1.8.0)
Using rdoc (3.12.2)
Using thor (0.18.1)
Using railties (3.2.8)
Using coffee-rails (3.2.2)
Using commonjs (0.2.6)
Using jquery-rails (3.0.4)
Using less (2.3.2)
Using less-rails (2.3.3)
Using libv8 (3.3.10.4)
Using rails (3.2.8)
Installing sass (3.2.10)
Installing sass-rails (3.2.6)
Using sqlite3 (1.3.7)
Using therubyracer (0.10.2)
Using twitter-bootstrap-rails (2.2.7)
Using uglifier (2.1.2)


2013年8月6日火曜日

twitter-bootstrapを使う際にはまったこと

libv8がインストールできなかった。
なので、therubyraceも入れられず、はまった。

Gemfileに以下のVersionを指定したらうまくできた。

group :assets do
       gem 'libv8', '~> 3.3.10'
       gem 'therubyracer', '~> 0.10.2'
end

はまったときのログは、以下の感じ。
Installing libv8 (3.16.14.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/ruby-1.9.3-head/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.5.6
Using compiler: /opt/local/bin/g++
g++: error: unrecognized command line option '-Wnewline-eof'


GCCをいれる

$ port search gcc

と打つと、下のようなリストが表示されます。

gcc42 @4.2.4 (lang)
    The GNU compiler collection

gcc43 @4.3.6 (lang)
    The GNU compiler collection

gcc44 @4.4.7 (lang)
    The GNU compiler collection

gcc45 @4.5.4 (lang)
    The GNU compiler collection

gcc46 @4.6.3 (lang)
    The GNU compiler collection

gcc47 @4.7.1 (lang)
    The GNU compiler collection

gcc48 @4.8-20120826 (lang)
    The GNU compiler collection, prerelease BETA

gcc_select @0.1 (sysutils)
    common files for selecting default gcc version

これは抜粋ですが、GCCを入れるだけなら、ここだけ見ればOK。
このリストから、入れたいものを下のようにコマンド打っていれるだけ。

$ sudo port install gcc47

複数のGCCが入っているから、Versionがわかりません
➡ $ sudo port select --list gcc

ActiveのGCCのVersionは?
 $ gcc --version

GCCのVersionってどうやって切り替えるの?
➡ $ sudo port install gcc_select の後に
$ sudo port select gcc mp-gcc4




2013年7月20日土曜日

ESX Serverを利用した仮想環境構築

OSをESX Serverに入れたいとき → ovfファイルを作成後、以下の画像のようにしてデプロイする。



Networkがつながらないとき → DHCPでいったんマシンがどのLAN内に存在するかを確認。

Domainに参加する → LocalDomainのAdministratorでログインしている場合、Passwordが引き継がれる。ログインするときは、参加するDomain名を指定して、Administratorログインすればよい。

WindowsServer2012で.NET3.Xを入れたい → WindowsUpdateで入れる。WindowsUpdateで入れられない場合は、InstallCDが必要。

WindowsUpdateがつながらない → Proxyを確認

MSSQL20XXがInstallできない → OSにServicePackが充ててあるか確認

2013年7月19日金曜日

WindowsServer2012でテスト環境としてActiveDirectoryを簡易構築

WindowsServer2012でクラスタ環境を構築し、検証をする必要がでてきた。
クラスタ環境を構築するためには、ActiveDirectoryを入れる必要がある。

WindowsServer2012は、2008R2などと同様にしてADを追加できる。

手順は、ServerManagementからAdd roles and featuresでADを選択するだけ。

1つ注意すべきは、テスト環境として構築するためには、ADを入れているサーバを
ドメインコントローラーにする必要がある。
このサーバをドメインコントローラーにするには、Add roles and features時に、
ダイアログ操作をするが、そのダイアログ内からリンクでとべ、
ドメインコントローラーの設定が可能だ。

また、ADを入れていると、MSSQL2012をインストールすることは出来たが、
ログインすることができなかった。

調査した所、動作はするとのことだが、推奨しない、とのこと。

2013年6月29日土曜日

RailsのDatabase確認

RailsプロジェクトのRootで
rake dbconsole

もしくは、同じディレクトリで、
sqlite3を使用しているなら、
sqlite3 'DatabaseのPath'

ちなみに、DatabaseのPathは、
config/database.yml

に書いてあります。

2013年6月3日月曜日

複数メソッドに跨ったトランザクション処理

SpringのTransactionを利用せずに、自分でTransactionを制御したい。
SpringのTransactionは、1メソッド内で完結する必要があるが、私がやりたいことは、複数メソッドにまたがってTransactionを維持したいのである。

それをするには、Transactionを持ち回わらなければいけない。
Hibernateでは、EntityManagerからTransactionを取得することが禁止されているようであるが、それを取得するメソッドが公開されている。恐らく設定なのだろう。

java.sql.Connectionクラスを使って、おとなしくDBからデータ取得して、Mapにでも詰めるのがベターなのだろうか。

しかし、私が取得したいデータは複数にまたがっているので、データ取得時に、JOINしないとダメかな。

取りあえず、単純にDBからQuery発行して直接データ取得した後、Objectにデータ詰めたいですって人には、以下のURLが参考になると思います。

http://www.codeproject.com/Tips/372152/Mapping-JDBC-ResultSet-to-Object-using-Annotations

2013年5月31日金曜日

[ Hibernate ] ORDER BYの結果を上から10件取得する

PureJavaで、ORDER BYでソートした後、その結果を、先頭から10件ずつデータを取得したかったので、FROM句以下でサブクエリを作った。

SELECT * FROM (SELECT * FROM table ORDER BY table.date ASC) WHERE ROWNUM <= 10

これを、EntityManagerから、createQuery( query )をCallしてSQLを実行するも失敗。

↓の仕様をみると、


HQL 副問い合わせは、 select または where 節だけで使われることに注意してください。

FROM句で使えないので、はまりました。

で、解決策は、PureJavaのjavax.persistence.QueryのsetMaxResults()を使って引数に10を入れれば、ソート後の結果から10件取得できました。

2013年5月14日火曜日

hamlの準備

rails generate した後に、hamlを使うようにする準備
1.Gemfileに以下の1行を記載
    gem 'haml-rails'
2.bundle install

hamlの準備をしていない時のErrorには、hamlを取り扱えるよ!、という記載がないが、hamlの準備をしたら、取り扱えるようになっていた!


ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):



ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):


あと、MissingTemplateがでる理由だが、ルーティングを間違えていた。

/app/views/コントローラー名/アクション名.html.haml

ex)
/app/views/hello/view.html.haml
の場合、URLは以下のようになる。
http://localhost:3000/hello/view

ちなみに、アクション名は、コントローラでは以下の色付きのところ。

-------


# codinf: utf-8

class HelloController < ApplicationController
  def view
    @msg = 'Hello World from view'
  end
end

2013年1月2日水曜日

herokuでsqlite3からpostgresqlへ

sqlite3 -> postgresql にDBを変更する時のログ。

$ heroku rake db:migrate</ br> ! For Cedar apps, use: `heroku run rake db:migrate` $ heroku run rake db:migrate</ br> Running rake db:migrate attached to terminal... up, run.5672 DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from at /app/Rakefile:9) DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from at /app/Rakefile:9) Connecting to database specified by DATABASE_URL Migrating to CreateMessages (20121222150925) == CreateMessages: migrating ================================================= -- create_table(:messages) NOTICE: CREATE TABLE will create implicit sequence "messages_id_seq" for serial column "messages.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "messages_pkey" for table "messages" -> 0.0589s == CreateMessages: migrated (0.0590s) ========================================

2013年1月1日火曜日

Gemfileを修正したらbundle install

しないと、以下の様なErrorが出て、herokuにpushできない。


git push heroku master
Counting objects: 91, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (81/81), done.
Writing objects: 100% (91/91), 30.37 KiB, done.
Total 91 (delta 5), reused 0 (delta 0)
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.3.0.pre.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       You are trying to install in deployment mode after changing
       your Gemfile. Run `bundle install` elsewhere and add the
       updated Gemfile.lock to version control.
       You have added to the Gemfile:
       * sqlite3
       * thin
       * pg
 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

To git@heroku.com:xxxxxxxxxxxxxxxxxxx.git
 ! [remote rejected] master -> master (pre-receive hook declined)