Ruby's Array and Array.wrap的区别

hash = {cgg: 11, cbq: 22} pry(main)> Array(hash) [ [ :cgg, 11 ], [ :cbq, 22 ] ] pry(main)> Array.wrap(hash) [ { :cgg => 11, :cbq => 22 } ] Array(nil) [] Array(11) => [ 11 ] Arr...


ruby使用transpose生成hash

irb(main):001:0> header = ['key1', 'key2', 'key3', 'key4'] => ["key1", "key2", "key3", "key4"] irb(main):002:0> values = ['val1', 'val2', 'val3', 'val4'] => ["val1", "val2", "val3", "va...


sinatra-console

bundle exec irb -I. -r api.rb ref: https://coderwall.com/p/rqfeug/rails-console-equivalent-for-sinatra


根据IP选择ruby source

开发必备翻墙。但生产服务器是放在国内,那么问题就来啦! Gemfile中的source写哪里的? source 'https://rubygems.org' source 'http://ruby.taobao.org' 切换国外的时候跑 https://rubygems.org 切换国内的时候跑 http://ruby.taobao.org 难道还要每次手工改不成? ...


assets本地编译优化部署时间

随着rails项目js效果增加,加了JS MVC框架等,变的每发布一次时间越来越延长!也增加服务器在高峰时候cpu与内存的负担! 综合考虑解决把 rake assets:precompile 放在本地编译,然后通过capistrano2发布到服务端! 修改 config/deploy.rb namespace :prepare do desc "Compress assets in...


让Octopress支持短链接

增加gem到Gemfile中 echo "gem 'dljbz'">>Gemfile 让dlj缓存不提交到git中 echo ".dlj-cache">>.gitignore 新增plugins/dlj_tag.rb文件,内容如下: ```ruby plugins/dlj_tag.rb -- encoding : utf-8 -- require '...


sunspot的坑爹配置引起了围观

sunspot的Gem用的是 ```ruby Gemfile gem 'sunspot_rails', '2.1.1' gem 'sunspot_solr', '2.1.1' ```bash shell user@xxxx:~/xxxxx/current$ RAILS_ENV=production bundle exec rake sunspot:reindex --trace ...


在rails中用backup数据备份-dropbox篇

###1.申请dropbox的api_key与api_secret 打开https://www.dropbox.com/developers/apps申请 ####第一步 点击右上角的”Create app“ ####第二步 点击右下角的”Create app“ ####第三步 ####第四步 复制App key与App secret 到下面的置文件中 打开config/...


在rails中用backup数据备份-备份篇

###1.安装backup.gem ```ruby backup.gem Install the latest 4.x version $ gem install backup -v '~> 4.0' --no-rdoc --no-ri ###2.生成backup的脚本 * 把这个备份放在rails的config目录下了! * 下面的生成脚本是:mongodb备份、gzi...


短链接dlj.bz

短链接 http://dlj.bz上线啦!短链接 - 更好传递!! ```bash curl调试方法 curl http://dlj.bz/api/urlshortener \ -H 'Content-Type: application/json' \ -d '{"long_url": "http://www.google.com/"}' {"short_url":"http://d...


rvm install ruby-1.9.2 error

今天要跑一个老的代码。发现rvm 装不了ruby1.9.2啦,报了错。 还以为是rvm 的问题... 升级了rvm.还是一样的。 想到之前Mac osX 升到了Mavericks。XCODE中的"command line tools"不见了。 $ rvm install ruby-1.9.2 Searching for binary rubies, this might take ...


.nil? .empty? .blank? .present? 方法总结

###nil? a=nil a.nil? = true a="" a.nil = false ###empty? "".empty? => true " ".empty? => false ###blank? nil.blank? =>true [].blank? => true {}.blank? => true "".blank? =...


sinatra assets pipeline example

添加gem ```ruby Gemfile gem 'sinatra-asset-pipeline' gem 'sprockets-helpers' 添加一些代码 ```ruby App.rb require 'sinatra/asset_pipeline' class App < Sinatra::Base # Include these files when preco...


rvm install ruby2

~ john$ rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-p371] [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p320] [ruby-]1.9.3-p125 [ruby-]1.9.3-p194 [ruby-]1.9.3-p286 [ruby-]1.9.3-p327 [ruby-]1...


rvm ruby report: Error running 'make', please read /home/xxx/.rvm/log/ruby-1.9.3-p385/make.log

每次配置环境都会有惊喜的报错。 john@john-Inspiron-N4050:~$ rvm install 1.9.3 Searching for binary rubies, this might take some time. No binary rubies available for: ubuntu/12.10/x86_64/ruby-1.9.3-p385. Continuin...