Mongo gem how to db.currentOp - ruby

How can I do db.currentOp() via the ruby Mongo gem?
Cant seem to find that in the gem api and documentation
Is it supported?
if not Is there a gem that does support that?

Looking at the definition of currentOp in the JS console, it looks very internal to me.
> db.currentOp
function ( arg ){
var q = {}
if ( arg ) {
if ( typeof( arg ) == "object" )
Object.extend( q , arg );
else if ( arg )
q["$all"] = true;
}
return this.$cmd.sys.inprog.findOne( q );
}
Besides, official mongo ruby driver doesn't contain "currentOp", "current_op", "inprog" or any other similar term. Based on this I must conclude that it's not supported.

You can send manual commands to the driver using the command call:
conn.command(currentOp: 1)
Should do that for you.

Related

How do I export contents between xml tags based on names in Extendscript for Indesign?

All I'd like to do here is open an InDesign 2018 CC file, pull out text uniquely (here I've chosen to grab content inside XML tag called "Title" from named tag window in the InDesign application side), save it to a txt file, and close the InDesign doc. I'm working in the Extendscript app, using Adobe InDesign CC 2018 (13.064). I just need to push to a txt file only certain named data (textboxes, xmltags, pageitems, etc) the contents based on anything, but via the name of the data holder. But xmltags are the only objects that I can name in the InDesign app apart from layers, and layers won't work for other reasons. So I'm stuck not being able to refer to xml-tagged contents. Please help.
Note:
I get an error with this code saying "Title" isn't defined, and I understand the error, but not sure how to utilize the method XML.toString() without referring to an object that's named inside the InDesign file. So I guess I'm using the wrong method to refer to xml-tagged data already located in a file??
So naturally, I throw out XML.toString() and utilize the commented out code (below) "app.activeDocument.xmlItems.item;" thinking maybe I will get an array of all items that are xml tagged, which is not even specific enough for my goal, but I'm desperate, and I get another newer error regarding the "exportfile" line of code: myArticles.exportFile() is not a function.
My code so far:
app.open(File("C:/Users/Sean/Desktop/New folder/va tech 2.indd"), true);
myArticles = Title.toString();
//THIS ATTEMPT WON'T WORK EITHER AS RPLCMNT FOR LINE ABOVE: myArticles= app.activeDocument.xmlItems.item;
myArticles.exportFile(ExportFormat.textType, new File("/C/Users/Sean/Desktop/New folder/test.txt"), false);
app.documents.everyItem().close(SaveOptions.NO);
var main = function() {
var doc, root, xes, n, nXE, st, xc, strs = [],
f = File ( Folder.desktop+"/contents.txt" );
try {
//NEED TO CHANGE THE URL. Ex: some/url > /Users/user/Desktop/foo.indd
doc = app.open ( File ( "some/url" ) );
}
catch(err){
alert(err.message);
return;
}
if ( !doc ) {
alert("You need an open document" );
return;
}
root = doc.xmlElements[0];
xes = root.evaluateXPathExpression("//Title");
n = xes.length;
while ( n-- ) {
nXE = xes[n];
xc = nXE.xmlContent;
if ( xc instanceof Story ) {
strs.push( xc.contents );
}
}
if ( strs.length ) {
f.open('w');
f.write ( strs.reverse().join("\r") );
f.close();
}
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

IStaticPortMappingCollection::Add always returns HRESULT_FROM_WIN32(ERROR_BUSY)

I'm trying to use the Windows UPnP APIs to map an external port to an internal one. UPnP is enabled and working with software installed on my system but I can't seem to get it working in my own code. The call looks something like this:
wrl::ComPtr< IStaticPortMappingCollection > staticPortMappings;
auto res = sm_impl->upnpNat->get_StaticPortMappingCollection( &staticPortMappings );
// Where sm_impl->upnpNat is a previously initialized IUPnPNAT pointer.
long ct = 0;
staticPortMappings->get_Count( &ct );
wrl::ComPtr< IStaticPortMapping > portMapping;
res = staticPortMappings->Add(
port,
CComBSTR( protocol.c_str( ) ).m_str,
port,
CComBSTR( clientName.c_str( ) ).m_str,
VARIANT_TRUE,
CComBSTR( description.c_str( ) ).m_str,
&portMapping
);
res will always be HRESULT_FROM_WIN32(ERROR_BUSY). The MSDN documentation does not list this as a typical return code and does not explain why one would get this return code or what to do about it.
It means the external port number (first parameter from staticPortMappings->Add) is already in use. Try adding another port.

Having issues running a script via cgi in lighttpd

I have the following piece in my config file:
cgi.assign = ( ".sh" => "" )
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
url.redirect = ( "^/urlpath/" => "http://somewebsite" )
}
I have the cgi module loaded:
server.modules = (
"mod_redirect",
"mod_access",
"mod_cgi",
"mod_accesslog" )
Now "CamsOn" and "CamsOff" are shebanged shell scripts. To be honest I had done this before and had it working but my server crashed and I lost my configs. For some reason I can't figure for the life of me how to get it working. I do the redirect so I don't have to actually create the "urlpath" page. The redirect works fine inside the $HTTP["url"] piece, and I've even tested the querystring portion by nesting a redirect inside that just takes it to google.com; urlpath/?cams=on sent me to google accordingly.
What am I doing wrong?
Update:
I was to get it to work using
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
}
I'm thinking that the redirect was getting parsed first, so when the address changed, it no longer fit the URL and querystring comparisons. Can I change this? The idea is to make the urlpath dynamic and updated in the conf file dynamically. This is why I have the redirect send you to another address. This way I also don't need to do html editing or create additional folders.
What am I doing wrong?
a) did not make backups
b) did not make backups
c) did not make backups
d) did not look in your own stackoverflow post history
See Can't figure out how to receive http requests using lighttpd
If you want to reduce the number of places you edit in your config file, you can assign a value to a variable in lighttpd.conf and use the variable in lighttpd.conf. See var.* in
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration
var.camsurlpath = "/urlpath/"
$HTTP["url"] =~ "^" + var.camsurlpath {
...
}

How to check if image is available in ruby?

I guess this is easy, I seem to be missing something simple.
I need to read an image and then display it which i do as follows, I should skip the code if the image is not available.
stu_image ="/admin_num.jpg"
if !stu_image
code for displaying the image
end
But, this is not working. Could somebody help with this please.
Cheers!
Seems to me like you're just saving a string, not the image.
this_dir = File.dirname( __FILE__ )
file = File.expand_path( "admin_num.jpg", this_dir )
Why not just testing if the file exists?
stu_image ="/admin_num.jpg"
FileTest.exists?(RAILS_ROOT + stu_image ) # < rails 3.0
FileTest.exists?(Rails.root + stu_image ) # >= rails 3.0
See File#exists? here:
http://ruby-doc.org/core-1.9.3/File.html#method-c-exists-3F

How to convert ppt to images in Ruby?

I'm using Ruby for displaying the contents of powerpoint files in a webpage. I've found solutions using the win32ole but I'm in the linux environment and it doesn't work. I think the application could trigger a openoffice command for conversion.
I recommend using Docsplit.
Install the gem, and then you can do something like:
Docsplit.extract_images(filename, :size => '920x', :format => [:png])
You can use Rjb and JODConverter to export your powerpoint to flash (or any other format).
Here is a pice of code to do it :
require 'rubygems'
require 'rjb'
classpath = nil
Rjb::load( classpath, ['-Djava.awt.headless=true'] )
jFile = Rjb::import( 'java.io.File' )
jSocketOpenOfficeConnection = Rjb::import( 'com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection' )
jOpenOfficeDocumentConverter = Rjb::import( 'com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter' )
input = jFile.new( "your-doc.ppt" )
output = jFile.new( "your-doc.swf" )
# connect to an OpenOffice.org instance running on port 8100
connection = jSocketOpenOfficeConnection.new( 8100 )
connection.connect()
# convert
converter = jOpenOfficeDocumentConverter.new( connection )
converter.convert( input, output )
# close the connection
connection.disconnect()
You need to start an OOo.org server :
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
And to add jodconverter-cli-X.X.X.jar to your CLASSPATH

Resources