I have 6 booleas variables in a dict and I want to run my code on all all their possible iteration.
so I have:
params["is_A"] = True/False
params["is_B"] = True/False
...
and then for all possible combinations, I want to call
my_func(params)
What is the best way to do so?
itertools.product can generate all the combinations:
import itertools
names = 'is_A is_B is_C is_D is_E is_F'.split()
def my_func(params):
print(params)
for p in itertools.product([True,False],repeat=6):
params = dict(zip(names,p))
my_func(params)
Output:
{'is_A': True, 'is_B': True, 'is_C': True, 'is_D': True, 'is_E': True, 'is_F': True}
{'is_A': True, 'is_B': True, 'is_C': True, 'is_D': True, 'is_E': True, 'is_F': False}
...
{'is_A': False, 'is_B': False, 'is_C': False, 'is_D': False, 'is_E': False, 'is_F': True}
{'is_A': False, 'is_B': False, 'is_C': False, 'is_D': False, 'is_E': False, 'is_F': False}
Related
I'm using Publish-Subscribe with RethinkDB.
For exchange I use one db named 'RPI_messages' with three tables:
Connector_messages
MAC_messages
Orders
I want to introduce some basic authentication on producer and consumer sides like this:
r.db('rethinkdb').table('users').insert({id: 'lis', password: 'somepassword'})
r.db('rethinkdb').table('users').insert({id: 'rpi', password: 'someotherpassword'})
r.db('RPi_messages').grant('lis', {read: false, write: true, config: true}) //producer
r.db('RPi_messages').grant('rpi', {read: true, write: false, config: true}) //consumers
r.db('rethinkdb').table('permissions')
shows this:
{
"database": "RPi_messages" ,
"id": [
"lis" ,
"007928e5-c654-4311-b3aa-a834c62dcf88"
] ,
"permissions": {
"config": true ,
"read": false ,
"write": true
} ,
"user": "lis"
}
Problem:
When I try to publish or to subscribe to exchange it throws an exception:
ReqlPermissionError: User `lis` does not have the required `config` permission in:
r.db_create('RPi_messages')
rethinkdb.errors.ReqlPermissionError: User `rpi` does not have the required `config` permission in:
r.db_create('RPi_messages')
Does this mean that my users need to have global permissions?
Any help greatly appreciated.
So, with fairly bit of try and error I made it work.
For anyone else: You need config permission on global scope for every user in your pub-sub system like this:
r.grant('lis', {read: false, write: false, config: true});
r.grant('rpi', {read: false, write: false, config: true});
...and following permissions on table(s) or, in my case, on database scope:
r.db('RPi_messages').grant('lis', {read: true, write: true, config: true}); //publisher
r.db('RPi_messages').grant('rpi', {read: true, write: false, config: true}); //sunscriber
Correct me if I'm wrong but this doesn't look very secure to me. Those permissions are needed because Exchanger class in rethink's pub-sub system looks if exchange table exists and creates on if it doesn't. Which means that anyone who gets one of your client subscriber devices can create as many tables in your db as they want.
Recently I started using sublime 3 text editor and the issue I encountered is the REPl terminal, I mean why is there syntax highlighting and autocompletion in a terminal during execution, it makes the terminal annoying, is there any fix?
Go to .sublime-settings file, add "auto_complete": false in SublimeRepl user settings.
"repl_view_settings": {
"translate_tabs_to_spaces": false,
"auto_indent": true,
"smart_indent": true,
"spell_check": false,
"indent_subsequent_lines": false,
"detect_indentation": false,
"auto_complete": false,
"line_numbers": true,
"gutter": true
},
If this doesn't work, go to SublimeREPL/config/Python/Main.sublime-menu, search for autocomplete_server and set it to false.
I have the following pipeline:
pipeline {
agent any
stages {
... building stuff...
stage('push to develop'){
when {
branch 'develop'
}
steps {
ftpPublisher paramPublish: [ parameterName: "" ], alwaysPublishFromMaster: true, masterNodeName: master, continueOnError: false, failOnError: false, publishers: [
[configName: 'cp-front', usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true, transfers: [
[asciiMode: false, cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*']
]]
]
}
}
}
}
Unfortunately, this throws:
groovy.lang.MissingPropertyException: No such property: master for
class: groovy.lang.Binding at
groovy.lang.Binding.getVariable(Binding.java:63) at
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at
org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at
org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
at
org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
at
com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
at
com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.run(WorkflowScript:22)
Which gives me about 0 idea what is going on. Any pointers?
master (an object, property) is not equal to 'master' - which is an instance of String. Maybe you made a simple mistake?
I'm attempting to create a platform that allows students to play code challenges head-to-head using blockly. I'm imagining something like:
The documentation mentions "Multiple workspaces" with block factory, but I feel like I might be reinventing the wheel here, so before I get started, does something like this already exist? Ideally, hooked up to app engine so students could grab code from any other student and test to see how their code compares?
Yes, it exists! We use this in the Developer Tools to give both an editor and the preview. Two demos to look at are the Multi-Playground (src) and the Mirrored Workspaces (src).
You'll notice in the multi-playground, we just call Blockly.inject(..) on each div:
function start() {
// ...
startBlocklyInstance('VertStartLTR', false, false, 'start', toolbox);
startBlocklyInstance('VertStartRTL', true, false, 'start', toolbox);
startBlocklyInstance('VertEndLTR', false, false, 'end', toolbox);
startBlocklyInstance('VertEndRTL', true, false, 'end', toolbox);
startBlocklyInstance('HorizontalStartLTR', false, true, 'start', toolbox);
startBlocklyInstance('HorizontalStartRTL', true, true, 'start', toolbox);
startBlocklyInstance('HorizontalEndLTR', false, true, 'end', toolbox);
startBlocklyInstance('HorizontalEndRTL', true, true, 'end', toolbox);
}
function startBlocklyInstance(suffix, rtl, horizontalLayout, position,
toolbox) {
options.rtl = rtl;
options.toolbox = toolbox;
options.horizontalLayout = horizontalLayout;
options.toolboxPosition = position;
Blockly.inject('blocklyDiv' + suffix, options);
}
I am spawnning a java App (REPL for querying a local DB) using:
repl = = require('child_process').spawn('java', ['-cp', '...list of libs...', ,{ cwd: '...path to env...', env: process.env, customFds: [-1, -1, -1] });
The REPL loads fine because I can seen its outputs in stdout, but stdin.write commands don't go throught. I can however write them directly the console window of the node process itself (which is weird since I didn't .resume() it).
I have printed out the stdin of the spawned process, it looks like this:
{ _handle:
{ writeQueueSize: 0,
socket: [Circular],
onread: [Function: onread] },
_pendingWriteReqs: 0,
_flags: 0,
_connectQueueSize: 0,
destroyed: false,
bytesRead: 0,
bytesWritten: 0,
allowHalfOpen: undefined,
writable: true,
readable: false }
It seems there is no 'fd' defined, and also .readable returns false. How can this be resolved?
(this is all on a windows machine, node v0.6.6)
Thanks
The documentation states that the customFds option was deprecated specifically because they couldn't get it to work on Windows.
While an array of -1's implies that it shouldn't be used, since the entire option is deprecated, try removing it entirely and see if that solves your problem.