Ruby server won't start with neography - ruby

I have ruby file which im running in my mac with OSX 10.9 that is a combination of sinatra and geography which i have both installed. when i use require 'sinatra' on the file everything is fine, but when i insert require 'neography' it gives me this error when trying to run the file.
/Users/AJ/.rvm/gems/ruby-2.1-head/gems/sinatra-1.4.4/lib/sinatra/base.rb:1488:in `start_server': undefined method `run' for HTTP:Module (NoMethodError)
from /Users/AJ/.rvm/gems/ruby-2.1-head/gems/sinatra-1.4.4/lib/sinatra/base.rb:1426:in `run!'
from /Users/AJ/.rvm/gems/ruby-2.1-head/gems/sinatra-1.4.4/lib/sinatra/main.rb:25:in `block in <module:Sinatra>'
What could be a possible reason for this error? Thanks in advance

Neography depends on httpclient, which in turn defines a module named HTTP.
When Sinatra tries to determine which server to use one of the options it tries is the net-http-server, whose Rack handler class is also named HTTP. This causes a name collision where Sinatra thinks the HTTP module in httpclient is the net-http-server and tries to run it as such, causing the error you see.
If you have another server installed, e.g. Thin, it will likely be detected before HTTP so you won’t see this error, but you are probably better explicitly setting the server to use. You can add something like
set :server, thin
to your application file to specify Thin as your server (you’ll need to install the thin gem first – you could also use Webrick). You could also specify this on the command line if you wanted: ruby my_app.rb -s thin, but I think you’d be better of adding it to your code to avoid problems in the future.

Related

Does ruby has a feature like socksProxy in java?

When I write a program in java, I use -DsocksProxyHost, -DsockProxyPort options to proxy all my network request to the specified address.
Does ruby has a feature like that?
I know there are Proxy class in ruby. However, I do not think I can utilize it when I want to connect to oracle database.
You can do this with JRuby using the -J flag which passes options to the JVM:
jruby -J-DsocksProxyHost=domain program.rb
MRI/Rubinius don't have a similar flag, but you can use a gem like proxifier or socksify to do the dirty work for you.

ruby neo4j session persistence

I'm using neo4j in a Ruby CLI app.
Each time a command is run from the command line, "session = Neo4j::Session.open(:server_db)" is re-established which is quite slow.
Is there anyway to persist the "session" first time use and re-use it in subsequent command invocations from the command line.
Regards
The neo4j-core gem uses the faraday gem to make persistent HTTP connections. That's defined here:
https://github.com/neo4jrb/neo4j-core/blob/master/lib/neo4j-server/cypher_session.rb#L24
That uses the NetHttpPersistent Faraday adapter here:
https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http_persistent.rb
Which I believe uses the net-http-persistent library:
https://github.com/drbrain/net-http-persistent
When calling open on Session, you can pass in a second argument Hash of options. You can specify a connection key in that hash which is a Faraday connection object which you've created. That might allow you to save some token/string somewhere and the reload the Faraday object each time from that to pick up the session from where it left off.
The other option is to have a daemon in the background which has the connection open

ACR1222L and Ruby smartcard gem

I'm trying to make a ACR1222L work with this ruby script that I found on github.
The script is made for the older ACR122U, but in my research I've seen that they both should be pretty similar.
My problem is when trying to run the script, I get this error:
C:\Users\Emil\Desktop>driver.rb
Calibration Time!
Place and leave a tag on the device
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/smartcard-0.5.5/lib/smartcard/pcsc/conte
xt.rb:112:in `wait_for_status_change': (0x100000006) (Smartcard::PCSC::Exception)
from C:/Users/Emil/Desktop/driver.rb:24:in `<main>'
Could it be that the "smartcard" gem used by the script does not support the ACR1222L, or am I simply just missing something?
Hope that someone can help!
The Smartcard::PCSC::Exception error code you get (0x100000006) translates to the Windows API error code INVALID_HANDLE_EXCEPTION (0x00000006). This typically indicates that the context handle used in the API call is invalid. With the smartcard gem, the PS/SC context (SCardEstablishContext) is established through the initializer of Smartcard::PCSC::Context. This operation seems to be successful, otherwise you would get an exception on line 13. The source of the INVALID_HANDLE_EXCEPTION seems to be SCardGetStatusChange (invoked by context.wait_for_status_change).
A possible reason for that call to fail with an INVALID_HANDLE_EXCEPTION could be a mismatch in the handle format, for instance caused by a 32-bit/64-bit mismatch. Thus, I would assume that the smartcard gem is designed for 32-bit only (while your path indicates that you are using a 64-bit version of Ruby).

Mongo Ruby :connecttimeoutms disappeared?

I've been using the connection option :connecttimeoutms when setting up MongoDB connections using the mongodb ruby gem. Like so:
connection = Connection.from_uri(uri, :connecttimeoutms => connect_timeout)
Now getting warnings that
connecttimeoutms is not a valid option for Mongo::Connection
since a recent bundle update.
Has this disappeared? Does anyone know what I should replace it with?
#sumskyi is absolutely right of course
After such investigation it seems it is now :connect_timeout and is measured in seconds
Thanks

Is it possible to run locally JRuby on Google App Engine without restarting server on every change?

Unfortunately, GAE requires restart of the server on each code change.
Is it possible to prevent it and have immediate feedback after code save?
Or, can I import Google App Engine's API into my ruby code and run it on Sinatra server? Tried this but it fails on "import com.google.appengine.api" (it doesn't know what 'com' is).
For Sinatra, I use "Rerun" ( http://github.com/alexch/rerun ) which restarts server immediately after a change with minimum wait.
Thanks.
Try http://github.com/rkh/sinatra-reloader
OK, seems like JRuby on Rails doesn't need server restart, Sinatra reloaded/shotgun plugins didn't work well for me.
To run it I copied the files from http://rails-depot.appspot.com/src (the source # http://code.google.com/p/appengine-jruby/source/browse did not contain all the files).

Resources