牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

2013-03-01から1ヶ月間の記事一覧

Rails3でwhereとかした時に日本時間でなくUTCになる場合のメモ

(rails3.2.12) 問題 明日の 00:00:00 より前のdbを取得したい (2013-03-29 00:00:00 を希望) irb> Time.now => 2013-03-28 11:26:42 +0900 irb> User.where('hoge_at < ?', Time.now.tomorrow.beginning_of_day) User Load (0.7ms) SELECT `users`.* FROM …

SICP 1.2 Procedures and the Processes They Generate

SICP 1.2 Procedures and the Processes They Generate - Exercise 1.10 (define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A (- x 1) (A x (- y 1)))))) (A 1 10) (A (- 1 1) (A 1 (- 10 1))) (A 0 (A 1 9)) (A 0 (A (- 1 1) (A 1 (…

Rails3 で日付を「ago」と「since」で取得するメモ

(rails3.2.12) irb(main):025:0> 1.day.ago => Wed, 20 Mar 2013 10:13:00 JST +09:00 irb(main):028:0> 7.days.since => Thu, 28 Mar 2013 10:13:22 JST +09:00 irb(main):029:0> 2.weeks.ago => Thu, 07 Mar 2013 10:13:31 JST +09:00 irb(main):030:0> 3.…

Rails3 で今日の「00:00:00」とか「23:59:59」とか取りたい時のメモ

(rails3.2.12) irb(main):021:0> Date.today.midnight => Thu, 21 Mar 2013 00:00:00 JST +09:00 irb(main):022:0> Date.today.end_of_day => Thu, 21 Mar 2013 23:59:59 JST +09:00 irb(main):023:0> Time.now.midnight => 2013-03-21 00:00:00 +0900 irb(m…

Rails3 で URLが『hoge.com/〜』の時に『www.hoge.com/〜』にリダイレクトする場合のメモ

(Rails3.2.12) config/routes.rb Redirect www Subdomain to Your Apex Domain Using the Rails Router | Big Nerd Ranch Blog constraints(host: /^(?!www\.)/i) do match '(*any)' => redirect { |params, request| URI.parse(request.url).tap { |uri| ur…

Rails3 で link_to に『:protocol => 'https://'』とかする場合のメモ

問題 link_to に『:protocol => 'https://'』しても、本番環境でhttpsにならない <%= link_to 'クリック', hoge_path, :protocol => 'https://' %> 解決 『:only_path => false』オプションが無いとprotocolが削除されるらしい Railsのlink_toメソッドでhttp…

Rails3 で一部のページのみhttpsにしたいのに、httpsからhttpに戻らない場合のメモ

(Rails3.2.12) 問題 一度httpsのページを表示すると、他のページ移ってもにhttpに戻らない。 解決策 例:hoges_controller の表示をhttpにリダイレクト app/view/controllers/application_controller.rb def redirect_to_http_from_https redirect_to :only_…

Rails3 のビューでテーブルの題名クリックするとソートするメモ

(Rails3.2.12) プロジェクト作成 rails new sortable_table -T cd new sortable_table rails g scaffold Product name price:decimal released:date rake db:migrate 確認用初期データ投入 db/seeds.rb Product.delete_all Product.create(name: "Katsuo", p…

helper_method のメモ

コントローラのメソッドをビューから(ヘルパーも?)呼びたい時に使う for example #228 Sortable Table Columns - RailsCasts app/controllers/products_controller.rb class ProductsController < ApplicationController helper_method :sort_column, :so…

Rails3 の Devise で Registration の編集後のリダイレクト先を変更するメモ

(Rails3.2.12)ファイル作成して下記のようにするapp/controllers/registrations_controller.rb class RegistrationsController < Devise::RegistrationsController protected def after_update_path_for(resource) hoge_path end end

Rails3 で true, false, nil の混じったブーリアン値を whereで検索するのに若干ハマったのでメモ

問題 ブーリアン値 hoge が ture 以外を検索したい DBの状態 dbにカラム foobar で nil x5、false x1、true、x0。 true以外が計6コ。 User.where(:foobar => nil).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` IS NULL => 5 User.whe…

Rails3 で「DEPRECATION WARNING: Passing the format in the template name is deprecated. Please pass render with :formats => [:html] instead.〜」などとエラー出た場合のメモ

(Rails3.2.12) 原因 Passing the format in the template name is deprecated. Please pass render with :formats =&gt; [:html] instead. - donghai821の日記 render に拡張子つけてるのが原因らしい format.html { render :file => "#{Rails.root}/public/…

Rails3 でサーバ起動させると「Errno::EIO: Input/output error 〜 」とかなる場合のメモ

(Rails3.2.12) 症状 rails s してブラウザで表示しようとすると「Errno::EIO: Input/output error 〜 」とエラーが無限ループになる。 処置 原因不明。 PCを再起動したら直った。 New Rails App dies with Errno::EIO at / - Stack Overflow

Rails3 でモデルの scope の書き方でエラー出たメモ

rake db:migrate:reset したらエラーでた。 bundle exec rake db:migrate:reset rake aborted! Mysql2::Error: Table 'hoge_development.users' doesn't exist: SHOW FULL FIELDS FROM `users` rails_app_path/app/models/user.rb:73:in `<class:User>' :エラー出てる行</class:user>…

CentOS で Apache と mod_ssl のバージョンを確認するメモ

$ httpd -v Server version: Apache/2.2.15 (Unix) Server built: Feb 13 2012 22:31:42 $ rpm -aq | grep mod_ssl mod_ssl-2.2.15-15.el6.centos.1.x86_64

Rails3 の whenever で「/usr/bin/env: ruby: No such file or directory」とかなった場合のメモ

(Rails3.2.12) javan/whenever · GitHub 原因 /usr/bin/env ruby で sudo つけるとパス見つけられなくなる。 $ /usr/bin/env ruby -v ruby 1.9.3p385 $ sudo /usr/bin/env ruby -v /usr/bin/env: ruby: No such file or directory rubyインストールしてある…

CentOS + Postfix + Dovecot で、なぜか root がメールを受信してしまう場合のメモ

(CentOS6.3, Postfix2.6.6, Dovecot?) 症状 たとえば info@hoge.com 宛にメールを送信したのに、 root@hoge.com が受信してしまう。 原因 root にエイリアス貼られてる cat /etc/aliases # # Aliases in this file will NOT be expanded in the header from …