Cannot pass parameter with near call - nearprotocol

I'm testing the Greeting contract in "workshop--exploring-assemblyscript-contracts" and try to pass parameter to saveMyMessage function but always get error. There maybe problem with quotations marks, I tried with " or '` but nothing succeeds. I'm running it on Windows.
This is the suggestion from the code:
near call greeting..testnet saveMyMessage '{"message": "bob? you in there?"}' --account-id .testnet
When I try
near call %ID% saveMyMessage '{"message": "bob? you in there?"}' --account-id %ID%
Or replace " with " or end single quote with ` always get error like this
Unknown argument: bob? you in there?}'

For starters, it appears you have a syntax error with 2 dots instead of 1 here - greeting..testnet
Have you tried seeing what %ID% is?
I would try the following syntax, but make sure when you set your IDenv variable, that it returns the correct value when you run echo $ID
Once you have your env variables set up correctly, try the following:
near call $ID saveMyMessage '{"message": "bob? you in there?"}' --account-id $ID

Related

How do I escape a password ending with a dollar sign icinga2?

I have dozens of devices I need to login to using an API script. One set of devices has a password ending in $. I've tried a bunch of things but I can't seem to escape that $ char. Here is the error I'm seeing.
critical/config: Error: Validation failed for object 'gelt-uk4-gp!HTTP/80: Status Check ' of type 'Service'; Attribute 'vars' -> 'gspass': Closing $ not found in macro format string 'n0t-real#$'.
Location: in /etc/icinga2/zones.d/global-templates/global-services.conf: 55:5-55:31
/etc/icinga2/zones.d/global-templates/global-services.conf(53): if ( host.vars.company == "gelt-emea" ) {
/etc/icinga2/zones.d/global-templates/global-services.conf(54): vars.gsuser = "admin"
/etc/icinga2/zones.d/global-templates/global-services.conf(55): vars.gspass = "n0t-real#$"
^^^^^^^^^^^^^^^^^^^^^^^^^^^
You add an extra $ right beside the literal dollar sign.
So if the password is word54s$ you type:
vars.geltpass = "word54s$$"

yargs .command error: second argument to option must be an object

Suppose I have a file "test.js":
var args = require('yargs')
.command('command', 'command usage here', {alias: "c"} )
.argv;
Then I run:
>node test command
I got this error:
second argument to option must be an object
If I remove the 3rd parameter of .command:
var args = require('yargs')
.command('command', 'command usage here')
.argv;
Everything is fine.
I must make a dumb mistake. But I just cannot figure it out.
Thanks
Your 3rd argument is not required, that's why it works when you remove it. I'm pretty sure the 3rd argument has to be a function call.
var args = require('yargs')
.command('command',
'command explanation',
function(yargs){
//insert yargs.options here
yargs.options({
c:{
demand: true,//if you require the command
alias: 'c',// you will enter -c to use it
description: 'explain what it does'
}
});
})
.argv;
an example of usage might be:
C:\WorkingDirectory>node app.js command -c run
your code could include console.log(args.c);//prints out run

issue with two nested loops in bash

I am trying to loop over two series of variables and make them with R statistical software to get the correlation results.
I got confused why the bigger loop (on mica_headers) doesn't take place while the inner loop finishes each time.
#!/bin/sh
#set -e
micaHeaderList="tot_instruction ILP32 ILP64 ILP128 ILP256 total_ins_count_for_hpc_alignment totInstruction mem-read mem-write control-flow arithmetic floating-point stack shift string sse other nop InstrFootprint64 InstrFootprint4k DataFootprint64 DataFootprint4k mem_access memReuseDist0-2 memReuseDist2-4 memReuseDist4-8 memReuseDist8-16 memReuseDist16-32 memReuseDist32-64 memReuseDist64-128 memReuseDist128-256 memReuseDist256-512 memReuseDist512-1k memReuseDist1k-2k memReuseDist2k-4k memReuseDist4k-8k memReuseDist8k-16k memReuseDist16k-32k memReuseDist32k-64k memReuseDist64k-128k memReuseDist128k-256k memReuseDist256k-512k memReuseDist512k-00 GAg_mispred_cnt_4bits PAg_mispred_cnt_4bits GAs_mispred_cnt_4bits PAs_mispred_cnt_4bits GAg_mispred_cnt_8bits PAg_mispred_cnt_8bits GAs_mispred_cnt_8bits PAs_mispred_cnt_8bits GAg_mispred_cnt_12bits PAg_mispred_cnt_12bits GAs_mispred_cnt_12bits PAs_mispred_cnt_12bits total_brCount total_transactionCount total_takenCount total_num_ops instr_reg_cnt total_reg_use_cnt total_reg_age reg_age_cnt_1 reg_age_cnt_2 reg_age_cnt_4 reg_age_cnt_8 reg_age_cnt_16 reg_age_cnt_32 reg_age_cnt_64 mem_read_cnt mem_read_local_stride_0 mem_read_local_stride_8 mem_read_local_stride_64 mem_read_local_stride_512 mem_read_local_stride_4096 mem_read_local_stride_32768 mem_read_local_stride_262144 mem_read_global_stride_0 mem_read_global_stride_8 mem_read_global_stride_64 mem_read_global_stride_512 mem_read_global_stride_4096 mem_read_global_stride_32768 mem_read_global_stride_262144 mem_write_cnt mem_write_local_stride_0 mem_write_local_stride_8 mem_write_local_stride_64 mem_write_local_stride_512 mem_write_local_stride_4096 mem_write_local_stride_32768 mem_write_local_stride_262144 mem_write_global_stride_0 mem_write_global_stride_8 mem_write_global_stride_64 mem_write_global_stride_512 mem_write_global_stride_4096 mem_write_global_stride_32768 mem_write_global_stride_262144"
mhToBeReplaced="ILP32"
compilerOptionList="funsafe_math_optimizations fno_guess_branch_probability fno_ivopts fno_tree_loop_optimize fno_inline_functions funroll_all_loops fno_omit_frame_pointer falign_jumps fselective_scheduling fno_inline_small_functions fno_tree_pre ftracer fno_move_loop_invariants"
coToBeReplaced="fno_guess_branch_probability"
for mica_header in $micaHeaderList
do
for compiler_option in $compilerOptionList
do
echo "Calculating $compiler_option correlation for $mica_header"
sed -i "s/$coToBeReplaced/$compiler_option/g" r.scr
coToBeReplaced=$compiler_option
make
done
sed -i "s/$mhToBeReplaced/$mica_header/g" r.scr
mhToBeReplaced=$mica_header
done
Edited: Generally, in order to avoid inconsistency between the values of iterations and source file, how could I be able to link these two together from different files. i.e. micaHeaderList with the headers inside the ALL.scv file ?
In the script there is a mistake which echoes a value of $mica_header which will be substituted only for make calls in the next outer loop run. This is caused by the second sed being run only after make. It should have been called before the inner loop. Could not this cause the confusion?
Also instead of replacing one value of a parameter for another it is better to create a template of r.src file with placeholders for the parameters to be changed. This way we can be sure that for some values of the parameters there could not be conflicts with the search patterns and that a typo will not prevent substitution.
Below is an improved script with considerably simpler code. The part inside if test "$Test" = 1 is just a testing code activated by Test=1. For this script just create a template for r.scr named r.scr.template and put the placeholders %%MicaHeader%% and %%CompilerOption%% instead of the parameters which should be replaced. For the first test there is a shorter list of parameters.
#!/bin/sh
micaHeaderList="tot_instruction ILP32 ILP64"
mhToBeReplaced=%%MicaHeader%%
compilerOptionList="funsafe_math_optimizations fno_guess_branch_probability fno_ivopts fno_tree_loop_optimize"
coToBeReplaced=%%CompilerOption%%
TemplateFile=r.scr.template
OutputFile=r.scr
Test=1
if test "$Test" = 1
then
TemplateFile="${TemplateFile}-test"
echo "$coToBeReplaced $mhToBeReplaced" >"$TemplateFile"
make ()
{
echo -n ">>> make: "
cat "$OutputFile"
}
fi
for mica_header in $micaHeaderList
do
for compiler_option in $compilerOptionList
do
echo "Calculating $compiler_option correlation for $mica_header"
sed "s/$mhToBeReplaced/$mica_header/g;s/$coToBeReplaced/$compiler_option/g" "$TemplateFile" >"$OutputFile"
make
done
done
If the problem still persists:
Check the generated r.src files.
Check if the make script really uses the substituted parameters from r.src.

Invalid command name in Tcl when using format

I'm running the following commands
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
and I get the following error:
full_pin_name is invalid command name "A" B
when top_cell equals A and encoded_name equals B.
Why is this happening?
I suspect the problem is with your $top_cell variable, which has the value invalid command name "A". To check, try the following line before your format line:
puts ">$top_cell<"
If indeed, $top_cell value has a problem, you can then trace back to the last set command. Let us know if it fixes your problem, or we might try some other approaches.
Try repeating this in a plain Tcl shell, it works. Something is different in your Tcl shell.
Try
info body set
and
info body format
If either report something other than set isn't a procedure or format isn't a procedure then you have your culprit.
May be this code runs in a namespace which has the set command defined in it?
To demonstrate:
% namespace eval foo {
proc set args {
puts hey!
}
proc whatever {top_cell encoded_name} {
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
}
}
% ::foo::whatever A B
hey!
can't read "full_pin_name": no such variable
%
As far as I can tell without a TCL interpreter here it should work assuming a normal interpreter with format defined. so it looks like maybe format has been renamed or doesn't exist as a command in the interpreter you are using?
To get you going you don't really need format to join strings anyway
set fill_pin_name "$top_cell $encoded_name"
should so what you need
Maybe your code looks like this:
set encoded_name B
if { [catch {[A]} top_cell]} {
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
}
The result is:
full_pin_name is invalid command name "A" B

command line arguments in bash to Rscript

I have a bash script that creates a csv file and an R file that creates graphs from that.
At the end of the bash script I call Rscript Graphs.R 10
The response I get is as follows:
Error in is.vector(X) : subscript out of bounds
Calls: print ... <Anonymous> -> lapply -> FUN -> lapply -> is.vector
Execution halted
The first few lines of my Graphs.R are:
#!/bin/Rscript
args <- commandArgs(TRUE)
CorrAns = args[1]
No idea what I am doing wrong? The advice on the net appears to me to say that this should work. Its very hard to make sense of commandArgs
With the following in args.R
print(commandArgs(TRUE)[1])
and the following in args.sh
Rscript args.R 10
I get the following output from bash args.sh
[1] "10"
and no error. If necessary, convert to a numberic type using as.numeric(commandArgs(TRUE)[1]).
Just a guess, perhaps you need to convert CorrAns from character to numeric, since Value section of ?CommandArgs says:
A character vector containing the name
of the executable and the
user-supplied command line arguments.
UPDATE: It could be as easy as:
#!/bin/Rscript
args <- commandArgs(TRUE)
(CorrAns = args[1])
(CorrAns = as.numeric(args[1]))
Reading the docs, it seems you might need to remove the TRUE from the call to commandArgs() as you don't call the script with --args. Either that, or you need to call Rscript Graphs.R --args 10.
Usage
commandArgs(trailingOnly = FALSE)
Arguments
trailingOnly logical. Should only
arguments after --args be returned?
Rscript args.R 10 where 10 is the numeric value we want to pass to the R script.
print(as.numeric(commandArgs(TRUE)[1]) prints out the value which can then be assigned to a variable.

Resources