问:
Watir app deployed to heroku
I'm trying to deploy an app to Heroku that uses Watir webdriver. It runs successfully locally. According to answers to this question: Can you deploy Watir on Heroku to generate HTML Snapshots? If so, how?, you can do it. I followed steps from this answer https://stackoverflow.com/a/21267376/3192470. My app.rb looks like this:

```<code>require "sinatra"
require "rubygems"
require "shotgun"
require "rake"
require "watir"

get '/sending_out' do
    browser = Watir::Browser.new :phantomjs
    erb :index
end
</code>```

But it crashes when deployed to Heroku with these logs:

```<code>2014-10-24T13:01:10.620468+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
2014-10-24T13:01:10.620465+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:35:in `block in launch'
2014-10-24T13:01:10.620480+00:00 app[web.1]:    credits.rb:44:in `rencredit'
2014-10-24T13:01:10.620496+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
2014-10-24T13:01:10.620510+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
2014-10-24T13:01:10.620534+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
2014-10-24T13:01:10.620590+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
2014-10-24T13:01:10.620460+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
2014-10-24T13:01:10.620475+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:46:in `initialize'
2014-10-24T13:01:10.620491+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
2014-10-24T13:01:10.620506+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
2014-10-24T13:01:10.620524+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
2014-10-24T13:01:10.620587+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
2014-10-24T13:01:10.620469+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
2014-10-24T13:01:10.620484+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
2014-10-24T13:01:10.620500+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
2014-10-24T13:01:10.620525+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
2014-10-24T13:01:10.620526+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
2014-10-24T13:01:10.620528+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
2014-10-24T13:01:10.620529+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
2014-10-24T13:01:10.620574+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
2014-10-24T13:01:10.621081+00:00 app[web.1]: ip-10-226-67-253.ec2.internal - - [24/Oct/2014:13:01:10 UTC] "POST /sending_out HTTP/1.1" 500 30
2014-10-24T13:01:10.620462+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
2014-10-24T13:01:10.620477+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/watir-5.0.0/lib/watir/loader.rb:9:in `initialize'
2014-10-24T13:01:10.620492+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
2014-10-24T13:01:10.620507+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
2014-10-24T13:01:10.620531+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
2014-10-24T13:01:10.620588+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-10-24T13:01:10.620459+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
2014-10-24T13:01:10.620474+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver.rb:67:in `for'
2014-10-24T13:01:10.620490+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
2014-10-24T13:01:10.620505+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
2014-10-24T13:01:10.620517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
2014-10-24T13:01:10.620584+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
2014-10-24T13:01:10.620464+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
2014-10-24T13:01:10.620479+00:00 app[web.1]:    credits.rb:44:in `new'
2014-10-24T13:01:10.620494+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
2014-10-24T13:01:10.620509+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
2014-10-24T13:01:10.620532+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
2014-10-24T13:01:10.620586+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
2014-10-24T13:01:10.620483+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
2014-10-24T13:01:10.620499+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
2014-10-24T13:01:10.620513+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
2014-10-24T13:01:10.620573+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
2014-10-24T13:01:10.620761+00:00 app[web.1]: 83.245.232.99 - - [24/Oct/2014 13:01:10] "POST /sending_out HTTP/1.1" 500 30 0.3206
2014-10-24T13:01:10.620466+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
2014-10-24T13:01:10.620481+00:00 app[web.1]:    credits.rb:36:in `block in <main>'
2014-10-24T13:01:10.620497+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
2014-10-24T13:01:10.620511+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
2014-10-24T13:01:10.620535+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'
2014-10-24T13:01:10.620592+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
2014-10-24T13:01:10.620471+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
2014-10-24T13:01:10.620486+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
2014-10-24T13:01:10.620502+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
2014-10-24T13:01:10.620514+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
2014-10-24T13:01:10.620537+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-10-24T13:01:10.620593+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
2014-10-24T13:01:10.620453+00:00 app[web.1]: Selenium::WebDriver::Error::WebDriverError - Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=:
2014-10-24T13:01:10.620472+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
2014-10-24T13:01:10.620487+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
2014-10-24T13:01:10.620503+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
2014-10-24T13:01:10.620515+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
2014-10-24T13:01:10.620555+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-10-24T13:01:10.621098+00:00 app[web.1]: http://sleepy-dawn-1804.herokuapp.com/ -> /sending_out
2014-10-24T13:01:10.625080+00:00 heroku[router]: at=info method=POST path="/sending_out" host=sleepy-dawn-1804.herokuapp.com request_id=ab9957cb-f2af-416c-9055-8fe4d4ccae69 fwd="83.245.232.99" dyno=web.1 connect=1ms service=327ms status=500 bytes=326
2014-10-24T13:19:46+00:00 heroku[slug-compiler]: Slug compilation started
2014-10-24T13:19:56+00:00 heroku[slug-compiler]: Slug compilation finished
2014-10-24T13:19:56.715255+00:00 heroku[api]: Deploy a3750e4 by ___
2014-10-24T13:19:56.715329+00:00 heroku[api]: Release v13 created by ___
2014-10-24T13:19:56.987774+00:00 heroku[web.1]: State changed from up to starting
2014-10-24T13:19:59.188226+00:00 app[web.1]: == Sinatra has ended his set (crowd applauds)
2014-10-24T13:19:59.372012+00:00 heroku[web.1]: Starting process with command `bundle exec ruby credits.rb -p 38378`
2014-10-24T13:19:59.936031+00:00 app[web.1]: bash: bundle: command not found
2014-10-24T13:19:58.792208+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-10-24T13:20:00.744914+00:00 heroku[web.1]: State changed from crashed to starting
2014-10-24T13:20:00.744331+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-24T13:20:00.731432+00:00 heroku[web.1]: Process exited with status 127
2014-10-24T13:20:00.979441+00:00 app[web.1]: [2014-10-24 13:20:00] INFO  WEBrick::HTTPServer#start done.
2014-10-24T13:20:00.979326+00:00 app[web.1]: [2014-10-24 13:20:00] INFO  going to shutdown ...
2014-10-24T13:20:01.793815+00:00 heroku[web.1]: Process exited with status 0
2014-10-24T13:20:02.890977+00:00 heroku[web.1]: Starting process with command `bundle exec ruby credits.rb -p 8176`
2014-10-24T13:20:03.432512+00:00 app[web.1]: bash: bundle: command not found
2014-10-24T13:20:04.173800+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-24T13:20:04.164173+00:00 heroku[web.1]: Process exited with status 127
2014-10-24T13:20:04.812284+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepy-dawn-1804.herokuapp.com request_id=f0b2bb74-8eaa-4a4c-801f-97ab9d442f04 fwd="54.166.216.157" dyno= connect= service= status=503 bytes=
2014-10-24T13:20:06.224767+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/sending_out" host=sleepy-dawn-1804.herokuapp.com request_id=eb306448-91ee-40ea-89ec-7756e277e986 fwd="83.245.232.99" dyno= connect= service= status=503 bytes=
</code>```

And also when I push it to Heroku it thinks it's a phantomjs app:

```<code>PhantomJS app detected
</code>```

What could be done about all that? Is this at all possible to run Watir from Heroku?

EDIT: answer from Heroku support:

Watir requires selenium, which requires an X server install on the machine.
  Because our dynos aren't meant to launch graphic applications, they don't have any X server installed, and therefore can't install Selenium.
  Therefore, I'm afraid it's not going to be possible to use Watir in your application.

答:
You can now use chrome headlessly as well, you can try it here in a sample I developed:

https://github.com/jormon/minimal-chrome-on-heroku-xvfb

Title: Watir app deployed to heroku

Body:
I'm trying to deploy an app to Heroku that uses Watir webdriver. It runs successfully locally. According to answers to this question: Can you deploy Watir on Heroku to generate HTML Snapshots? If so, how?, you can do it. I followed steps from this answer https://stackoverflow.com/a/21267376/3192470. My app.rb looks like this:

require "sinatra"
require "rubygems"
require "shotgun"
require "rake"
require "watir"

get '/sending_out' do
    browser = Watir::Browser.new :phantomjs
    erb :index
end

But it crashes when deployed to Heroku with these logs:

2014-10-24T13:01:10.620468+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
2014-10-24T13:01:10.620465+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:35:in `block in launch'
2014-10-24T13:01:10.620480+00:00 app[web.1]:    credits.rb:44:in `rencredit'
2014-10-24T13:01:10.620496+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
2014-10-24T13:01:10.620510+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
2014-10-24T13:01:10.620534+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
2014-10-24T13:01:10.620590+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
2014-10-24T13:01:10.620460+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
2014-10-24T13:01:10.620475+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:46:in `initialize'
2014-10-24T13:01:10.620491+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
2014-10-24T13:01:10.620506+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
2014-10-24T13:01:10.620524+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
2014-10-24T13:01:10.620587+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
2014-10-24T13:01:10.620469+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
2014-10-24T13:01:10.620484+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
2014-10-24T13:01:10.620500+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
2014-10-24T13:01:10.620525+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
2014-10-24T13:01:10.620526+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
2014-10-24T13:01:10.620528+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
2014-10-24T13:01:10.620529+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
2014-10-24T13:01:10.620574+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
2014-10-24T13:01:10.621081+00:00 app[web.1]: ip-10-226-67-253.ec2.internal - - [24/Oct/2014:13:01:10 UTC] "POST /sending_out HTTP/1.1" 500 30
2014-10-24T13:01:10.620462+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
2014-10-24T13:01:10.620477+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/watir-5.0.0/lib/watir/loader.rb:9:in `initialize'
2014-10-24T13:01:10.620492+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
2014-10-24T13:01:10.620507+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
2014-10-24T13:01:10.620531+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
2014-10-24T13:01:10.620588+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-10-24T13:01:10.620459+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
2014-10-24T13:01:10.620474+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver.rb:67:in `for'
2014-10-24T13:01:10.620490+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
2014-10-24T13:01:10.620505+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
2014-10-24T13:01:10.620517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
2014-10-24T13:01:10.620584+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
2014-10-24T13:01:10.620464+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
2014-10-24T13:01:10.620479+00:00 app[web.1]:    credits.rb:44:in `new'
2014-10-24T13:01:10.620494+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
2014-10-24T13:01:10.620509+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
2014-10-24T13:01:10.620532+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
2014-10-24T13:01:10.620586+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
2014-10-24T13:01:10.620483+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
2014-10-24T13:01:10.620499+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
2014-10-24T13:01:10.620513+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
2014-10-24T13:01:10.620573+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
2014-10-24T13:01:10.620761+00:00 app[web.1]: 83.245.232.99 - - [24/Oct/2014 13:01:10] "POST /sending_out HTTP/1.1" 500 30 0.3206
2014-10-24T13:01:10.620466+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
2014-10-24T13:01:10.620481+00:00 app[web.1]:    credits.rb:36:in `block in '
2014-10-24T13:01:10.620497+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
2014-10-24T13:01:10.620511+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
2014-10-24T13:01:10.620535+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'
2014-10-24T13:01:10.620592+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
2014-10-24T13:01:10.620471+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
2014-10-24T13:01:10.620486+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
2014-10-24T13:01:10.620502+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
2014-10-24T13:01:10.620514+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
2014-10-24T13:01:10.620537+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-10-24T13:01:10.620593+00:00 app[web.1]:    /app/vendor/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
2014-10-24T13:01:10.620453+00:00 app[web.1]: Selenium::WebDriver::Error::WebDriverError - Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=:
2014-10-24T13:01:10.620472+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
2014-10-24T13:01:10.620487+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
2014-10-24T13:01:10.620503+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
2014-10-24T13:01:10.620515+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
2014-10-24T13:01:10.620555+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-10-24T13:01:10.621098+00:00 app[web.1]: http://sleepy-dawn-1804.herokuapp.com/ -> /sending_out
2014-10-24T13:01:10.625080+00:00 heroku[router]: at=info method=POST path="/sending_out" host=sleepy-dawn-1804.herokuapp.com request_id=ab9957cb-f2af-416c-9055-8fe4d4ccae69 fwd="83.245.232.99" dyno=web.1 connect=1ms service=327ms status=500 bytes=326
2014-10-24T13:19:46+00:00 heroku[slug-compiler]: Slug compilation started
2014-10-24T13:19:56+00:00 heroku[slug-compiler]: Slug compilation finished
2014-10-24T13:19:56.715255+00:00 heroku[api]: Deploy a3750e4 by ___
2014-10-24T13:19:56.715329+00:00 heroku[api]: Release v13 created by ___
2014-10-24T13:19:56.987774+00:00 heroku[web.1]: State changed from up to starting
2014-10-24T13:19:59.188226+00:00 app[web.1]: == Sinatra has ended his set (crowd applauds)
2014-10-24T13:19:59.372012+00:00 heroku[web.1]: Starting process with command `bundle exec ruby credits.rb -p 38378`
2014-10-24T13:19:59.936031+00:00 app[web.1]: bash: bundle: command not found
2014-10-24T13:19:58.792208+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-10-24T13:20:00.744914+00:00 heroku[web.1]: State changed from crashed to starting
2014-10-24T13:20:00.744331+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-24T13:20:00.731432+00:00 heroku[web.1]: Process exited with status 127
2014-10-24T13:20:00.979441+00:00 app[web.1]: [2014-10-24 13:20:00] INFO  WEBrick::HTTPServer#start done.
2014-10-24T13:20:00.979326+00:00 app[web.1]: [2014-10-24 13:20:00] INFO  going to shutdown ...
2014-10-24T13:20:01.793815+00:00 heroku[web.1]: Process exited with status 0
2014-10-24T13:20:02.890977+00:00 heroku[web.1]: Starting process with command `bundle exec ruby credits.rb -p 8176`
2014-10-24T13:20:03.432512+00:00 app[web.1]: bash: bundle: command not found
2014-10-24T13:20:04.173800+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-24T13:20:04.164173+00:00 heroku[web.1]: Process exited with status 127
2014-10-24T13:20:04.812284+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepy-dawn-1804.herokuapp.com request_id=f0b2bb74-8eaa-4a4c-801f-97ab9d442f04 fwd="54.166.216.157" dyno= connect= service= status=503 bytes=
2014-10-24T13:20:06.224767+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/sending_out" host=sleepy-dawn-1804.herokuapp.com request_id=eb306448-91ee-40ea-89ec-7756e277e986 fwd="83.245.232.99" dyno= connect= service= status=503 bytes=

And also when I push it to Heroku it thinks it's a phantomjs app:

PhantomJS app detected

What could be done about all that? Is this at all possible to run Watir from Heroku?

EDIT: answer from Heroku support:

Watir requires selenium, which requires an X server install on the machine.
  Because our dynos aren't meant to launch graphic applications, they don't have any X server installed, and therefore can't install Selenium.
  Therefore, I'm afraid it's not going to be possible to use Watir in your application.


来源: stackexchange

问:
NSTextField draws partially transparent text when drawsBackground = YES
I have an NSTextField. I want it to draw text and have a background color. But when I set drawsBackground to YES, the text seems to draw partially transparently. For example, if I set the text color to white and background to black, the text comes out gray. Why is this?

答:
Make sure isEnabled set to true.

I was seeing this as well and changing this fixed it for me.

ContentLicense: CC BY-SA 3.0


问:
Automatically scroll to bottom of RecyclerView
I have a fragment that has a RecyclerView inside its layout file. The RecyclerView holds messages in a chat. So naturally, I need the RecyclerView to scroll to the bottom when the chat fragment gets opened.

I tried scrolling directly on the RecyclerView:

```<code>var mRecyclerView = view.FindViewById<RecyclerView>
mRecyclerView.ScrollToPosition(mMessages.Count-1);
</code>```

Second method:

```<code>LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(Application.Context);
mRecyclerView.SetLayoutManager(mLinearLayoutManager);
mLinearLayoutManager.ScrollToPosition(mMessages.Count - 1);
</code>```

Third method:

```<code>LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(Application.Context);
mRecyclerView.SetLayoutManager(mLinearLayoutManager);
mLinearLayoutManager.ScrollToPositionWithOffset(mMessages.Count - 1, 0);
</code>```

Unfortunately, nothing happens in either case. Any suggestions would be greatly appreciated!

答:
Please use smoothScrollToPosition to fix your issue.
I always use smoothScrollToPosition for redirecting to any position.

Make sure, mMessages size is good as you thinking.

Example,

```<code>RecyclerView rv = (RecyclerView)findViewById(R.id.recyclerView);
rv.smoothScrollToPosition(mMessages.count-1);
</code>```

Body:
I have a fragment that has a RecyclerView inside its layout file. The RecyclerView holds messages in a chat. So naturally, I need the RecyclerView to scroll to the bottom when the chat fragment gets opened.

I tried scrolling directly on the RecyclerView:

var mRecyclerView = view.FindViewById<RecyclerView>
mRecyclerView.ScrollToPosition(mMessages.Count-1);

Second method:

LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(Application.Context);
mRecyclerView.SetLayoutManager(mLinearLayoutManager);
mLinearLayoutManager.ScrollToPosition(mMessages.Count - 1);

Third method:

LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(Application.Context);
mRecyclerView.SetLayoutManager(mLinearLayoutManager);
mLinearLayoutManager.ScrollToPositionWithOffset(mMessages.Count - 1, 0);

Unfortunately, nothing happens in either case. Any suggestions would be greatly appreciated!

Body:
Please use smoothScrollToPosition to fix your issue.
I always use smoothScrollToPosition for redirecting to any position.

Make sure, mMessages size is good as you thinking.

Example,

RecyclerView rv = (RecyclerView)findViewById(R.id.recyclerView);
rv.smoothScrollToPosition(mMessages.count-1);


问:
Best way to convert string of digits into its numerical big.Rat value
I'm working with math/big.

I was wondering if somebody knows a short way to convert a string of digits like "2023930943509509" to a big.Rat type value.

I know .SetString() can be used for big.Int types, but can the same be done for the Rat type?

答:
You don't have to learn these methods and functions by heart, whenever you look for something, check the package documentation. The doc of the package in question can be found here: math/big.

As you can see in the doc, there is a Rat.SetString() method for the big.Rat type too which you can use for this purpose:

```<code>func (z *Rat) SetString(s string) (*Rat, bool)
</code>```

SetString sets z to the value of s and returns z and a boolean indicating success. s can be given as a fraction "a/b" or as a floating-point number optionally followed by an exponent. The entire string (not just a prefix) must be valid for success. If the operation failed, the value of z is un- defined but the returned value is nil.

Example using it:

```<code>r := big.NewRat(1, 1)
if _, ok := r.SetString("2023930943509509"); !ok {
    fmt.Println("Failed to parse the string!")
}
fmt.Println(r)
fmt.Println(r.FloatString(2))
</code>```

Output (try it on the Go Playground):

```<code>2023930943509509/1
2023930943509509.00
</code>```

Body:
You don't have to learn these methods and functions by heart, whenever you look for something, check the package documentation. The doc of the package in question can be found here: math/big.

As you can see in the doc, there is a Rat.SetString() method for the big.Rat type too which you can use for this purpose:

func (z *Rat) SetString(s string) (*Rat, bool)

SetString sets z to the value of s and returns z and a boolean indicating success. s can be given as a fraction "a/b" or as a floating-point number optionally followed by an exponent. The entire string (not just a prefix) must be valid for success. If the operation failed, the value of z is un- defined but the returned value is nil.

Example using it:

r := big.NewRat(1, 1)
if _, ok := r.SetString("2023930943509509"); !ok {
    fmt.Println("Failed to parse the string!")
}
fmt.Println(r)
fmt.Println(r.FloatString(2))

Output (try it on the Go Playground):

2023930943509509/1
2023930943509509.00


问:
Configure Ingress Kubernetes - accessible only on single node
I had setup ingress on my Kubernetes Cluster running on VMWAre virtual machines by following everything similar to the specifications here. All the ports are open and accessible.

https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example

My master is x.x.x.10 and nodes are x.x.x.12 and x.x.x.13.

After the creation of ingress/controllers, I need to get the IP where the nginx-controller runs

```<code>nginx-ingress-rc-kgfmd          1/1       Running   0          21h       172.16.5.5   x.x.x.12
</code>```

so, it usually runs either on x.x.x.12 or x.x.x.13, and then when I do this it hits my web service

curl --resolve  master.federated.fds:80:x.x.x.12 https://master.federated.fds/coffee

where master.federated.fds is the DNS resolvable name of Master.

I need to make it work without the help of IP address and only with the DNS resolvable name or else atleast with any of the node ip's

Eg: http://node2.federated.fds/coffee, when I curl this I get Connection refused error

Updating with specifications

```<code>apiVersion: v1
kind: Service
metadata:
  name: coffee-svc
  labels:
    app: coffee
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
#    nodePort: 30080
  type: NodePort
  selector:
    app: coffee
</code>```

ingress

```<code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
spec:
  rules:
  - host: jciamaster.federated.fds
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80
</code>```

nginx ing controller

```<code>    apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80
          hostPort: 80
</code>```

I see that the port 80 is listening only on the node where nginx pod runs and not on any other node. Could someone pls let me know how to access the application through all node ip's or thro a url like jciamaster.federated.fds?

Thanks,

Update:

Tried to run with nginx controller as svc as suggested by Marc

```<code>apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80

        # Uncomment the lines below to enable extensive logging and/or customization of
        # NGINX configuration with configmaps
        #args:
         #- -v=3
         #- -nginx-configmaps=default/nginx-config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: nginx-ingress-label
  name: nginx-ing-svc
spec:
  ports:
   - port: 80
     targetPort: 80
     protocol: TCP
     name: http
     nodePort: 30000
  type: NodePort
  selector:
    name: nginx-ingress
</code>```

When I hit http://x.x.x.:30000/coffee it just hangs and does nothing.Anything I am doing wrong?

答: You can expose the nginx controller Pod with a NodePort Service, then you can access it on all nodes.</p>

Body:
I had setup ingress on my Kubernetes Cluster running on VMWAre virtual machines by following everything similar to the specifications here. All the ports are open and accessible.

https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example

My master is x.x.x.10 and nodes are x.x.x.12 and x.x.x.13.

After the creation of ingress/controllers, I need to get the IP where the nginx-controller runs

nginx-ingress-rc-kgfmd          1/1       Running   0          21h       172.16.5.5   x.x.x.12

so, it usually runs either on x.x.x.12 or x.x.x.13, and then when I do this it hits my web service

curl --resolve  master.federated.fds:80:x.x.x.12 https://master.federated.fds/coffee

where master.federated.fds is the DNS resolvable name of Master.

I need to make it work without the help of IP address and only with the DNS resolvable name or else atleast with any of the node ip's

Eg: http://node2.federated.fds/coffee, when I curl this I get Connection refused error

Updating with specifications

apiVersion: v1
kind: Service
metadata:
  name: coffee-svc
  labels:
    app: coffee
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
#    nodePort: 30080
  type: NodePort
  selector:
    app: coffee

ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
spec:
  rules:
  - host: jciamaster.federated.fds
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80

nginx ing controller

    apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80
          hostPort: 80

I see that the port 80 is listening only on the node where nginx pod runs and not on any other node. Could someone pls let me know how to access the application through all node ip's or thro a url like jciamaster.federated.fds?

Thanks,

Update:

Tried to run with nginx controller as svc as suggested by Marc

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    app: nginx-ingress
spec:
  replicas: 1
  selector:
    app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      containers:
      - image: nginxdemos/nginx-ingress:0.8.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80

        # Uncomment the lines below to enable extensive logging and/or customization of
        # NGINX configuration with configmaps
        #args:
         #- -v=3
         #- -nginx-configmaps=default/nginx-config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: nginx-ingress-label
  name: nginx-ing-svc
spec:
  ports:
   - port: 80
     targetPort: 80
     protocol: TCP
     name: http
     nodePort: 30000
  type: NodePort
  selector:
    name: nginx-ingress

When I hit http://x.x.x.:30000/coffee it just hangs and does nothing.Anything I am doing wrong?


问:
Chart.js Date and Time Bar Chart Not Rendering - Line Works Though
I'm using Chart.js to create a datetime bar chart showing the number of players in multiple servers depending on the date and time of the last scan.  However, for some reason, the bar chart will not render.  If I use a line type chart, it renders just fine.  Anyone know why the bar chart will not render?  I don't have any console errors in developer tools.

Here's the fiddle:

https://jsfiddle.net/j3rmjzpw/2/

HTML:

```<code><canvas id='playerChartLine' width='800' height='400'></canvas>
<canvas id='playerChartBar' width='800' height='400'></canvas>
</code>```

Javascript / jQuery:

```<code>$( document ).ready(function() {
    renderChartJS("line", "playerChartLine", [{x: "2017-07-04T01:51:02-06:00", y: 240}, {x: "2017-07-04T10:51:02-06:00", y: 150}], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
    renderChartJS("bar", "playerChartBar", [{x: "2017-07-04T01:51:02-06:00", y: 240}, {x: "2017-07-04T10:51:02-06:00", y: 150}], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
});

function renderChartJS(chartType, elemId, data, title, xAxisLabel, yAxisLabel, rgbaColorStr, yMax){

    var ticksObj = {
        suggestedMin: 0,
        beginAtZero: true,
        stepValue: 50,
    }

    if(yMax != 0){
        ticksObj.max = yMax;
    }

    if(data.length){
        var ctx = document.getElementById(elemId).getContext('2d');
        var myChart = new Chart(ctx, {
            type: chartType,
            data: {
                datasets: [{
                    label: yAxisLabel,
                    data: data,
                    borderColor: "rgba(" + rgbaColorStr + ",1)",
                    backgroundColor: "rgba(" + rgbaColorStr + ",0.5)"
                }],
            },
            options: {
                responsive: false,
                maintainAspectRatio: true,
                scaleBeginAtZero: true,
                title:
                {
                    display: true,
                    text: title
                },
                scales: {
                    xAxes: [{
                        type: "time",
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: xAxisLabel
                        },
                        ticks: {
                            minRotation: 90,
                            maxRotation: 90,
                            stepValue: 10,
                            autoSkip: true,
                            maxTicksLimit: 50
                        },
                        time: {
                            unit: 'minute',
                            unitStepSize: 10,
                            max: data[data.length - 1].x
                        }
                    }],
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: yAxisLabel
                        },
                        ticks: ticksObj
                    }]
                }

            }
        });
    }
}
</code>```

The bottom chart should be the bar chart, but it is not rendering properly.

Anyone know what's happening?

答:
The issue is, bar chart doesn't support the type of data format, that you are providing.

You should rather use the following type of data format ...

```<code>renderChartJS("line", "playerChartLine", ["2017-07-04T01:51:02-06:00", "2017-07-04T10:51:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
renderChartJS("bar", "playerChartBar", ["2017-07-04T01:51:02-06:00", "2017-07-04T01:59:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
</code>```

here, third argument is for x-axis labels and the forth one is for data

and, here's the working version of your code, with this applied ...

$(document).ready(function() {
   renderChartJS("line", "playerChartLine", ["2017-07-04T01:51:02-06:00", "2017-07-04T10:51:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
   renderChartJS("bar", "playerChartBar", ["2017-07-04T01:51:02-06:00", "2017-07-04T01:59:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
});

function renderChartJS(chartType, elemId, labels, data, title, xAxisLabel, yAxisLabel, rgbaColorStr, yMax) {

   var ticksObj = {
      suggestedMin: 0,
      beginAtZero: true,
      stepValue: 50,
   }

   if (yMax != 0) {
      ticksObj.max = yMax;
   }

   if (data.length) {
      var ctx = document.getElementById(elemId).getContext('2d');
      var myChart = new Chart(ctx, {
         type: chartType,
         data: {
            labels: labels,
            datasets: [{
               label: yAxisLabel,
               data: data,
               borderColor: "rgba(" + rgbaColorStr + ",1)",
               backgroundColor: "rgba(" + rgbaColorStr + ",0.5)"
            }],
         },
         options: {
            responsive: false,
            maintainAspectRatio: true,
            scaleBeginAtZero: true,
            title: {
               display: true,
               text: title
            },
            scales: {
               xAxes: [{
                  type: "time",
                  display: true,
                  scaleLabel: {
                     display: true,
                     labelString: xAxisLabel
                  },
                  ticks: {
                     minRotation: 90,
                     maxRotation: 90,
                     stepValue: 10,
                     autoSkip: true,
                     maxTicksLimit: 50
                  },
                  time: {
                     unit: 'minute',
                     unitStepSize: 10,
                     max: data[data.length - 1].x
                  }
               }],
               yAxes: [{
                  display: true,
                  scaleLabel: {
                     display: true,
                     labelString: yAxisLabel
                  },
                  ticks: ticksObj
               }]
            }

         }
      });
   }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://github.com/chartjs/Chart.js/releases/download/v2.6.0/Chart.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id='playerChartLine' width='800' height='400'></canvas>
<canvas id='playerChartBar' width='800' height='400'></canvas></code>```

Body:
I'm using Chart.js to create a datetime bar chart showing the number of players in multiple servers depending on the date and time of the last scan.  However, for some reason, the bar chart will not render.  If I use a line type chart, it renders just fine.  Anyone know why the bar chart will not render?  I don't have any console errors in developer tools.

Here's the fiddle:

https://jsfiddle.net/j3rmjzpw/2/

HTML:

<canvas id='playerChartLine' width='800' height='400'></canvas>
<canvas id='playerChartBar' width='800' height='400'></canvas>

Javascript / jQuery:

$( document ).ready(function() {
    renderChartJS("line", "playerChartLine", [{x: "2017-07-04T01:51:02-06:00", y: 240}, {x: "2017-07-04T10:51:02-06:00", y: 150}], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
    renderChartJS("bar", "playerChartBar", [{x: "2017-07-04T01:51:02-06:00", y: 240}, {x: "2017-07-04T10:51:02-06:00", y: 150}], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
});

function renderChartJS(chartType, elemId, data, title, xAxisLabel, yAxisLabel, rgbaColorStr, yMax){

    var ticksObj = {
        suggestedMin: 0,
        beginAtZero: true,
        stepValue: 50,
    }

    if(yMax != 0){
        ticksObj.max = yMax;
    }

    if(data.length){
        var ctx = document.getElementById(elemId).getContext('2d');
        var myChart = new Chart(ctx, {
            type: chartType,
            data: {
                datasets: [{
                    label: yAxisLabel,
                    data: data,
                    borderColor: "rgba(" + rgbaColorStr + ",1)",
                    backgroundColor: "rgba(" + rgbaColorStr + ",0.5)"
                }],
            },
            options: {
                responsive: false,
                maintainAspectRatio: true,
                scaleBeginAtZero: true,
                title:
                {
                    display: true,
                    text: title
                },
                scales: {
                    xAxes: [{
                        type: "time",
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: xAxisLabel
                        },
                        ticks: {
                            minRotation: 90,
                            maxRotation: 90,
                            stepValue: 10,
                            autoSkip: true,
                            maxTicksLimit: 50
                        },
                        time: {
                            unit: 'minute',
                            unitStepSize: 10,
                            max: data[data.length - 1].x
                        }
                    }],
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: yAxisLabel
                        },
                        ticks: ticksObj
                    }]
                }

            }
        });
    }
}

The bottom chart should be the bar chart, but it is not rendering properly.

Anyone know what's happening?

Body:
The issue is, bar chart doesn't support the type of data format, that you are providing.

You should rather use the following type of data format ...

renderChartJS("line", "playerChartLine", ["2017-07-04T01:51:02-06:00", "2017-07-04T10:51:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
renderChartJS("bar", "playerChartBar", ["2017-07-04T01:51:02-06:00", "2017-07-04T01:59:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players

here, third argument is for x-axis labels and the forth one is for data

and, here's the working version of your code, with this applied ...

$(document).ready(function() {
   renderChartJS("line", "playerChartLine", ["2017-07-04T01:51:02-06:00", "2017-07-04T10:51:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
   renderChartJS("bar", "playerChartBar", ["2017-07-04T01:51:02-06:00", "2017-07-04T01:59:02-06:00"], [240, 150], "Total Number of Players Playing", "Date", "Players", "188,4,0", 0); // Number of players
});

function renderChartJS(chartType, elemId, labels, data, title, xAxisLabel, yAxisLabel, rgbaColorStr, yMax) {

   var ticksObj = {
      suggestedMin: 0,
      beginAtZero: true,
      stepValue: 50,
   }

   if (yMax != 0) {
      ticksObj.max = yMax;
   }

   if (data.length) {
      var ctx = document.getElementById(elemId).getContext('2d');
      var myChart = new Chart(ctx, {
         type: chartType,
         data: {
            labels: labels,
            datasets: [{
               label: yAxisLabel,
               data: data,
               borderColor: "rgba(" + rgbaColorStr + ",1)",
               backgroundColor: "rgba(" + rgbaColorStr + ",0.5)"
            }],
         },
         options: {
            responsive: false,
            maintainAspectRatio: true,
            scaleBeginAtZero: true,
            title: {
               display: true,
               text: title
            },
            scales: {
               xAxes: [{
                  type: "time",
                  display: true,
                  scaleLabel: {
                     display: true,
                     labelString: xAxisLabel
                  },
                  ticks: {
                     minRotation: 90,
                     maxRotation: 90,
                     stepValue: 10,
                     autoSkip: true,
                     maxTicksLimit: 50
                  },
                  time: {
                     unit: 'minute',
                     unitStepSize: 10,
                     max: data[data.length - 1].x
                  }
               }],
               yAxes: [{
                  display: true,
                  scaleLabel: {
                     display: true,
                     labelString: yAxisLabel
                  },
                  ticks: ticksObj
               }]
            }

         }
      });
   }
}

<script src="https://github.com/chartjs/Chart.js/releases/download/v2.6.0/Chart.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id='playerChartLine' width='800' height='400'></canvas>
<canvas id='playerChartBar' width='800' height='400'></canvas>


问:
Hiding a cardview using child webview in Android Studio
I am currently using android studio for a dashboard to visualize live data.

```<code><android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="190dp"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <WebView
                android:id="@+id/webviewCO2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="CO2"
                android:textAppearance="@style/TextAppearance.AppCompat.Title"
                android:textColor="@color/background_floating_material_dark"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp" />

            <TextView
                android:id="@+id/CO2_ti"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#000000"
                android:text="-"
                android:textSize="40dp"
                android:textAlignment="center"
                android:layout_marginTop="5dp" />

        </LinearLayout>

    </android.support.v7.widget.CardView>
</code>```

This is one of the components of my dashboard. However, some of the devices do not have a CO2 sensor and I would like to completely hide this in the view when that is the case.

When I have the webview, is there some sort of code to get the "parent element" just like in html so that I can set the visibility of the CardView to GONE?

I am currently able to get the webview like this

```<code>WebView webViewCO2;
webViewCO2 = (WebView) view.findViewById(R.id.webviewCO2);
</code>```

Is there somthing similar I cuold  do to get the cardView such that I can change its visibility? (Maybe if I gave the cardView an id?)

答:
```<code>CardView cardView = (CardView) view.findViewById(R.id.cv_id);
</code>```

and

```<code>cardView.setVisibility(View.GONE)
</code>```

did the trick

Body:
I am currently using android studio for a dashboard to visualize live data.

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="190dp"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <WebView
                android:id="@+id/webviewCO2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="CO2"
                android:textAppearance="@style/TextAppearance.AppCompat.Title"
                android:textColor="@color/background_floating_material_dark"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp" />

            <TextView
                android:id="@+id/CO2_ti"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#000000"
                android:text="-"
                android:textSize="40dp"
                android:textAlignment="center"
                android:layout_marginTop="5dp" />

        </LinearLayout>

    </android.support.v7.widget.CardView>

This is one of the components of my dashboard. However, some of the devices do not have a CO2 sensor and I would like to completely hide this in the view when that is the case.

When I have the webview, is there some sort of code to get the "parent element" just like in html so that I can set the visibility of the CardView to GONE?

I am currently able to get the webview like this

WebView webViewCO2;
webViewCO2 = (WebView) view.findViewById(R.id.webviewCO2);

Is there somthing similar I cuold  do to get the cardView such that I can change its visibility? (Maybe if I gave the cardView an id?)

Body:
CardView cardView = (CardView) view.findViewById(R.id.cv_id);

and

cardView.setVisibility(View.GONE)

did the trick


问:
Display data in html/js file using NodeJs from mysql database
My index.js file is

```<code>var express         = require('express');
var  app            = express();
var path            = require('path');
var router          = express.Router();
var data            = require('./data/jsonData');
var createDatabase  = require('./data/db');
var careateTable    = require('./data/createTable');
var insert          = require('./data/insert');
var bodyParser      = require('body-parser');
var select          = require('./data/select');

app.use(express.static(path.join(__dirname, 'www')));
app.use(express.static(path.join(__dirname, 'form')));
app.use(bodyParser());
app.get('/' , function (req , res) {
    res.sendFile(path.join(__dirname + '/www/index.html'));
});

app.get('/data' ,function (req , res) {
    res.json(data);
});
app.get('/form' ,function (req , res) {
    res.sendFile(path.join(__dirname + '/form/index.html'));
});
app.post('/form' ,function (req , res) {
    console.log(req.body.user);
    console.log(req.body.password);
    insert.insertModule(req.body.user , req.body.password);
    res.sendFile(path.join(__dirname + '/www/index.html'));
});
app.get('/show' , function (req , res) {
    var i ;
   select.select( function (err, results) {
       if (err == 'error') {
           console.log(err);
       } else {
           console.log(results);
           res.send(results.username);
       }
   });

});

app.listen(3000);
console.log("App is listning on port 3000");
</code>```

and select.js is

```<code>var mysql = require('mysql');
var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "NodeDataBase"
});
con.connect(function (err) {
    if (err) throw err;
    console.log("Connected!");
});

module.exports  = {
    select: function (callback) {
        var sql = "SELECT username , password FROM login ";
        con.query(sql, function (err, result , fields) {
            if (err) {
                callback("error", err)
            } else {
                callback("success", result)
            }
        });
    }
}
</code>```

I want to show the results object data to html file , So how can i do this please suggest me.

from a get request /show it will show all userdata fetched from the database

答:
I´ll try to explain the way it works (with the consideration on you are now able to see the data on 'http://localhost:3000/show') . Plz, guys, correct me if I do explain something in the wrong way.

There, what you have in your code, is the

Server side code

mysql: Declares connection to database (this is your database connector)

node.js: Declares methods to put/push/get data from database (your server side as is)

express.js: Declares urls to put/push/get data from database (http/https router)

Then, if we check the code, we can see the declaration of a server api - for example app.get('/show')

There, what you are saying is that express, will use the url /show with the method GET

Here is where your client appears in scene. Now, we suppose your server is up and running, waiting to serve GET petitions on http://localhost:3000/show.

If that is correct, when clicking the link you should see the user names, and now you will need an http client to connect to your http server side.

The way you can grab data on your HTML client from your server, is javascript.

Then, you will need to build an HTML file, that will also contain a javascript script (in my example written in angular).

The HTML (this is written in jade. you can convert it) should look like this:

Client HTML Code
  You should create an index.html file, and paste this code

```<code><!doctype html>
<html ng-app>
  <head>
    <title>My AngularJS App</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  <div ng-controller="MyCtrl">
    <table>
      <thead>
        <tr>
          <th>
            <p>Name</p>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="user in users">
          <td>
            <p>{{user}}</p>
          </td>
        </tr>
      </tbody>
    </table>
   </div>
    <script>
     var myApp = angular.module('myApp',[]);
     function MyCtrl($scope, $http) {
     //This method will call your server, with the GET method and the url /show
     $http.get("http://localhost:3000/show").then(function(success){
      if(success.data.length>0)
      {
         $scope.users=success.data;
      }
     });
     }
   </script>
  </body>
 </html>
</code>```

This code should capture the data and show a row in the table for every name in the database.

Hope it helps, at least as a clear explanation of how the full stack (client-server) works.

Body:
My index.js file is

var express         = require('express');
var  app            = express();
var path            = require('path');
var router          = express.Router();
var data            = require('./data/jsonData');
var createDatabase  = require('./data/db');
var careateTable    = require('./data/createTable');
var insert          = require('./data/insert');
var bodyParser      = require('body-parser');
var select          = require('./data/select');

app.use(express.static(path.join(__dirname, 'www')));
app.use(express.static(path.join(__dirname, 'form')));
app.use(bodyParser());
app.get('/' , function (req , res) {
    res.sendFile(path.join(__dirname + '/www/index.html'));
});

app.get('/data' ,function (req , res) {
    res.json(data);
});
app.get('/form' ,function (req , res) {
    res.sendFile(path.join(__dirname + '/form/index.html'));
});
app.post('/form' ,function (req , res) {
    console.log(req.body.user);
    console.log(req.body.password);
    insert.insertModule(req.body.user , req.body.password);
    res.sendFile(path.join(__dirname + '/www/index.html'));
});
app.get('/show' , function (req , res) {
    var i ;
   select.select( function (err, results) {
       if (err == 'error') {
           console.log(err);
       } else {
           console.log(results);
           res.send(results.username);
       }
   });

});

app.listen(3000);
console.log("App is listning on port 3000");

and select.js is

var mysql = require('mysql');
var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "NodeDataBase"
});
con.connect(function (err) {
    if (err) throw err;
    console.log("Connected!");
});

module.exports  = {
    select: function (callback) {
        var sql = "SELECT username , password FROM login ";
        con.query(sql, function (err, result , fields) {
            if (err) {
                callback("error", err)
            } else {
                callback("success", result)
            }
        });
    }
}

I want to show the results object data to html file , So how can i do this please suggest me.

from a get request /show it will show all userdata fetched from the database

Body:
I´ll try to explain the way it works (with the consideration on you are now able to see the data on 'http://localhost:3000/show') . Plz, guys, correct me if I do explain something in the wrong way.

There, what you have in your code, is the

Server side code

mysql: Declares connection to database (this is your database connector)

node.js: Declares methods to put/push/get data from database (your server side as is)

express.js: Declares urls to put/push/get data from database (http/https router)

Then, if we check the code, we can see the declaration of a server api - for example app.get('/show')

There, what you are saying is that express, will use the url /show with the method GET

Here is where your client appears in scene. Now, we suppose your server is up and running, waiting to serve GET petitions on http://localhost:3000/show.

If that is correct, when clicking the link you should see the user names, and now you will need an http client to connect to your http server side.

The way you can grab data on your HTML client from your server, is javascript.

Then, you will need to build an HTML file, that will also contain a javascript script (in my example written in angular).

The HTML (this is written in jade. you can convert it) should look like this:

Client HTML Code
  You should create an index.html file, and paste this code

<!doctype html>
<html ng-app>
  <head>
    <title>My AngularJS App</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  <div ng-controller="MyCtrl">
    <table>
      <thead>
        <tr>
          <th>
            <p>Name</p>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="user in users">
          <td>
            <p>{{user}}</p>
          </td>
        </tr>
      </tbody>
    </table>
   </div>
    <script>
     var myApp = angular.module('myApp',[]);
     function MyCtrl($scope, $http) {
     //This method will call your server, with the GET method and the url /show
     $http.get("http://localhost:3000/show").then(function(success){
      if(success.data.length>0)
      {
         $scope.users=success.data;
      }
     });
     }
   </script>
  </body>
 </html>

This code should capture the data and show a row in the table for every name in the database.

Hope it helps, at least as a clear explanation of how the full stack (client-server) works.


问:
Node.js, EventEmitter of why using it
I have a question about events.EventEmitter in Node.js, why use it? What is the difference with example 1 and example 2? I find them identical, are they? When is it practical to use it?

```<code>let events = require("events");
let util = require("util");
let eventEmitter = new events.EventEmitter();
</code>```

Example 1 with the EventEmitter:

```<code>let Student = function(name) {
    this.name = name;
}

util.inherits(Student, events.EventEmitter);

let student_max = new Student('max');

student_max.on('scored', function(points) {
    if (points > 90) {
        points = points + ' wow you scored more than 90'
    }
    console.log(`${this.name} ${points} points`);
})

student_max.emit('scored',95);
</code>```

Example 2 without EventEmitter

```<code>let Student2 = function(name) {
    this.name = name;
    this.score = function(str,points) {
        if (str!=='scored') {
            return;
        }
        if (points > 90) {
            points = points + ' wow you scored more than 90'
        }
        console.log(`${this.name} ${points} points`);
    }
}

let student_lenny = new Student2('Lenny');

student_lenny.score('scored',95);
</code>```

答:
The first example subclasses an event emitter and then uses that event emitter to implement some functionality.  That means that anyone else can take one of your student_max objects and register an event listener for the scored message or they could even emit a scored message themselves.  You could then very easily use the eventEmitter functionality to extend to other events that occurred in your object and then any third party could observe or trigger those events too. eventEmitter is a standardized way of exposing event based functionality.  You can accomplish things with an eventEmitter by designing your own notification schemes, but it is often better to build on a standard scheme that lots of developers already know and that has a fair amount of functionality already built in.

Your second example as currently coded accomplishes the same thing, but is not as extensible.  For example, if you wanted to know anything a score happens, you would have to subclass the object and override the score method rather than just adding a listener to an event using the well-established eventEmitter interface.  If you didn't create the object yourself (which makes it hard to subclass), then you'd have to monkey-patch the score method in order to observe it.

what is the difference of the example1 to example2

It's an architectural difference that affects both how outside agents interact with these objects and how extensible they are in the future.

The use of the eventEmitter in example1 is very extensible and makes it easy to add future events to the object using the eventEmitter features or for outside agents to monitor or trigger events using a standardized interface.  So, the difference is not in exactly what the code you show achieves, but in how it is architected and thus how extensible it would be in the future or how outside code could interact with your object

When is it practical to use it?

You would think about using an eventEmitter object pretty much anytime you want outside parties to be able to observe events or trigger events on your object in a lightweight and easy way.  It's a pre-built system for that and is often better than inventing your own callback notification scheme.  And sometimes, it is useful even for your own implementation when you aren't trying to enable outside interactions.

Title: Node.js, EventEmitter of why using it

Body:
I have a question about events.EventEmitter in Node.js, why use it? What is the difference with example 1 and example 2? I find them identical, are they? When is it practical to use it?

let events = require("events");
let util = require("util");
let eventEmitter = new events.EventEmitter();

Example 1 with the EventEmitter:

let Student = function(name) {
    this.name = name;
}

util.inherits(Student, events.EventEmitter);

let student_max = new Student('max');

student_max.on('scored', function(points) {
    if (points > 90) {
        points = points + ' wow you scored more than 90'
    }
    console.log(`${this.name} ${points} points`);
})

student_max.emit('scored',95);

Example 2 without EventEmitter

let Student2 = function(name) {
    this.name = name;
    this.score = function(str,points) {
        if (str!=='scored') {
            return;
        }
        if (points > 90) {
            points = points + ' wow you scored more than 90'
        }
        console.log(`${this.name} ${points} points`);
    }
}

let student_lenny = new Student2('Lenny');

student_lenny.score('scored',95);


问:
How to use Sql Server Service Broker with Java
I am writting my application in java and sql server. There are some libraries I need that are only available in java. So I am forced to use Java as my programming language. After some research I am unable to find official resources for java and sql server service broker. Is there a way to use java and work with sql server service broker?</p>

答: In short, yes. You can issue a receive statement from the queue to get messages and do with them what you will from there. You don't need to do anything special just because it's Java.


问:
Using JQuery methods to find the class. Using a JavaScript file in a rails application
The texts 'pearl' and 'diamond' are elements in an array stored in localStorage. I couldn't find any good resources to help me pull the data from localStorage so I can display and manipulate the data in rails. Thus, I wrote a function in my application.js file to help me find the texts and the surrounding classes.

Here's the info in html.

```<code><div class="ruby-gem">
  <a target="_blank" href="https://www.website.com/pearl">pearl</a>
  <img class="star-pic" src="/assets/star-gray.png" alt="star pic">
</div>
<div class="ruby-gem">
  <a target="_blank" href="https://www.website.com/diamond">diamond</a>
  <img class="star-pic" src="/assets/star-gray.png" alt="star pic">
</div>
</code>```

Here's my function in the application.js file. Right now the variable findSrc is undefined.

```<code>function checkStorage(){
  var storage = JSON.parse(localStorage.getItem("rubygems"))
  var gems = $(".ruby-gem a").map(function(){
    return $(this).text()
  }).get()
  for (var i = 0; i < gems.length; i++){
    if(storage.includes(gems[i])){
      var gemFavorite = gems[i]
      var findDiv = $("a:contains(gemFavorite)")
      var findImgClass = findDiv.next()
      var findSrc = $(findImgClass).find("img").attr("src")
      if(findSrc == "/assets/star-gray.png"){
        $(findImgClass).attr("src", "/assets/star-blue.png")
      }
    }
  }
}
</code>```

The ultimate goal is to change the image from a gray star to a blue star if the item(s) are located in localStorage. This is probably not the best way to do it but I couldn't figure out a nicer solution.

Any advice would be greatly appreciated.

答:
Why do you store them in localStorage? Where do 'pearl' and 'diamond' come from?

I could imagine something like they're data from the previous page?

If i were you i would store the array in the params, when it's only two we are talking about.

For example

I'm only guessing

Previous page:

```<code><a href="link_to_the_page_your_showing?#{{p: "pearl", d:"diamond"}.to_query}">
Go blue star!</a>
<!-- output in the url on next page: "d=diamond&p=pearl" -->
<a href="link_to_the_page_your_showing">Go boring gray star!</a>
</code>```

Your page:

```<code><!-- Using erb to manipulate the src in img -->
<div class="ruby-gem">
<a target="_blank" href="https://www.website.com/pearl">pearl</a>
<img class="star-pic" src="/assets/<%= params[:p] == "pearl" ? "star-
blue" : "star-gray" %>.png" alt="star pic">
</div>
<div class="ruby-gem">
<a target="_blank" href="https://www.website.com/diamond">diamond</a>
<img class="star-pic" src="/assets/<%= params[:d] == "diamond" ? "star-
blue" : "star-gray" %>.png" alt="star pic">
</div>
</code>```

Body:
The texts 'pearl' and 'diamond' are elements in an array stored in localStorage. I couldn't find any good resources to help me pull the data from localStorage so I can display and manipulate the data in rails. Thus, I wrote a function in my application.js file to help me find the texts and the surrounding classes.

Here's the info in html.

  pearl

  diamond

Here's my function in the application.js file. Right now the variable findSrc is undefined.

function checkStorage(){
  var storage = JSON.parse(localStorage.getItem("rubygems"))
  var gems = $(".ruby-gem a").map(function(){
    return $(this).text()
  }).get()
  for (var i = 0; i < gems.length; i++){
    if(storage.includes(gems[i])){
      var gemFavorite = gems[i]
      var findDiv = $("a:contains(gemFavorite)")
      var findImgClass = findDiv.next()
      var findSrc = $(findImgClass).find("img").attr("src")
      if(findSrc == "/assets/star-gray.png"){
        $(findImgClass).attr("src", "/assets/star-blue.png")
      }
    }
  }
}

The ultimate goal is to change the image from a gray star to a blue star if the item(s) are located in localStorage. This is probably not the best way to do it but I couldn't figure out a nicer solution.

Any advice would be greatly appreciated.

Body:
Why do you store them in localStorage? Where do 'pearl' and 'diamond' come from?

I could imagine something like they're data from the previous page?

If i were you i would store the array in the params, when it's only two we are talking about.

For example

I'm only guessing

Previous page:

<a href="link_to_the_page_your_showing?#{{p: "pearl", d:"diamond"}.to_query}">
Go blue star!</a>
<!-- output in the url on next page: "d=diamond&p=pearl" -->
<a href="link_to_the_page_your_showing">Go boring gray star!</a>

Your page:

<!-- Using erb to manipulate the src in img -->
<div class="ruby-gem">
<a target="_blank" href="https://www.website.com/pearl">pearl</a>
<img class="star-pic" src="/assets/<%= params[:p] == "pearl" ? "star-
blue" : "star-gray" %>.png" alt="star pic">
</div>
<div class="ruby-gem">
<a target="_blank" href="https://www.website.com/diamond">diamond</a>
<img class="star-pic" src="/assets/<%= params[:d] == "diamond" ? "star-
blue" : "star-gray" %>.png" alt="star pic">
</div>


问:
HTML/CSS - Iframe fit screen
I use the code below in order to display a youtube video. I set its size at 560 width and 315 height. Code works good but when I try to resize the window, the iframe/video doesn't resize but instead scrollbars appear. How can I make the iframe also resize so it always fits the width of the screen?</p>

```<code><body>
    <iframe width="560" height="315" src="https://www.youtube.com/embed/a3ICNMQW7Ok?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</body>
</code>```

答:
the given width and heights are fixed sizes. if you give them in percentage like 70%,80% it should resize with the window

    ```

Title: HTML/CSS - Iframe fit screen

Body:
the given width and heights are fixed sizes. if you give them in percentage like 70%,80% it should resize with the window

 <body>
        <iframe width="100%" height="500px" src="https://www.youtube.com/embed/a3ICNMQW7Ok?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </body>


问:
Laravel 'with' eager loading scope
using this eager loading:

```<code>$lang = in_array($lang,$languages) ? $lang : 'en';

    $requirements = Requirement::with([
            'countryMatch',
            'applier' => function ($query) { $query->select('id','passport_type','office_id','citizenship_id')->groupBy('citizenship_id');},
            'doc.translation' => function ($query) { $query->where('language',$lang);}])->get();
</code>```

I am trying to use the variable $lang defined at the beginning inside the 'with statement' but I always get:

```<code>Undefined variable: lang
</code>```

答:
Try this, pass your variable by using the use keyword to the closure:

```<code>$requirements = Requirement::with([
    'countryMatch',
    'applier' => function ($query) {
        $query->select('id','passport_type','office_id','citizenship_id')->groupBy('citizenship_id');
    },
    'doc.translation' => function ($query) use ($lang) {
        $query->where('language',$lang);
    }
])->get();
</code>```

Title: Laravel 'with' eager loading scope

Body:
using this eager loading:

$lang = in_array($lang,$languages) ? $lang : 'en';

    $requirements = Requirement::with([
            'countryMatch',
            'applier' => function ($query) { $query->select('id','passport_type','office_id','citizenship_id')->groupBy('citizenship_id');},
            'doc.translation' => function ($query) { $query->where('language',$lang);}])->get();

I am trying to use the variable $lang defined at the beginning inside the 'with statement' but I always get:

Undefined variable: lang

Body:
Try this, pass your variable by using the use keyword to the closure:

$requirements = Requirement::with([
    'countryMatch',
    'applier' => function ($query) {
        $query->select('id','passport_type','office_id','citizenship_id')->groupBy('citizenship_id');
    },
    'doc.translation' => function ($query) use ($lang) {
        $query->where('language',$lang);
    }
])->get();


问:
CSS: Let a child element with variable height and position absolute end at the top of the parent element?
In a website I have a "dropup" menu at the bottom of a website.

Have a look at the following fiddle:

body {
    background-color: #ccc;
}
ul {
    list-style-type:none;
    width:200px;
}
.spacer {
    height:150px;
    width:auto;
}
ul,li {
    margin:0;
    padding:0;
}
a {
    color:#fff;
    width:200px;
    background-color:#e4003d;
}
ul li a {
    text-decoration: none;
    display: block;
    padding: 10px;
}

ul li ul {
    z-index: 8888;
    position: absolute;
    background-color: #fff;
    display: none;
}

ul:hover li ul, ul:focus li ul {
    display:block;
}

ul li ul li {
    background-color: #fff;
    color: #e4003d;
    background-image: none;
}
ul li ul li a {
    background-color: #fff;
    color: #e4003d;
    background-image: none;
}

ul li ul li a:hover, ul li ul li a:focus {
    background-color: #e4003d;
    color: #fff !important;
}

ul li ul {
    margin-top: -100px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="spacer"></div>
<ul class="page-switcher">
  <li>
    Sitamet
    <ul>
      <li>Lorem</li>
      <li>Ipsum</li>
      <li>Dolor</li>
    </ul>
  </li>
</ul>
<div class="spacer"></div></code>```

When the menu is hovered I want the submenu to end exactly at the top of the ul.page-switcher. There is no information about the number of items within the menu or their height.

In the example I have used margin-top:-100px; but this is just for demonstration as the number of pixels is not fixed.

Need a CSS only solution and should keep the position absolute. How would you solve this?

答:
You have to put a min-height and position relative to the first li element.

The submenue you have to set position absolute and bottom 0

Body:
In a website I have a "dropup" menu at the bottom of a website.

Have a look at the following fiddle:

body {
    background-color: #ccc;
}
ul {
    list-style-type:none;
    width:200px;
}
.spacer {
    height:150px;
    width:auto;
}
ul,li {
    margin:0;
    padding:0;
}
a {
    color:#fff;
    width:200px;
    background-color:#e4003d;
}
ul li a {
    text-decoration: none;
    display: block;
    padding: 10px;
}

ul li ul {
    z-index: 8888;
    position: absolute;
    background-color: #fff;
    display: none;
}

ul:hover li ul, ul:focus li ul {
    display:block;
}

ul li ul li {
    background-color: #fff;
    color: #e4003d;
    background-image: none;
}
ul li ul li a {
    background-color: #fff;
    color: #e4003d;
    background-image: none;
}

ul li ul li a:hover, ul li ul li a:focus {
    background-color: #e4003d;
    color: #fff !important;
}

ul li ul {
    margin-top: -100px;
}

    Sitamet

Lorem

Ipsum

Dolor

When the menu is hovered I want the submenu to end exactly at the top of the ul.page-switcher. There is no information about the number of items within the menu or their height.

In the example I have used margin-top:-100px; but this is just for demonstration as the number of pixels is not fixed.

Need a CSS only solution and should keep the position absolute. How would you solve this?


问:
How to calculate the last friday of the month with momentjs
How could I calculate the last friday of this month using the momentjs api?</p>

答:
I tried testing multiple months and for few months above answer by @afternoon did not work. Below is the test code.(one such test is for Aug 2018)

```<code>var moment  = require('moment')
var affirm  = require("affirm.js")
var cc = moment(Date.now())
for (var i = 0; i < 100000; i++) {
    lastFridayForMonth(cc)
    var nextWeek = moment(cc).add(7, 'days')
    console.log(cc.format("ddd DD MMM YYYY"), nextWeek.format('MMM'))
    affirm((cc.month() - nextWeek.month()) === -1 || (cc.month() - nextWeek.month()) === 11, "1 month gap is not found")
    affirm(cc.day() === 5, "its not friday")
    cc.add(1, "months")
}
</code>```

I have put another solution

```<code>function lastFridayForMonth(monthMoment) {
    var month = monthMoment.month()
    monthMoment.endOf("month").startOf("isoweek").add(4, "days")
    if (monthMoment.month() !== month) monthMoment.subtract(7, "days")
}
</code>```

Body:
I tried testing multiple months and for few months above answer by @afternoon did not work. Below is the test code.(one such test is for Aug 2018)

var moment  = require('moment')
var affirm  = require("affirm.js")
var cc = moment(Date.now())
for (var i = 0; i < 100000; i++) {
    lastFridayForMonth(cc)
    var nextWeek = moment(cc).add(7, 'days')
    console.log(cc.format("ddd DD MMM YYYY"), nextWeek.format('MMM'))
    affirm((cc.month() - nextWeek.month()) === -1 || (cc.month() - nextWeek.month()) === 11, "1 month gap is not found")
    affirm(cc.day() === 5, "its not friday")
    cc.add(1, "months")
}

I have put another solution

function lastFridayForMonth(monthMoment) {
    var month = monthMoment.month()
    monthMoment.endOf("month").startOf("isoweek").add(4, "days")
    if (monthMoment.month() !== month) monthMoment.subtract(7, "days")
}


问:
How maven packages snapshot dependencies?
I am working on a big project with many maven dependencies where some of them may be transitive ones.

I would like to know how maven packages the SNAPSHOT dependencies, because when I open an artifact I see that sometimes the libraries are packaged with SNAPSHOT in their name and other times there is a timestamp, like in this picture:

What worries me the most is that even packaging with -U argument the SNAPSHOT libraries not always correspond to the latest version available on the repository.

In the pom.xml the dependency versions are always ending in "-SNAPSHOT" and we are using maven 3.3.3.

答:
Snapshots are handled differently in local repository and in remote repositories.

The mvn install installs SNAPSHOTS as -SNAPSHOT to the local repository which is fine for local builds. The remote repositories contains the SNAPSHOT versions with timestamps as they are results of mvn deploy.

During local builds these two can mix as it is possible that one artifact is the result of the local build (-SNAPSHOT) and the other is downloaded from a remote repository (-20170623.063055-4).

The real problem is that they can mix in an unexpected way. Maven tries its best to obtain the latest SNAPSHOT from any available repository. This will most likely happen when you use the -U as it forces the check on remote repositories.

Sometimes this results an error: lib-a and lib-b are both dependencies, you built both 5 min ago, however the CI built lib-a 3 min ago then the build will use the CI lib-a and your lib-b as the CI has a newer version. If you modified something in the lib-a but the CI's lib-a does not contain it as it is not yet committed then it will be a very annoying issue.

The best strategy is to avoid deploying snapshots to remote repositories.

This is a good article regarding the repository internals: https://blog.packagecloud.io/eng/2017/03/09/how-does-a-maven-repository-work/

Also there is a related SO answer: https://stackoverflow.com/a/32416454/8230378


问:
How to create an attribute that can inspect method parameters and return value?
I want to be able to put an attribute on a method and have that method inspect the method parameters and the return value.  Pseudo code.

```<code>[AttributeUsage(AttributeTargets.Method)]
class MyAttribute: Attribute {
   public void MethodEnter(MethodInfo info) {
      foreach (var param in info.MethodParameters {
        Console.WriteLine(param.ToString());
      }
   }

   public void MethodLeave(MethodInfo info) {
      Console.WriteLine(info.ReturnValue);
   }
}

public class MyClass {
  [MyAttribute]
  public SomeType foo(Order order, List<OrderLine> orderLines) {
     ...
  }
}
</code>```

Is this possible?

Basically, I want to be able to log everything that comes in and leaves the function.  I've done this previously with PostSharp, but it seems like an overkill to use it for logging.

答:
You basicaly looking for AOP (Aspect Oriented Programming) solution. PostSharp uses IL injection in your binaries after compilation and in my opinion, this is worst framework I worked with.

Instead of looking into some very complex solution I recommend you to decorate your classes. For example:

```<code>public MyClass : IMyClass
{
    public object[] MyMethod(object[] args){...}
}

public LoggerDecoratedMyClass : IMyClass
{
    private readonly IMyClass _inner;
    private readonly ILogger _logger;
    public LoggerDecoratedMyClass(IMyClass inner, ILogger logger)
    {
        _inner = inner;
        _logger = logger;
    }

    public object[] MyMethod(object[] args)
    {
        try
        {
            var result = _inner.MyMethod(args);
            _logger.LogSuccess(...);
            return result;
        }
        catch (Exception ex)
        {
            _logger.LogError(..., ex);
            throw;
        }
    }
}
</code>```

This looks a lot better than attribute bindings, and provide you with ability to control your Aspect dependecies. Also, it forces you to write interface oriented code.

UPDATE

Also, I often use scope logging:

```<code>internal struct ScopeLogger : IDisposable
{
    private readonly string _name;
    public ScopeLogger(ILogger logger, string scopeName, object[] args)
    {
        _name = scopeName;
        _logger = logger;
        _logger.LogInfo("Begin {name}: {args}", _name, args);
    }
    public void Dispose()
    {
        _logger.LogInfo("End {name}",_name);
    }
}

public static IDisposable LogScope(this ILogger logger, string name, params object[] args)
{
    return new ScopeLogger(logger, name, args);
}
</code>```

And simply use it like this:

```<code>public LoggerDecoratedMyClass : IMyClass
{
    private readonly IMyClass _inner;
    private readonly ILogger _logger;
    public LoggerDecoratedMyClass(IMyClass inner, ILogger logger)
    {
        _inner = inner;
        _logger = logger;
    }

    public object[] MyMethod(object[] args)
    {
        using(_logger.LogScope(nameof(MyMethod), args))
        {
            return _inner.MyMethod(args);
        }
    }
}
</code>```

Decorators this way looks a lot better and shorter.

Body:
I want to be able to put an attribute on a method and have that method inspect the method parameters and the return value.  Pseudo code.

[AttributeUsage(AttributeTargets.Method)]
class MyAttribute: Attribute {
   public void MethodEnter(MethodInfo info) {
      foreach (var param in info.MethodParameters {
        Console.WriteLine(param.ToString());
      }
   }

   public void MethodLeave(MethodInfo info) {
      Console.WriteLine(info.ReturnValue);
   }
}

public class MyClass {
  [MyAttribute]
  public SomeType foo(Order order, List<OrderLine> orderLines) {
     ...
  }
}

Is this possible?

Basically, I want to be able to log everything that comes in and leaves the function.  I've done this previously with PostSharp, but it seems like an overkill to use it for logging.

Body:
You basicaly looking for AOP (Aspect Oriented Programming) solution. PostSharp uses IL injection in your binaries after compilation and in my opinion, this is worst framework I worked with.

Instead of looking into some very complex solution I recommend you to decorate your classes. For example:

public MyClass : IMyClass
{
    public object[] MyMethod(object[] args){...}
}

public LoggerDecoratedMyClass : IMyClass
{
    private readonly IMyClass _inner;
    private readonly ILogger _logger;
    public LoggerDecoratedMyClass(IMyClass inner, ILogger logger)
    {
        _inner = inner;
        _logger = logger;
    }

    public object[] MyMethod(object[] args)
    {
        try
        {
            var result = _inner.MyMethod(args);
            _logger.LogSuccess(...);
            return result;
        }
        catch (Exception ex)
        {
            _logger.LogError(..., ex);
            throw;
        }
    }
}

This looks a lot better than attribute bindings, and provide you with ability to control your Aspect dependecies. Also, it forces you to write interface oriented code.

UPDATE

Also, I often use scope logging:

internal struct ScopeLogger : IDisposable
{
    private readonly string _name;
    public ScopeLogger(ILogger logger, string scopeName, object[] args)
    {
        _name = scopeName;
        _logger = logger;
        _logger.LogInfo("Begin {name}: {args}", _name, args);
    }
    public void Dispose()
    {
        _logger.LogInfo("End {name}",_name);
    }
}

public static IDisposable LogScope(this ILogger logger, string name, params object[] args)
{
    return new ScopeLogger(logger, name, args);
}

And simply use it like this:

public LoggerDecoratedMyClass : IMyClass
{
    private readonly IMyClass _inner;
    private readonly ILogger _logger;
    public LoggerDecoratedMyClass(IMyClass inner, ILogger logger)
    {
        _inner = inner;
        _logger = logger;
    }

    public object[] MyMethod(object[] args)
    {
        using(_logger.LogScope(nameof(MyMethod), args))
        {
            return _inner.MyMethod(args);
        }
    }
}

Decorators this way looks a lot better and shorter.


问:
CheckBox in Nativescript (ios and Android)
What is the best way to create checkbox in Nativescript with javascript?

I know if I use checkbox it's only for Android, and I have problems with the switches. So I will like use images to reproduce a checkbox.

I have this XML

```<code><ListView items="{{ whishList }}">
        <ListView.itemTemplate>
            <GridLayout class="listes" columns="auto,*,30">
                <Image id="id_check" src="res://selectoff" tap="CheckList"/>
                <Label id="id_wishlist" text="{{ id_wishlist }}"/>
            </GridLayout>
        </ListView.itemTemplate>
    </ListView>
</code>```

If I tap the image, I would Like to change the image of item.
And with JS I need to change the image, but this changes only the last item:

```<code>exports.CheckList = function(args){var customControl = args.object;
  customControl.bindingContext = whishList;
  var checkID = customControl.parent.parent.getViewById("id_check");
  checkID.src ="res://selecton";
}
</code>```

答:
My solution is the following</p>

```<code>var customControl = args.object;
var checkID = customControl.parent.getViewById("id_check");
checkID.src ="res://checkon";
</code>```

Body:
What is the best way to create checkbox in Nativescript with javascript?

I know if I use checkbox it's only for Android, and I have problems with the switches. So I will like use images to reproduce a checkbox.

I have this XML

<ListView items="{{ whishList }}">
        <ListView.itemTemplate>
            <GridLayout class="listes" columns="auto,*,30">
                <Image id="id_check" src="res://selectoff" tap="CheckList"/>

            </GridLayout>
        </ListView.itemTemplate>
    </ListView>

If I tap the image, I would Like to change the image of item.
And with JS I need to change the image, but this changes only the last item:

exports.CheckList = function(args){var customControl = args.object;
  customControl.bindingContext = whishList;
  var checkID = customControl.parent.parent.getViewById("id_check");
  checkID.src ="res://selecton";
}

Body:
My solution is the following

var customControl = args.object;
var checkID = customControl.parent.getViewById("id_check");
checkID.src ="res://checkon";


问:
Filter in pie chart not working SSRS
For some reason, I am unable to get the filter functionality to work properly. I have 4 options labeled as A, B, C, D. Then I have the values being represented in the chart are points.

I go to Chart Properties and then the Data tab. I go to category and select Edit and then to Filters.

Here I select
Expression as =Fields!options.Value
Operator as =
Value as A

I want to make a pie graph of just Option A against the whole. When I use the settings above, the graph does not even show. If I take out the filter, the graph shows all 4 Options

```<code>I tried value
<br>=A <br>
"A" <br>
="A" <br>But nothing works.
</code>```

Can someone help me in this.

答: A work around for this would be to put your options into a parameter and then set the filter for the graph to equate to the parameter selected.</p>

Title: Filter in pie chart not working SSRS

Body:
For some reason, I am unable to get the filter functionality to work properly. I have 4 options labeled as A, B, C, D. Then I have the values being represented in the chart are points.

I go to Chart Properties and then the Data tab. I go to category and select Edit and then to Filters.

Here I select
Expression as =Fields!options.Value
Operator as =
Value as A

I want to make a pie graph of just Option A against the whole. When I use the settings above, the graph does not even show. If I take out the filter, the graph shows all 4 Options

I tried value

=A

"A"

="A"
But nothing works.

Can someone help me in this.


问:
Creating a dataframe from a scraped character vector
I am trying to create a dataframe that has the columns: First name, Last name, Party, State, Member ID. Here is my code

```<code>library('rvest')

candidate_url <- 'https://www.congress.gov/help/field-values/member-bioguide-ids'
candidate_page <- read_html(candidate_url)
candidate_nodes <- html_nodes(candidate_page, 'table')
candidate_list <- html_text(candidate_nodes)
</code>```

My main issue is getting the member IDs. An example ID is A000009. When I use the gsub function I lose the leading A in this example. The A is from this candidate's last name (Abercrombie), but I do not know how to add the A back into the member ID. Of course if there's a better way I am open to any suggestions.

答:
This is a bit hackish, but if you want to extract the variables using regex here are a few pointers.</p>

```<code>candidate_list <- unlist(candidate_list)

ID <- regmatches(candidate_list,
  gregexpr("[a-zA-Z]{1}[0-9]{6}", candidate_list))

party_state <- regmatches(candidate_list,
  gregexpr("(?<=\\()[^)]+(?=\\))", candidate_list, perl=TRUE))

names_etc <- strsplit(candidate_list, "[a-zA-Z]{1}[0-9]{6}")

names <- sapply(names_etc, function(x) sub(" \\([^)]*\\)", "", x))
</code>```

Body:
I am trying to create a dataframe that has the columns: First name, Last name, Party, State, Member ID. Here is my code

library('rvest')

candidate_url <- 'https://www.congress.gov/help/field-values/member-bioguide-ids'
candidate_page <- read_html(candidate_url)
candidate_nodes <- html_nodes(candidate_page, 'table')
candidate_list <- html_text(candidate_nodes)

My main issue is getting the member IDs. An example ID is A000009. When I use the gsub function I lose the leading A in this example. The A is from this candidate's last name (Abercrombie), but I do not know how to add the A back into the member ID. Of course if there's a better way I am open to any suggestions.

Body:
This is a bit hackish, but if you want to extract the variables using regex here are a few pointers.

candidate_list <- unlist(candidate_list)

ID <- regmatches(candidate_list,
  gregexpr("[a-zA-Z]{1}[0-9]{6}", candidate_list))

party_state <- regmatches(candidate_list,
  gregexpr("(?<=\\()[^)]+(?=\\))", candidate_list, perl=TRUE))

names_etc <- strsplit(candidate_list, "[a-zA-Z]{1}[0-9]{6}")

names <- sapply(names_etc, function(x) sub(" \\([^)]*\\)", "", x))


问:
Angularjs. I need to take out the a.txt and b.txt and c.txt in the string "a.txt,b.txt,c.txt," ignore commas using angularjs
json result the string "a.txt,b.txt,c.txt," in model.File
string[] arr = "{{model.File}}".Trim(',').Split(new char[] { ',' });

I use in cshtml is that but in angularjs I do not know how to use it

答:
Are you looking for an array of filenames? If so, you can use Javascript's  string.split() function:</p>

```<code>var filenames = str.split(',');
</code>```

Body:
Are you looking for an array of filenames? If so, you can use Javascript's  string.split() function:

var filenames = str.split(',');