parameter-passing

Numeric argument passed with jq --arg not matching data with ==

老子叫甜甜 提交于 2019-11-30 05:30:00
问题 Here is a sample JSON response from my curl: { "success": true, "message": "jobStatus", "jobStatus": [ { "ID": 9, "status": "Successful" }, { "ID": 2, "status": "Successful" }, { "ID": 99, "status": "Failed" } ] } I want to check the status of ID=2. Here is the command I tried: cat test.txt|jq --arg v "2" '.jobStatus[]|select(.ID == $v)|.status' response: there is none I tried value 2 without quotes and still no result. By contrast, if I try the command with a literal 2 , it works: cat test

Pass array literal to PostgreSQL function

醉酒当歌 提交于 2019-11-30 05:14:05
问题 I have a Postgres function which contains a select statement. I need to add a condition using a passed in variable containing an array of string values. CREATE OR REPLACE FUNCTION get_questions(vcode text) RETURN return_value as $f$ DECLARE vresult return_value; BEGIN --snip-- SELECT id, title, code FROM questions WHERE code NOT IN (vcode); --snip-- questions table: id ,title, code 1, "title1", "qcode1" 2, "title2", "qcode2" 3, "title3", "qcode3" 4, "title4", "qcode4" How should the vcode

C: Passing variable number of arguments from one function to another

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 04:56:22
So, here's a small problem I'm facing right now -> I'm trying to write a function that will accept a char* message and a variable number of arguments. My function will modify the message a little, and then It'll call printf with the message and given parameters. Essentialy, I'm trying to write something like that: void modifyAndPrintMessage(char* message,...){ char* newMessage; //copy message. //Here I'm modifying the newMessage to be printed,and then I'd like to print it. //passed args won't be changed in any way. printf(newMessage,...); //Of course, this won't work. Any ideas? fflush(stdout)

Why doesn't this work if in Ruby everything is an Object?

旧街凉风 提交于 2019-11-30 03:51:44
Considering that in the Ruby programming language everything is said to be an Object, I safely assumed that passing arguments to methods are done by reference . However this little example below puzzles me: $string = "String" def changer(s) s = 1 end changer($string) puts $string.class String => nil As you can see the original Object wasn't modified, I wish to know why , and also, how could I accomplish the desired behavior ie. Getting the method to actually change the object referenced by its argument. The way Ruby works is a combination of pass by value and pass by reference. In fact, Ruby

How to Pass Parameters from QSub to Bash Script?

空扰寡人 提交于 2019-11-30 02:19:06
问题 I'm having an issue passing variables to a Bash script using QSub. Assume I have a Bash script named example. The format of example is the following: #!/bin/bash # (assume other variables have been set) echo $1 $2 $3 $4 So, executing "bash example.sh this is a test" on Terminal (I am using Ubuntu 12.04.3 LTS, if that helps) produces the output "this is a test". However, when I enter "qsub -v this,is,a,test example.sh", I get no output. I checked the output file that QSub produces, but the

Why use packed *args/**kwargs instead of passing list/dict?

余生长醉 提交于 2019-11-30 02:11:24
If I don't know how many arguments a function will be passed, I could write the function using argument packing: def add(factor, *nums): """Add numbers and multiply by factor.""" return sum(nums) * factor Alternatively, I could avoid argument packing by passing a list of numbers as the argument: def add(factor, nums): """Add numbers and multiply by factor. :type factor: int :type nums: list of int """ return sum(nums) * factor Is there an advantage to using argument packing *args over passing a list of numbers? Or are there situations where one is more appropriate? *args / **kwargs has its

Unquoted tokens in argument mode involving variable references and subexpressions: why are they sometimes split into multiple arguments?

隐身守侯 提交于 2019-11-30 01:47:54
Note: A summary of this question has since been posted at the PowerShell GitHub repository , since superseded by this more comprehensive issue . Arguments passed to a command in PowerShell are parsed in argument mode (as opposed to expression mode - see Get-Help about_Parsing ). Conveniently, (double-)quoting arguments that do not contain whitespace or metacharacters is usually optional , even when these arguments involve variable references (e.g. $HOME\sub ) or subexpressions (e.g., version=$($PsVersionTable.PsVersion) . For the most part, such unquoted arguments are treated as if they were

How can I pass a Class as parameter and return a generic collection in Java?

自古美人都是妖i 提交于 2019-11-29 23:38:53
I am designing a simple Data Access Object for my Java application. I have a few classes (records) that represents a single row in tables like User and Fruit . I would like to have a single method for getting all records of a specific type. For the moment I have it like this: public List<User> getAllUsers() { ... } public List<Fruit> getAllFruits() { ... } .... But I would like to have a single polymorphic method like this (wrong): public List<T> getAllRecords(Class<T> type) { if(type instanceof User) { // Use JDBC and SQL SELECT * FROM user } else if(type instanceof Fruit) { // Use JDBC and

Can parameters be constant?

落爺英雄遲暮 提交于 2019-11-29 22:45:20
I'm looking for the C# equivalent of Java's final . Does it exist? Does C# have anything like the following: public Foo(final int bar); In the above example, bar is a read only variable and cannot be changed by Foo() . Is there any way to do this in C#? For instance, maybe I have a long method that will be working with x , y , and z coordinates of some object (ints). I want to be absolutely certain that the function doesn't alter these values in any way, thereby corrupting the data. Thus, I would like to declare them readonly. public Foo(int x, int y, int z) { // do stuff x++; // oops. This

Invoke a second script with arguments from a script

浪尽此生 提交于 2019-11-29 20:24:00
I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at design time, so right at the point where I need to invoke this second PowerShell script, I basically just have one variable that has the path to this second script, and a second variable that is an array of arguments to pass to the script identified in the path variable. So the variable containing the path to the second script ($scriptPath), might