Encore's Blog

Web 开发者 | 专注于WEB应用程序的软件开发人员
Gem - Use ruby-processbar to display processing progress
工具 2019-06-09 Encore Shao

Basic requirements: when using Rake to process data, we need to know the current processing status and progress.Before, my processing method is: use puts to print some unique information so that we can process the progress through the current. Finally, Googled found a good gem. It may be more friendly to help us output the data processing status and schedule. So recommend it to everyone today.G...

标签: Gems Ruby Rake GEM
Use Brakeman analysis code security in Ruby on Rails
开发 2019-03-24 邵壮

Brakeman - Ruby on Rails Static Analysis Security Tool如果您也使用Ruby On Rails来构建应用程式,那我推荐你也添加 `brakeman` 到您的项目中,它可以有效的帮助你分析代码安全问题,从而提高代码质量。接下来,我们看看如何在你的项目中使用它1. Add brakeman to your Gemfilegroup :development do   gem 'brakeman' end2. Running locallyFrom a Rails application's root directory:brakeman3. CI Configuration for Rails Project Drop this into project_root/.gitlab-ci.ymlservices:   - postg...

标签: Rails Ruby GEM
Git 钩子:提交前使用Rubocop做代码格式检查
工具 2018-09-05 邵壮

Git hook - 如果您使用git作为代码管理工作。 前提摘要:我们会在Rails项目中使用rubocop来校验我们代码的格式,语法等等是否正确。但有时候我们在提交时候在本地会忘记跑rubocop来校验代码是否合格,此时,如果你的项目配置了自动化CI, 那么你可能会收到一封failed的邮件通知. 这样的体验会很不好! 那么为了避免这些事情发生,git有一个很好的钩子来帮我们实线提交前的验证。<pre-commit>, 是不是听起来很不错,接下来我们来使用Ruby来完成这个git hook.  查看所有的hooks - 在你自己项目的根目录下运行 #blog> ls .git/hooks applypatch-msg.sample post-update.sample pre-push.s...

标签: Ruby Git Rails
Ruby - 如何通过一组键获取哈希值
工作 2018-08-15 邵壮

Ruby: 2.5.1  -  Hash#dig 前提:一个已知的Hash数据,然后知道一组键值. 从而想获取最终的value. 在我们数据中有一个名为data jsonb 字段, 然后不同Source的数据,数据是结构是不一样的。如以下示例: 1. { "values" => 10 } 2. { "followers"=> { "count"=>0 } } 3. { "financials"=>[{"margin"=>{"value"=>10}}] } 4. { "social" => { "linkedin" => { "employees" => {"value" => 234} } } } 本来想着拓展一下Hash类,最后发现Ruby中已经实现了 Hash#dig ...

标签: Rails Ruby
Ruby - Exception与StandardError:有什么区别?
开发 2018-07-01 邵壮

请不要在Ruby直接使用Exception来捕捉异常! 在这之前你也许已经听说过这个。的确这是一个很好的建议,除非你已经知道,否则它会让人感到困惑。接下来让我们来分解这个,看看它到底是什么意思。 你可能知道在Ruby中,你可以像这样拯救异常: begin do_something() rescue => e puts e # e is an exception object containing info about the error. end And you can rescue specific errors by providing the classname of the error. begin do_something() rescue ActiveRecord::RecordNo...

标签: Ruby
How to add submodule to gitlab CI
开发 2017-08-13 邵壮

如何在Rails项目中使用rails engine, 如何在CI中配置submodule 以gem的形式添加在Gemfile中 # Engine gem 'database_core', path: 'vendor/engines/database_core' 接下来我们应该每天都尝试拿最新的engine代码到本地 # If you first clone this project, please run this command in terminal > git submodule update --init --recursive # Every day should pull the latest updates from the remote repository > git pull > git submod...

标签: Docker Ruby Rails
A quick script to selectively remove Failed Jobs from Resque 1.x
编码 2017-07-16 Encore Shao

1. 你可以复制到以下的代码片段并将其粘贴到rails控制台中 def delete_if redis = Resque.redis (0...Resque::Failure.count).each do |i| string = redis.lindex(:failed, i) break if string.nil? job = Resque.decode(string) remove = yield job next unless remove redis.lrem(:failed, 1, string) redo end end 2. 选择你要删除的所有workers,例如:由于http错误而失败的所有推送通知作业 ...

标签: Rails Ruby Resque
How to know the cost of loading all gems in your project
开发 2017-07-15 邵壮

Add benchmark to config/boot.rb require 'benchmark' def require(file) puts Benchmark.measure("") { super }.format("%t require #{file}") end Run command in iterm2 rails runner 1 | sort -nr | head -n 150 You will see all output like this: encore:blog (master) : 14h42m -> rails runner 1 | sort -nr | head -n 150 0.050000 require i18n 0.030000 require securerandom 0.030000 re...

标签: Ruby Rails
Amazon - Alexa Web Information Service (AWIS)
工具 2017-04-07 邵壮

Source: https://github.com/encoreshao/amazon-awis Amazon - Alexa Web Information Service (AWIS) Ruby Library for AWIS REST API - See: Alexa Docs How to installation gem install awis-sdk-ruby How to usage Configure your amazon certificate require 'awis' AWIS_CONFIG = YAML.load(File.read('awis.yml')) Awis.config do |c| c.access_key_id = AWIS_CO...

标签: Alexa AWIS Amazon Ruby
This website uses cookies to ensure you get the best experience on our website.
Got it!