2014/07/03

HEROKUで無料でROOTドメイン運用する

お名前.com + herokuでルートドメイン運用をしていたのですが、HerokuのアップデートによってAレコードの使用ができなくなります。今後はCNAMEを利用することになります。

お名前.comはルートドメイン(ネイキッドドメイン)のCNAMEに対応していないため、これまでルートドメインで運用して場合は困ることになります。

そこでdozensというサービスを使うと解決できます。設定は5分くらいで完了します。

(1)dozensに会員登録

(2)dozensにてドメイン登録、ルートドメインのCNAME設定をする

(3)お名前.com のネームサーバーを下記にする
ns1.dzndns.com
ns2.dzndns.com
ns3.dzndns.com
ns4.dzndns.com

(4)設定反映を待つ

こんな感じです。

dozensこちらからドメイン設定をしてもらえると、無料で登録できる枠が(お互いに)増えます。どうぞよろしくお願いします!

2013/01/31

ffmpegをmacにhomebrewでインストール

ffmpegをmacにhomebrewでインストールしようとしたところ、サーバーが落ちていたので依存関係にあるtexi2htmlをダウンロードできなかった。その場合の臨時対応としてbrewのダウンロード先をミラーに変更する。

/usr/local/Library/Formula/texi2html.rbを編集

require 'formula'                                                                                  

class Texi2html < Formula
  homepage 'http://www.nongnu.org/texi2html/'
  #url 'http://download.savannah.gnu.org/releases/texi2html/texi2html-1.82.tar.gz'
  url 'http://download-mirror.savannah.gnu.org/releases/texi2html/texi2html-1.82.tar.gz'
  sha1 'e7bbe1197147566250abd5c456b94c8e37e0a81f'

  keg_only :provided_pre_mountain_lion

  def install
    system "./configure", "--disable-dependency-tracking", "--prefix=#{prefix}",
                          "--mandir=#{man}", "--infodir=#{info}"
    system "make install"
  end 

  def test
    system "#{bin}/texi2html", "--help"
  end 
end

2013/01/21

railsで日本語を含まないコメントのバリデーション

gem 'moji'
validates_format_of :body,
  :with => Moji.regexp(Moji::ZEN_ALNUM | Moji::ZEN_KANA | Moji::ZEN_KANJI)

rails consoleで全部delete

User.delete @users.map { |u| u.id }

rails consoleでpryを使う方法

config/initializers/pry.rbに下記を記載
begin
  require 'pry'
  module Rails
    class Console
      class IRB
        def self.start
          Pry.start
        end
      end
    end
  end
rescue LoadError => e
  puts e
end

https://github.com/rweng/pry-railsを使えばいいっぽいけど


あとRails4からは下記のようにすれば使えばいいっぽい config/application.rb
# also need to add pry to Gemfile
console do
  require "pry"
  config.console = Pry
end

2012/10/23

ボタンの二度押し防止

onclick="this.disabled=true;return true;" 
HTMLに上記のような感じでonclickを追加して、あとはjqueryで下記のような感じに
 
$("form").submit(function() {
  $(":submit", this).attr("disabled", "disabled");
});

powとrvmの同居環境

バージョンが上がってpowがrvmrcを読まなくなったのでこんな感じで修正。
.powrcに記入
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then
  source "$rvm_path/scripts/rvm"
  source ".rvmrc"
fi

railsの複合カラムのユニーク制限

validates_uniqueness_of :hoge_id, :scope => :huga_id
って感じ余裕。

Postfixでalias設定

複数の宛先を一つのアドレスで取得するために設定
main.cf
alias_maps = hash:/etc/aliases,regexp:/etc/postfix/aliases.reg 

/etc/postfix/aliases.regで正規表現でマッチさせればOK。(ユーザー名がhoge)
/^[0-9a-z\-]+(@.*)?$/ hoge 

Rackでリダイレクト

   config.gem 'rack-rewrite'
    require 'rack/rewrite'
    config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
      if ENV['RACK_ENV'] == 'production'
       # use Rack::Rewrite do
          r301 %r{.*}, 'http://hoge.com$&', :if => Proc.new {|rack_env|
            rack_env['SERVER_NAME'] != 'hoge.com'
          }
       # end
      end
    end
config/application.rbに上記のような感じで書くとRailsのRackでリダイレクト設定ができます。Herokuを使っていると便利。

ruby on railsでgoogle analyticsのコードを本番だけで挿入

<%= render :partial => ‘layouts/ga’ if RAILS_ENV == ‘production’ %>
こんな感じでレイアウトに記入。パーシャルはapp/views/llayouts/_ga.html.erbみたいな感じでOK。

cakephpでGoogle Analyticsを本番環境だけで挿入

<?php
if (Configure::read('debug') == 0){
  echo $this->element('analytics');
}
?>

こんな感じでレイアウトに記入 実際のアナリティクスのコードはapp/views/elements/analytics.ctpに書く

cakephpのヘルパーで日付拡張

  function dateFormat($date,$format = 'Y年m月d日') {
    return date($format,strtotime($date));
  }
  function df($date,$format = 'Y年m月d日') {
    return $this->dateFormat($date,$format);
  }
  function dfh($date,$format = 'Y年m月d日 H時') {
    return $this->dateFormat($date,$format);
  }
  function dfhm($date,$format = 'Y年m月d日 H時i分') {
    return $this->dateFormat($date,$format);
  }
  function dfwy($date,$format = 'm月d日') {
    return $this->dateFormat($date,$format);
  }
  function dfwyhm($date,$format = 'm月d日 H時i分') {
    return $this->dateFormat($date,$format);
  }


app/views/helper/html.php

 こんな感じで拡張してあげると便利

2012/07/10

CakePHPのモデルキャッシュ

新しくカラムを追加した場合、本番環境でのみ更新されないということがある。debug=0では999日間モデルキャッシュが効いてるので削除してあげましょうというお話。

http://pplace.jp/2011/06/158/

2012/07/09

CakePHPでQdmailを使う場合の修正

エラー文

Fatal error: Call to undefined method View::renderElement() in /***/app/controllers/components/qdmail.php on line 3823

エラー分の該当箇所を下記に修正



$content = $view->element( $this->view_dir . DS . $type . DS . $this->template , 
  array('content' => $content ) , true );



http://www.msng.info/archives/2011/01/using-qdmail-component-on-cakephp-1-3.php

JqueryのCDNが落ちてた場合の対処法

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>!window.jQuery && document.write('<script src="/サーバーURL/jquery.js"><\/script>')</script>


こんな感じで対処できる

iOSでデフォルトで動いてるプロセスリスト

Launchd: takes over many tasks from cron, xinetd, mach_init, and init, which are UNIX programs that traditionally have handled system initialization, called systems scripts, run startup items, and generally prepared the system for the user. (do not close)
TQServer: Net Long Company PC Suit daemon (recommend not to close it)
BTServer: Bluetooth Service (BlueTooth) (in my environment with the dock, turn it off iphone not responding)
CommCenter: Communications Center (phone system) (do not close)
configd: to automatically configure and maintain the network (do not close)
cron: regularly scheduled command or script execution (alarm clock might use it, recommend not to close it)
mDNSResponder: Multicast-DNS Responder daemon. (Do not turn off)
lockdownd: so that iPhone can use other SIM card (do not close)
ptpd: the process of connecting itunes (do not close)
fitx: WeFIT Input Method (not recommended to be closed)
mediaserverd: (system sounds) (do not close)
notifyd: inter-process communication (do not close)
SpringBoard: Springboard is no better explanation in English, if you used the installer or ibrickr install a third-party software, you will find the middle of the screen there is a circular symbol loader, and then immediately return to the standby screen iPhone , then this is a Springboard restart the process (do not close)
MobilePhone: I need not explain this right (do not close)
sshd: ssh daemon (you can close it)
crashreporterd: test application crashes the daemon. (Recommend to close)
dock: dock the software process (you decide to use or not)
iapd: ipod is the iphone and other Apple products using a communication protocol, the purpose is to allow other third-party devices such as communication equipment and iphone. (Recommended closure)
syslogd: recording system error logs and status messages (recommend to close)
: time to refresh the file system cache to prevent data loss caused by system crash (recommend to close). If you want to manually sync the file system cache, in text mode (ssh to connect to the iphone), implementation of the sync command.

VirtualBoxのCentOSでCPU使用率が上がる問題

/etc/grub.conf を下記のように編集


title CentOS (2.6.18-194.3.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.3.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet divider=10
        initrd /initrd-2.6.18-194.3.1.el5.img


http://digitalbox.jp/happy-go-lucky-computing/centos/howto-decrease-cpu-utilization-of-centos-on-virtualbox/

CakePHP1.3.10のテストのエラー対応


# /cake/tests/lib/reporter/cake_html_reporter.php
function CakeHtmlReporter($charset = 'utf-8', $params = array()) {
-    $params = array_map(array($this, '_htmlEntities'), $params);
-    $this->CakeBaseReporter($charset, $params);
+    $this->CakeBaseReporter($charset, $params);
+    $params = array_map(array($this, '_htmlEntities'), $params);
}


1.3.7では修正されたみたいだけど1.3.10ではまた戻っていたので対応

http://blog.longkey1.net/archive/931

Apacheがログローテートのときに落ちる問題

restartをreloadに変更して対処


vi /etc/logrotate.d/httpd/var/log/httpd/*log
{
 missingok
 notifempty
 sharedscripts
 postrotate
  #/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
  /sbin/service httpd reload > /dev/null 2>/dev/null || true
 endscript
}

http://life1204.blogspot.jp/2008/11/httpdlogrotatehttpd.html