0埋めしないようにするには、「-」マイナスつける。
> Time.now.strftime('%Y/%-m/%-d %-H:%-M:%-S') => "2015/6/6 13:9:54"
通常
> Time.now.strftime('%Y/%m/%d %H:%M:%S')=> "2015/06/06 13:10:05"
> Time.now.strftime('%Y/%-m/%-d %-H:%-M:%-S') => "2015/6/6 13:9:54"
> Time.now.strftime('%Y/%m/%d %H:%M:%S')=> "2015/06/06 13:10:05"
gem 'lazy_high_charts
//= require highcharts/highcharts
//= require highcharts/highcharts-more
//= require highcharts/highstock
//= require_tree .
def sellView
@categories = ["apple", "orange", "banana", "strawberry", "melon", "lemon", "peach"]
@data = [40, 10, 20, 50, 30, 10, 60]
@h = LazyHighCharts::HighChart.new("graph") do |f|
f.chart(:type => "bar")
f.title(:text => "Sample bar")
f.xAxis(:categories => @categories)
f.series(:name => "Fruits",
:data => @data)
end
end
<%= high_chart("sample", @h) %>
irb(main):072:0> today = Time.now
=> 2013-10-10 16:22:31 +0900
irb(main):073:0> beginning_of_month = Time.now.beginning_of_month
=> 2013-10-01 00:00:00 +0900
irb(main):074:0> (today - beginning_of_month).to_i/1.day
=> 9
$ gem list --local | grep mysql2
mysql2 (0.3.11)
$ irb
irb(main):001:0> require 'mysql2'
LoadError: no such file to load -- mysql2
from (irb):1:in `require'
from (irb):1
irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'mysql2'
=> true
> {"a" => 1, "b" => 2}.symbolize_keys
=> {:a=>1, :b=>2}
>hash = {"a" => 1, "b" => 2}
=> {"a"=>1, "b"=>2}
> json = hash.to_json
=> "{\"a\":1,\"b\":2}"
> JSON.parse(json)
=> {"a"=>1, "b"=>2}
> JSON.parse(json, {:symbolize_names => true})
=> {:a=>1, :b=>2}
gem sources --add http://rubygems.org/gem sources --add http://gems.github.com/
削除する時はこんな感じ。
gem sources --remove https://rubygems.org/
何が設定されているかは、 gem env コマンドで見てみましょう。
gem sources -l を実行するうと設定されたgemの検索対象部だけが見れます
require 'openssl'
require 'base64'
def encrypt(data, key, iv)
cipher = OpenSSL::Cipher.new('aes-128-cbc')
cipher.encrypt
cipher.key = key
cipher.iv = iv
cipher.update(data) + cipher.final
end
def decrypt(data, key, iv)
cipher = OpenSSL::Cipher.new('aes-128-cbc')
cipher.decrypt
cipher.key = key
cipher.iv = iv
cipher.update(data) + cipher.final
end
def main(data)
key = "1234567890123456"
iv = "abcdef1234567890"
# 暗号化
result = encrypt(data, key, iv)
base64text = Base64::strict_encode64(result)
# 復号化
text = Base64::strict_decode64(base64text)
dec_data = decrypt(text, key, iv)
# 確認
puts "<plain>"
puts data
puts "<after decrypt>"
puts dec_data
puts "<compare>"
puts data == dec_data
end
if ARGV.length != 1
puts "usage: ruby #{__FILE__} data"
exit 0
end
main(ARGV[0])
OpenSSL::Cipher::CipherError (key length too short):
> require "base64"
> encode = Base64.encode64("Hello World!")
=> "SGVsbG8gV29ybGQh\n"
> Base64.decode64(encode)
=> "Hello World!"
$ cd /opt/svn/test/hooks
$ vi pre_commit.rb
ごにょごにょ記載
$ sudo chown www-data:www-data pre_commit.rbpre-commit.tmplからpre-commitの作成
$ sudo chmod 777 pre_commit.rb
$ cp pre-commit.tmpl pre-commitapache再起動
$ sudo chown www-data:www-data pre-commit
$ sudo chmod 777 pre-commit
$ vi pre-commit
==
## 日本語を読み込む必要がある場合はこれが必要!
export LANG=ja_JP.UTF-8
REPOS="$1"
TXN="$2"
${REPOS}/hooks/pre_commit.rb "$REPOS" "$TXN"
==
rescue => e
msg = e.backtrace
require 'net/smtp'
#SMTP.start でセッションを開く
#第一引数がサーバのアドレスで第二引数がポート番号
#ブロックを使うとセッションの終了を自動的にやってくれる。
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
#send_mail(テンプレート, 送信元, 送信先)
smtp.send_mail <<EndOfMail, 'your@mail.address', 'to@some.domain'
From: Your Name <your@mail.address>
To: Dest Address <to@some.domain>
Subject: xxx script error
#{msg}
EndOfMail
}
> str = "ABCDE"
=> "ABCDE"
# 最終文字
> str[-1, 1]
=> "E"
# 最後から3番目の、そこから2文字
> str[-3, 2]
=> "CD"
1.9.3p194 :001 > 1/3
=> 0
1.9.3p194 :002 > 1/3.to_f
=> 0.3333333333333333
1.9.3p194 :003 > (1/3.to_f).round
=> 0
1.9.3p194 :004 > (1/3.to_f).round(2)
=> 0.33
1.9.3p194 :005 > 1/4
=> 0
1.9.3p194 :006 > 1.to_f/4
=> 0.25
1.9.3p194 :007 > (1.to_f/4).round
=> 0
1.9.3p194 :008 > (1.to_f/4).round(1)
=> 0.3
1.9.3p194 :009 > (1.to_f/4).round(2)
=> 0.25
sudo /etc/mysql/my.cnfこれを1行追加して
default-character-set=utf8MySQL再起動すればOK!
$ sudo /etc/init.d/mysql restart
$ rvm use listrvm を最新に更新する
rvm rubies
jruby-1.6.2 [ amd64 ]
ree-1.8.7-2011.03 [ x86_64 ]
ruby-1.8.6-p420 [ x86_64 ]
ruby-1.8.7-p352 [ x86_64 ]
ruby-1.9.2-p290 [ x86_64 ]
$ rvm get headアップデートしたrvmの再読み込み
$ rvm reload
RVM reloaded!
$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p358]
[ruby-]1.8.7-head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2-p318
[ruby-]1.9.2[-p320]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3-p125
[ruby-]1.9.3-[p194]
[ruby-]1.9.3-head
ruby-head
…
$ rvm install 1.9.3"--head"をつけるとリポジトリの最新リビジョン。
Installing Ruby from source to: /home/tiffany/.rvm/rubies/ruby-1.9.3-p194, this may take a while depending on your cpu(s)...
$ rvm use 1.9.3
Using /home/tiffany/.rvm/gems/ruby-1.9.3-p194
$ rvm use 1.9.2あれ… どもう最新じゃないからインストールせよと…
ruby-1.9.2-p320 is not installed.
To install do: 'rvm install ruby-1.9.2-p320'
$ rvm install ruby-1.9.2-p320
$ rvm use 1.9.2
Using /home/tiffany/.rvm/gems/ruby-1.9.2-p320
$ rvm use ruby-1.9.2-p290
Using /home/tiffany/.rvm/gems/ruby-1.9.2-p290
> require 'digest/md5'
=> true
> Digest::MD5.hexdigest("aa")
=> "4124bc0a9335c27f086f24ba207a4912"
> Digest::MD5.hexdigest("AA")
=> "3b98e2dffc6cb06a89dcb0d5c60a0206"
$ gem install passenger
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions. This could take a while...
Fetching: daemon_controller-1.0.0.gem (100%)
Fetching: passenger-3.0.12.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-1.0.0
Successfully installed passenger-3.0.12
3 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for daemon_controller-1.0.0...
Installing ri documentation for passenger-3.0.12...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for daemon_controller-1.0.0...
Installing RDoc documentation for passenger-3.0.12...
$ passenger-install-apache2-moduleここではとりあえずEnter押下。
Welcome to the Phusion Passenger Apache 2 module installer, v3.0.12.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
Here's what you can expect from the installation process:
1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
3. You'll learn how to deploy a Ruby on Rails application.
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
Press Enter to continue, or Ctrl-C to abort.
--------------------------------------------無事インストールされたようなのでEnter押下。
The Apache 2 module was successfully installed.
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /home/tiffany/.rvm/gems/ruby-1.9.2-p290@rails3/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
PassengerRoot /home/tiffany/.rvm/gems/ruby-1.9.2-p290@rails3/gems/passenger-3.0.12
PassengerRuby /home/tiffany/.rvm/wrappers/ruby-1.9.2-p290@rails3/ruby
After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!
Press ENTER to continue.
--------------------------------------------
Deploying a Ruby on Rails application: an example
Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:
<VirtualHost *:80>
ServerName www.yourhost.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /somewhere/public
<Directory /somewhere/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:
/home/tiffany/.rvm/gems/ruby-1.9.2-p290@rails3/gems/passenger-3.0.12/doc/Users guide Apache.html
Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
$ sudo vi /etc/apache2/sites-available/xxxそのファイルに下記を追加します。
LoadModule passenger_module /home/tiffany/.rvm/gems/ruby-1.9.2-p290@rails3/gems/passenger-3.0.12/ext/apache2/mod_passenger.soモジュールのパス設定
PassengerRoot /home/tiffany/.rvm/gems/ruby-1.9.2-p290@rails3/gems/passenger-3.0.12
PassengerRuby /home/tiffany/.rvm/wrappers/ruby-1.9.2-p290@rails3/ruby
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /home/tiffany/sinatra/public
<Directory /home/tiffany/sinatra/public>
AllowOverride all
Options -MultiViews
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
DocumentRoot /home/tiffany/sinatra/public
RackEnv development