Does ruby has a feature like socksProxy in java? - ruby

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.

Related

Executing Perl/CGI script in AJAX without using server

I am having a Perl and a CGI file through which I want to fetch data from database. I've a UI where I am trying to use AJAX call which will hit the perl (.pl) or (.cgi) file and get the response in JSON. I've checked the perl/cgi file by running through command prompt and it works fine. This is how I am running my code in command prompt:
D:\>PerlExecutables\strawberry_32\perl\bin\perl.exe C:\Users\UserXYZ\Desktop\PerlExamples\test.cgi
The reason is I cannot do any kind of installation on my machine and also I don't want to run it through server like Apache or IIS.
How can this be achieved? Is there any way to make the script work in AJAX by passing the perl.exe path for execution or Any other alternatives?
Thanks!
One way to do this is to use Plack::App::CGIBin. It allows you to mount CGI scripts as apps with the PSGI/Plack protocol.
use Plack::App::CGIBin;
use Plack::Builder;
my $app = Plack::App::CGIBin->new(root => "/path/to/cgi-bin")->to_app;
builder {
mount "/cgi-bin" => $app;
};
Save that as myapp.psgi (or whatever your stuff is called) and run it like this:
$ plackup myapp.psgi
By default it will open up a server on port 3000 on localhost. You will need to be able to install Perl modules. Since you have Strawberry Perl that shouldn't be a problem. In the worst case, just use a local::lib.
You will also need to be able to open a port for listening. If you cannot there is no other solution than to get an admin to install you an actual full-scale web server.
The PSGI protocol and the Plack tools are a simple, easy to use replacement for CGI. They allow you to be very flexible while making it easy to have persistently running large applications.

Get variable from PuppetMaster config from ruby functions

I wrote simple function for my puppet module. It makes some requests using puppetdb API and I need IP address of puppetdb server. Is there correct way to get settings of connection PuppetMaster to puppetdb to get address of puppetdb server or I should parse puppet.conf by hand?
Parsing puppetdb.conf by hand would be the least desirable way to go about it.
Looking at the code that loads the config, it should be possible to access it using
settings_value = Puppet::Util::Puppetdb.config['main'][setting_name]
for configuration options from the [main] section.
Looking at even more code, you should even be able to use
Puppet::Util::Puppetdb.server
Puppet::Util::Puppetdb.port
I'm not entirely sure whether those APIs are available from parser functions, but it's worth a shot.

Ruby server won't start with neography

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.

How do I perform a DNS zone transfer (AXFR) using Ruby 1.9?

I'm trying to do a DNS zone transfer and would like to do it using Ruby 1.9. Are there any gems built-in or otherwise that will do this simply?
Take a look at Dnsruby.
If it doesn't do what you need, the author is still maintaining it.
Although I tried dnsruby, I found net-dns to be more intutive.
net-dns is a close port of the Net::DNS from perl, and shares almost all the same methods.
dnsruby ended up being extremely verbose just to do a simple zone transfer.
Installing net-dns was as simple as "gem install net-dns". After creating a new Net::DNS::Resolver object, I used #axfr to perform the zone transfer which worked nicely.
In cases where zone transfer wasn't enabled, I simply used #query or #search.

Is it possible to run Mongo client shell query/commands from Ruby?

Could I use the Mongo client shell queries/commands from inside Ruby?
I know there is the Ruby driver DSL, but I was thinking about something similar to running a SQL query from within PHP.
Just for the sake of knowing.
You can always work directly with the MongoDB Ruby driver. Read this tutorial for more information.

Resources