ruby

Chrome DevTools

点点圈 提交于 2021-02-09 07:55:47
Chrome DevTools 小技巧 1.表格视图 console.table(arr2/obj, [arrColName]); // 以列表形式显示对象属性/值或者多维数组键/值 2.计时 console.time/timeEnd(str); // 成对出现,配合使用 3.snippet 可以把自己的调试工具库放进去,非常方便 4.图片取色 用浏览器打开图片,审查元素,设置任意色值,用取色器取色 5.常用快捷键 Ctrl + Shift + f 跨文件查找 Ctrl + Shift + o 查找函数定义 Ctrl + p 转到Sources面板 Ctrl + Shift + c 审查元素 Ctrl + L 跳转到指定行 ESC 显示/不显示console Ctrl + L 清空console 零.主面板 1.常用功能 模拟设备(横屏切换),模拟触摸事件(默认开启) 2.不常用功能 模拟网络(移动网络性能优化),模拟经纬度、加速度,调试媒体查询 二.Elements 1.常用功能 定位,临时修改,查看css规则,事件监听 2.不常用功能 DOM断点 (插入断点,子树更新/属性值更新/节点移除时触发,对应DOM3级节点更新事件),拖放节点修改DOM结构, 强制元素显示hover/active等状态 三.Network 1.网络面板能做什么 哪个资源最晚开始下载?

How to run ruby on terminal using sublime

喜夏-厌秋 提交于 2021-02-08 21:51:25
问题 I'm not even sure if this question is right. I'm doing a ruby tutorial on the following link www.youtube.com/watch?v=Dji9ALCgfpM And he writes code on sublime, and the ran code is shown on terminal. I used to do berry thing on integrative ruby, irb. What's the difference? 回答1: You have two main options: The first option is to run the Ruby code in your terminal. Save your Ruby file as somename.rb. In your terminal, navigate to the directory you saved it in, and then simply run it with ruby

LoadError: cannot load such file — capybara Stand Alone Code

独自空忆成欢 提交于 2021-02-08 15:32:53
问题 I'm working on building a simple post miner using Ruby and the following tutorial (http://ngauthier.com/2014/06/scraping-the-web-with-ruby.html) Here is my code I currently have: #!/usr/bin/ruby require 'capybara' require 'capybara/poltergeist' include Capybara::DSL Capybara.default_driver = :poltergeist visit "http://dilloncarter.com" all(".posts .post ").each do |post| title = post.find("h1 a").text url = post.find("h1 a")["href"] date = post.find("a")["datetime"] summary = post.find("p

Get value of all constants defined in a module

喜欢而已 提交于 2021-02-08 13:28:09
问题 I want to get the values of all the constants defined in a module: module Letters A = 'apple'.freeze B = 'boy'.freeze end constants gave me the name of the constants: Letters.constants(false) #=> [:A, :B] How do I get an array of their values, i.e. ["apple", "boy"] ? 回答1: In order to do this use map Letters.constants(false).map &Letters.method(:const_get) this will return ["a","b"] Second way : Letters.constants(false).map { |c| Letters.const_get c } Thanks @mudasobwa and Sagar Pandya for

Same string but different bytes codes

会有一股神秘感。 提交于 2021-02-08 13:13:52
问题 I have two strings: a = 'hà nội' b = 'hà nội' When I compare them with a == b , it returns false . I checked the byte codes: a.bytes = [104, 97, 204, 128, 32, 110, 195, 180, 204, 163, 105] b.bytes = [104, 195, 160, 32, 110, 225, 187, 153, 105] What is the cause? How can I fix it so that a == b returns true ? 回答1: This is an issue with Unicode equivalence. In order to compare these strings you need to normalize them, so that they both use the same byte sequences for these types of characters

Same string but different bytes codes

。_饼干妹妹 提交于 2021-02-08 13:13:49
问题 I have two strings: a = 'hà nội' b = 'hà nội' When I compare them with a == b , it returns false . I checked the byte codes: a.bytes = [104, 97, 204, 128, 32, 110, 195, 180, 204, 163, 105] b.bytes = [104, 195, 160, 32, 110, 225, 187, 153, 105] What is the cause? How can I fix it so that a == b returns true ? 回答1: This is an issue with Unicode equivalence. In order to compare these strings you need to normalize them, so that they both use the same byte sequences for these types of characters

Same string but different bytes codes

家住魔仙堡 提交于 2021-02-08 13:12:41
问题 I have two strings: a = 'hà nội' b = 'hà nội' When I compare them with a == b , it returns false . I checked the byte codes: a.bytes = [104, 97, 204, 128, 32, 110, 195, 180, 204, 163, 105] b.bytes = [104, 195, 160, 32, 110, 225, 187, 153, 105] What is the cause? How can I fix it so that a == b returns true ? 回答1: This is an issue with Unicode equivalence. In order to compare these strings you need to normalize them, so that they both use the same byte sequences for these types of characters

Heroku could not detect rake tasks (LoadError: cannot load such file — rspec/core/rake_task)

 ̄綄美尐妖づ 提交于 2021-02-08 13:07:54
问题 I'm using travisCI to deploy to heroku and I am getting this error. It has only just started happening. I have the basic rails Rakefile and I have a file that looks like this as otherwise travis cannot detect the rake tasks: # lib\tasks\spec.rake require 'rspec/core/rake_task' RSpec::Core::RakeTask.new task :default => :spec Why would this error be displaying specifically for heroku? EDIT - I had a similar version to the (better) answer given: begin require 'rspec/core/rake_task' desc "Run

Heroku could not detect rake tasks (LoadError: cannot load such file — rspec/core/rake_task)

孤街醉人 提交于 2021-02-08 13:04:52
问题 I'm using travisCI to deploy to heroku and I am getting this error. It has only just started happening. I have the basic rails Rakefile and I have a file that looks like this as otherwise travis cannot detect the rake tasks: # lib\tasks\spec.rake require 'rspec/core/rake_task' RSpec::Core::RakeTask.new task :default => :spec Why would this error be displaying specifically for heroku? EDIT - I had a similar version to the (better) answer given: begin require 'rspec/core/rake_task' desc "Run

where do I put code in Sinatra that I want to execute when the app is shutdown?

强颜欢笑 提交于 2021-02-08 12:52:27
问题 I am using Sinatra for my webapp. I have some cleanup code that I want to execute when my app is being shutdown. Is there a hook for this in Sinatra or do I have to use a separate mechanism? 回答1: Look at Kernel#at_exit, I don't see why it shouldn't work in a Sinatra app if you define a block like that somewhere in your main app file. Update: According to matt's comment, you have to define your at_exit handler before requiring Sinatra. 来源: https://stackoverflow.com/questions/11105556/where-do