Skip to content

Instantly share code, notes, and snippets.

@yyandrew
yyandrew / skills.otl
Last active September 30, 2015 04:04
SECTION1 - Rails
1.Enumerable inject用法:User.limit(2).inject({}) {|h, u| h[u.id]=u.email;h} #return {1=>"test1@test.com", 2=>"test2@test.com"};
2.查看所有precompile的assets文件 y Rails.application.config.assets.paths
3..gitignore没有作用的解决方法
git rm . -r --cached
git add .
git commit -m "fixed untracked files"
4.install fish shell on ubuntu
#install fish shell
sudo apt-add-repository ppa:fish-shell/release-2
// get chart object in javascript
var chart = $("#chart_container_id").highcharts();
// fire click event of first point
chart.series[0].data[0].firePointEvent('click');
1.cap staging deploy -s branch=1626d55d3da9
2.cap staging deploy:rollback #rollback to the previous version
3.添加新的任务-显示服务器当前的代码版本号。在config/deploy.rb文件添加如下代码
namespace :deploy do
desc 'Show deployed version'
task :revision do
on roles(:app) do
execute "echo current version is------------------"
execute "cat #{current_path}/REVISION"
execute "echo end----------------"
def run_in_browser(js, html)
jsfile = Tempfile.new(['js', '.js'])
jsfile.write(js)
jsfile.close
htmlfile = Tempfile.new(['test', '.html'])
htmlfile.write(html)
htmlfile.close
Phantomjs.run(jsfile.path, htmlfile.path)
TODO List
2014-10-12 13:04:37 ----------------------------------------
[_] 50% About vimoutliner
[X] Learn vimoutliner
[_] Content code issue of vimoutliner when use otl2html.py
NEXT ACTIONS
[_] 16%Lenrn rails
[X] Try swaggerui gem
[_] Learn docker-http://blog.gemnasium.com/post/65599561888/rails-meets-docker
[_] Learn chef http://learn.getchef.com/
# return boolean but not MatchData
!!website.match(Regexp.new(sites))
params.require(:article).permit(:title, :content, :description, :images_attributes => [:title, :image])
Image.where("image is not ?", nil).each do |image| image.image.recreate_versions! if image.image? end
#create capistrano task to run rake task of rails
# add below code to deploy.rb
desc "recreate version of all images."
task :recreate_version_of_images do
on roles(:app) do
within "#{current_path}" do
with rails_env: :production do
execute :rake, "images:recreate_version"
end
end
a.sort # sort by asc
a.sort { |x,y| y <=> x } # sort by desc