Extend list in omegaconf from command line - omegaconf

I have a configuration similar to this from a yaml file
training_variables:
- var1
- var2
I want to extend the list using an additional variable, and I want to do it from the command line. How to do it? It seems not possible but I think it can be very useful if you want to experiment a new setup without changing the configuration file every time. I was wondering something like this:
train.py training_variables=$training_variables+['var3']

This is not supported, and is not planned to be supported in the form you are requesting.
A practical solution is to split your list into two variables and concatenate them in the code.
base_list:
- a
- b
extra_list: []
train.py:
...
combined_list = cfg.base_list + cfg.extra_list
...
$ python train.py 'extra_list=[c,d,e]'
I am not 100% sure the above command line would work with an app using OmegaConf directly but it should work with Hydra 1.0 or newer.

Related

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

How to list Zabbix macro values for a host

I've a Zabbix item which I can't get to work using a Zabbix macro.
The item key I start with looks like this:
web.page.regexp[10.0.0.100,/path,"(.*)",, \1]
And testing it with the following command also shows me nice results:
$ sudo zabbix_agentd -t 'web.page.regexp[10.0.0.100,/path,80,"(.*)",, \1]' --print
web.page.regexp[10.0.0.100,/path,80,"(.*)",, \1] [s|works]
But of course using the IP hardcoded isn't nice, that's why I want to use the predefined macros within the key, like this:
web.page.regexp[{HOST.IP1},/path,"(.*)",, \1]
But unfortunately this macro doesn't resolve to anything and the result looks like this:
web.page.regexp[10.0.0.100,/path,80,"(.*)",, \1] [s|]
Therefore I'd love to know if there's any way to list all the macro values for a specific host in Zabbix. Or is there a better way to use the {HOST.*} macros?
Using localhostis not an option for me - I want to test the public interface and I want to understand why the macros don't work as I expect it.
Cheers
Macro {HOST.IP1} should be expanded correctly for passive agent items (although it is suggested to just use {HOST.IP}). However, if your item is an active agent item, then {HOST.IP1} will expand to *UNKNOWN*, because an item is not attached to an interface in that case.
As for macro list for a host, it was implemented for user macros under ZBXNEXT-210 and is already available in pre-2.5.0 trunk (which is not ready for production yet).

Use the tree-view in Atom editor init script

I'm trying to write a init script for the Atom editor to add a custom command to be able to reveal the currently opened editor file in the tree-view with one key combination, instead of two.
Here is an example code (which makes something different) to make clear how it generally has to look like.
atom.commands.add 'atom-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveEditor()
editor.selectLine()
editor.cutSelectedText()
The two commands I need should not be sent to the editor, but to the tree-view. Here are the two commands:
tree-view:toggle-focus
tree-view:reveal-active-file
I assume I have to do something similar as above, like getActiveTreeView or something like that. I tried to google it but it doesn't seem to be obvious. Does someone know how to do this?
It could look something like this:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
tree-view.toggle-focus()
tree-view.reveal-active-file()
You can use the atom.commands.dispatch() method to send a command when getting a hold of the object to send the commands to is hard. In your case, you can use:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')
Sadly, Lee's answer is not correct anymore. Within changes in the API the changed the naming of atom.workspaceView to atom.workspace.
So, if anyone gets here (sure questions and answer is a "bit" old), here's the current working script.
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspace.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspace.element, 'tree-view:reveal-active-file')
#Source
https://discuss.atom.io/t/workspaceview-events/14595/4

How to store and call a simple mongodb procedure

I often call the same commands in MongoDb command shell, for example :
db.user().find().pretty();
How would you store and call back this command ?
Ideally converting it to something like this :
db.findp( 'user' );
I believe this is NOT what your looking for, now that I read your question again: http://docs.mongodb.org/manual/applications/server-side-javascript/
Instead you are looking to modify the console in such a manner to make your life easier.
I should note, right now, that there is actually an extension which can do this sort of auto-formatting for you made by 10gen: https://github.com/TylerBrock/mongo-hacker
However if you wish to modify the files behind MongoDBs console a little more then you will need to do some manual labour.
There is a rc script in your home directory called .mongorc.js. In this file you can place any custom code you like (as #Asya mentioned) and it will actually become a command within the console.
In you rc file you could place a function like:
DB.prototype.pfind = function(col){
return this[col].find().pretty();
};
Or you could write:
DBCollection.prototype.pfind = function(){
return this.find().pretty();
};
Then you should be able to do:
db.pfind('users');
Or with the second command:
db.users.pfind();
Of course this method is for Linux, I am unsure about Windows, however, Windows should have an rc type script somewhere I believe.

How could I embedded socket in Lua internally, just like oslib, debuglib?

I want to implement the function like embedding the socket function in my Lua build.
So I don't need to copy socket.core.dll any more (just for fun).
I search the maillist, and see some guys discuss the topic,
http://lua-users.org/lists/lua-l/2005-10/msg00269.html
But I have question for the details steps, who could give me a detailed steps for changing the lua and luasocket code to make them work together (not with dll method).
I tried these steps in windows xp with VC2008:
1) copy luasocket code to Lua project.
2) add some code
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{LUA_SOCKETLIBNAME, luaopen_socket_core}, // add this line
{LUA_MIMELIBNAME, luaopen_socket_core}, // add this line
{NULL, NULL}
};
3) build the project, and run it.
When I type print(socket._VERSION), it shows luasocket 2.0.2, it is correct.
When I type print(socket.dns.toip("localhost")), it shows 127.0.0.1 table: 00480AD0, it is correct too.
But when I try to use other features, for example bind, it can't work.
Who could tell me the reason?
you need put luasocket stuff into the package.preload table, in this way:
lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");
// add mime.core yourself...
luasocket is a mixed C/lua module, you need to bundle both versions into your application if you want it to work without any extra files.
socket.lua loads socket.core (from socket/core.dll)
mime.lua loads mime.core (from mime/core.dll)
So in order for your application to work you will need to build all the .dll files and the .lua files into your application and manually load them (or set them up to be loaded correctly via custom package loaders).
The email you quoted is tweaking the package.preload table (in a way that appears a tad odd now but might work anyway) to get the built-in C code to be loaded correctly when require is called.
Try running
for k, v in pairs(socket) do print(k, v) end
and maybe we'll be able to help.