tag:blogger.com,1999:blog-35612970578321058812024-03-08T14:39:45.515+09:00私的開発備忘録geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.comBlogger108125tag:blogger.com,1999:blog-3561297057832105881.post-72216508025866273662014-07-03T11:08:00.003+09:002014-07-03T11:13:50.343+09:00HEROKUで無料でROOTドメイン運用するお名前.com + herokuでルートドメイン運用をしていたのですが、HerokuのアップデートによってAレコードの使用ができなくなります。今後はCNAMEを利用することになります。<br />
<br />
お名前.comはルートドメイン(ネイキッドドメイン)のCNAMEに対応していないため、これまでルートドメインで運用して場合は困ることになります。<br />
<br />
そこで<a href="http://dozens.jp/i/uYuuhq">dozens</a>というサービスを使うと解決できます。設定は5分くらいで完了します。<br />
<br />
(1)<a href="http://dozens.jp/i/uYuuhq">dozens</a>に会員登録<br />
<br />
(2)<a href="http://dozens.jp/i/uYuuhq">dozens</a>にてドメイン登録、ルートドメインのCNAME設定をする<br />
<br />
(3)お名前.com のネームサーバーを下記にする<br />
ns1.dzndns.com<br />
ns2.dzndns.com<br />
ns3.dzndns.com<br />
ns4.dzndns.com<br />
<br />
(4)設定反映を待つ<br />
<br />
こんな感じです。<br />
<div>
<br /></div>
<div>
<a href="http://dozens.jp/i/uYuuhq">dozens</a>こちらからドメイン設定をしてもらえると、無料で登録できる枠が(お互いに)増えます。どうぞよろしくお願いします!</div>
geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-80888468086114350902013-01-31T19:22:00.001+09:002013-01-31T19:23:25.587+09:00ffmpegをmacにhomebrewでインストールffmpegをmacにhomebrewでインストールしようとしたところ、サーバーが落ちていたので依存関係にあるtexi2htmlをダウンロードできなかった。その場合の臨時対応としてbrewのダウンロード先をミラーに変更する。<br />
<br />
/usr/local/Library/Formula/texi2html.rbを編集<br />
<br />
<pre class="brush:ruby">
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
</pre>
<br />geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com2tag:blogger.com,1999:blog-3561297057832105881.post-38054293871356708092013-01-21T03:39:00.000+09:002013-01-21T03:39:39.648+09:00railsで日本語を含まないコメントのバリデーション<pre class="brush:ruby">
gem 'moji'
</pre>
<pre class="brush:ruby">
validates_format_of :body,
:with => Moji.regexp(Moji::ZEN_ALNUM | Moji::ZEN_KANA | Moji::ZEN_KANJI)
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-25084755615310809652013-01-21T03:37:00.002+09:002013-01-21T03:37:55.576+09:00rails consoleで全部delete<pre class="brush:ruby">
User.delete @users.map { |u| u.id }
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-45976908324398351662013-01-21T03:35:00.001+09:002013-01-21T03:45:00.276+09:00rails consoleでpryを使う方法config/initializers/pry.rbに下記を記載
<br />
<pre class="brush:ruby">begin
require 'pry'
module Rails
class Console
class IRB
def self.start
Pry.start
end
end
end
end
rescue LoadError => e
puts e
end
</pre>
<br />
<a href="https://github.com/rweng/pry-rails">https://github.com/rweng/pry-rails</a>を使えばいいっぽいけど<br />
<br />
<br />
あとRails4からは下記のようにすれば使えばいいっぽい
config/application.rb<br />
<pre class="brush:ruby"># also need to add pry to Gemfile
console do
require "pry"
config.console = Pry
end
</pre>
geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-29458351786168935442012-10-23T15:08:00.000+09:002013-01-21T03:08:50.904+09:00ボタンの二度押し防止<pre class="brush:javascript">
onclick="this.disabled=true;return true;"
</pre>
HTMLに上記のような感じでonclickを追加して、あとはjqueryで下記のような感じに
<br />
<pre class="brush:javascript">
$("form").submit(function() {
$(":submit", this).attr("disabled", "disabled");
});
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-60554740064524258032012-10-23T15:05:00.000+09:002013-01-21T03:05:12.884+09:00powとrvmの同居環境バージョンが上がってpowがrvmrcを読まなくなったのでこんな感じで修正。<br />
.powrcに記入
<pre class="brush:bash">
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then
source "$rvm_path/scripts/rvm"
source ".rvmrc"
fi
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-37818448961003451842012-10-23T15:03:00.000+09:002013-01-21T03:25:04.616+09:00railsの複合カラムのユニーク制限<pre class="brush:ruby">
validates_uniqueness_of :hoge_id, :scope => :huga_id
</pre>
って感じ余裕。geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-38901674309486331882012-10-23T14:57:00.002+09:002013-01-21T03:06:50.780+09:00Postfixでalias設定複数の宛先を一つのアドレスで取得するために設定<br />
<span style="background-color: white; color: #333333; font-family: 'MS Pゴシック', 'MS PGothic', Osaka, 'ヒラギノ角ゴ Pro W3'; font-size: 14px; line-height: 25px;">main.cf</span><br />
<pre class="brush:bash">
alias_maps = hash:/etc/aliases,regexp:/etc/postfix/aliases.reg
</pre>
<br />
/etc/postfix/aliases.regで正規表現でマッチさせればOK。(ユーザー名がhoge)
<br />
<pre class="brush:bash">
/^[0-9a-z\-]+(@.*)?$/ hoge
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-49844715852073713892012-10-23T14:52:00.001+09:002013-01-21T03:07:38.252+09:00Rackでリダイレクト<pre class="brush:ruby">
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
</pre>
config/application.rbに上記のような感じで書くとRailsのRackでリダイレクト設定ができます。Herokuを使っていると便利。geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-88817564244308136492012-10-23T14:49:00.001+09:002013-01-21T03:08:06.464+09:00ruby on railsでgoogle analyticsのコードを本番だけで挿入<pre class="brush:ruby">
<%= render :partial => ‘layouts/ga’ if RAILS_ENV == ‘production’ %>
</pre>
こんな感じでレイアウトに記入。パーシャルはapp/views/llayouts/_ga.html.erbみたいな感じでOK。geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-35826946935871657832012-10-23T14:46:00.004+09:002013-01-21T03:09:10.081+09:00cakephpでGoogle Analyticsを本番環境だけで挿入<pre class="brush:php">
<?php
if (Configure::read('debug') == 0){
echo $this->element('analytics');
}
?>
</pre>
<br />
こんな感じでレイアウトに記入
実際のアナリティクスのコードはapp/views/elements/analytics.ctpに書くgeekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-72569745483671621652012-10-23T14:43:00.001+09:002013-01-21T03:09:36.665+09:00cakephpのヘルパーで日付拡張<pre class="brush:php">
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);
}
</pre>
<br />
<br />
app/views/helper/html.php<br />
<br />
こんな感じで拡張してあげると便利
geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-82371331527927977582012-07-10T00:00:00.003+09:002013-01-21T03:48:21.974+09:00CakePHPのモデルキャッシュ新しくカラムを追加した場合、本番環境でのみ更新されないということがある。debug=0では999日間モデルキャッシュが効いてるので削除してあげましょうというお話。<br />
<br />
<a href="http://pplace.jp/2011/06/158/">http://pplace.jp/2011/06/158/</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-18309530630362309132012-07-09T23:59:00.002+09:002013-01-21T03:48:27.912+09:00CakePHPでQdmailを使う場合の修正エラー文<br />
<br />
<pre class="brush:bash">Fatal error: Call to undefined method View::renderElement() in /***/app/controllers/components/qdmail.php on line 3823
</pre>
<br />
エラー分の該当箇所を下記に修正<br />
<br />
<br />
<br />
<pre class="brush:php">$content = $view->element( $this->view_dir . DS . $type . DS . $this->template ,
array('content' => $content ) , true );
</pre>
<br />
<br />
<br />
<a href="http://www.msng.info/archives/2011/01/using-qdmail-component-on-cakephp-1-3.php">http://www.msng.info/archives/2011/01/using-qdmail-component-on-cakephp-1-3.php</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-30886669648927265622012-07-09T23:57:00.002+09:002013-01-21T03:12:12.130+09:00JqueryのCDNが落ちてた場合の対処法<pre class="brush:javascript">
<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>
</pre>
<br />
<br />
こんな感じで対処できる<br />geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-75352955317951992952012-07-09T23:54:00.005+09:002013-01-21T03:25:57.192+09:00iOSでデフォルトで動いてるプロセスリスト<b>Launchd</b>: 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)<br />
<div class="p1">
<b>TQServer</b>: Net Long Company PC Suit daemon (recommend not to close it)</div>
<div class="p1">
<b>BTServer</b>: Bluetooth Service (BlueTooth) (in my environment with the dock, turn it off iphone not responding)</div>
<div class="p1">
<b>CommCenter</b>: Communications Center (phone system) (do not close)</div>
<div class="p1">
<b>configd</b>: to automatically configure and maintain the network (do not close)</div>
<div class="p1">
<b>cron</b>: regularly scheduled command or script execution (alarm clock might use it, recommend not to close it)</div>
<div class="p1">
<b>mDNSResponder</b>: Multicast-DNS Responder daemon. (Do not turn off)</div>
<div class="p1">
<b>lockdownd</b>: so that iPhone can use other SIM card (do not close)</div>
<div class="p1">
<b>ptpd</b>: the process of connecting itunes (do not close)</div>
<div class="p1">
<b>fitx</b>: WeFIT Input Method (not recommended to be closed)</div>
<div class="p1">
<b>mediaserverd</b>: (system sounds) (do not close)</div>
<div class="p1">
<b>notifyd</b>: inter-process communication (do not close)</div>
<div class="p1">
<b>SpringBoard</b>: 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)</div>
<div class="p1">
<b>MobilePhone</b>: I need not explain this right (do not close)</div>
<div class="p1">
<b>sshd</b>: ssh daemon (you can close it)</div>
<div class="p1">
<b>crashreporterd</b>: test application crashes the daemon. (Recommend to close)</div>
<div class="p1">
<b>dock</b>: dock the software process (you decide to use or not)</div>
<div class="p1">
<b>iapd</b>: 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)</div>
<div class="p1">
<b>syslogd</b>: recording system error logs and status messages (recommend to close)</div>
<div class="p2">
: 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.</div>
<br />geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-84864739099426569302012-07-09T23:52:00.002+09:002013-01-21T03:48:33.988+09:00VirtualBoxのCentOSでCPU使用率が上がる問題/etc/grub.conf を下記のように編集<br />
<br />
<br />
<pre class="brush:bash">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
</pre>
<br />
<br />
<a href="http://digitalbox.jp/happy-go-lucky-computing/centos/howto-decrease-cpu-utilization-of-centos-on-virtualbox/">http://digitalbox.jp/happy-go-lucky-computing/centos/howto-decrease-cpu-utilization-of-centos-on-virtualbox/</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-79125248846438357052012-07-09T23:50:00.003+09:002013-01-21T03:49:02.574+09:00CakePHP1.3.10のテストのエラー対応<br />
# /cake/tests/lib/reporter/cake_html_reporter.php
<br />
<pre class="brush: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);
}
</pre>
<br />
<br />
1.3.7では修正されたみたいだけど1.3.10ではまた戻っていたので対応<br />
<br />
<a href="http://blog.longkey1.net/archive/931">http://blog.longkey1.net/archive/931</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-23523176894329033872012-07-09T23:48:00.001+09:002013-01-21T03:49:12.193+09:00Apacheがログローテートのときに落ちる問題restartをreloadに変更して対処<br />
<br />
<br />
vi /etc/logrotate.d/httpd/var/log/httpd/*log
<br />
<pre class="brush:bash">{
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
}
</pre>
<br />
<a href="http://life1204.blogspot.jp/2008/11/httpdlogrotatehttpd.html">http://life1204.blogspot.jp/2008/11/httpdlogrotatehttpd.html</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-48259671338747201652012-07-09T23:42:00.003+09:002013-01-21T03:24:24.587+09:00HTML5のcanvasで画像データの読み書き<br />
<div class="p1">
<b style="background-color: white;">Canvasからbase64エンコーディングされた画像データを取得する方法
</b>
<pre class="brush:javascript">
var canvas = document.getElementById("myCanvas");
var base64 = canvas.toDataURL();
// LocalStorageに保存する
window.localStorage.setItem("saveKey", base64);
</pre>
<b>LocalStorageに保存したデータをCanvasに読み込む方法</b></div>
<pre class="brush:javascript">// LocalStroageからデータを取得する
var base64 = window.localStorage.getItem("saveKey");
// Imageオブジェクトを作成し、src属性にデータを設定する
var image = new Image();
image.src = base64;
image.onload = function(){
// 画像の読み込みが終わったら、Canvasに画像を反映する。
canvas.drawImage(image, 0, 0);
}
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-52765338609089750612012-07-09T23:27:00.004+09:002013-01-21T03:49:27.666+09:00herokuで独自ドメインを使うCustom Domain Add Onを入れてドメインを指定<br />
<br />
DNSサイドでは下記を登録する<br />
<br />
<pre class="CodeRay" lang="unknown" style="background-color: #434e56; background-image: url(https://devcenter.heroku.com/images/dev-center/wikistyle/pre_code_background.png); background-repeat: repeat repeat; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(63, 70, 76); color: #f8f8f8; font-family: Monaco, monospace; font-size: 11px; line-height: 18px; margin-bottom: 22px; outline: 0px; overflow-y: auto; padding: 12px; vertical-align: baseline;">75.101.163.44
75.101.145.87
174.129.212.2</pre>
<a href="https://devcenter.heroku.com/articles/custom-domains#dns_setup">https://devcenter.heroku.com/articles/custom-domains#dns_setup</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-35024087811034949232012-07-09T23:24:00.000+09:002013-01-21T03:49:43.328+09:00rvmとcapistranoを同時に使う時のメモGemfileに追加<br />
<br />
<br />
<pre class="brush:ruby">gem 'rvm-capistrano'
</pre>
<div>
<br /></div>
<div>
deproy.rbに追加</div>
<div>
<pre class="brush:ruby">set :rvm_ruby_string, 'ree@rails3' # Or:
#set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
require "rvm/capistrano" # Load RVM's capistrano plugin.
</pre>
</div>
<br />
<a href="https://rvm.io/integration/capistrano/">https://rvm.io/integration/capistrano/</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-15220833366616635082012-04-17T12:42:00.000+09:002012-04-17T12:42:10.385+09:00bundleでpgをインストールするときのエラー対応bundleでpgをインストールする時にmacのローカル環境ではpostgreSQLのconfign指定してあげる必要がある。Mac PortsでpostgreSQLを入れている場合下記のような感じで指定できる。
<br />
<br />
<pre class="brush:bash">bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config
</pre>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0tag:blogger.com,1999:blog-3561297057832105881.post-26168994331151792612012-04-17T12:37:00.000+09:002013-01-21T03:49:58.534+09:00postfixでqdmail.phpを使う場合エラーを吐くので1186行目をコメントアウトする<br />
<br />
<pre class="brush:php">//If(false !== @system($sendmail_path.' -d0.1 < /dev/null > /dev/null',$ret)){
// if(is_array($ret)){
// $ret = reset($ret);
// }
// $code = (int) substr($ret,0,3);
// if( 100 === $code || 111 === $code){
// $this->is_qmail = true;
// }
//}
</pre>
<br />
<a href="http://hal456.net/qdmail/support#c303">http://hal456.net/qdmail/support#c303</a>geekneeshttp://www.blogger.com/profile/08756603604232984823noreply@blogger.com0