parameters

Optional args in MATLAB functions

非 Y 不嫁゛ 提交于 2019-12-17 15:32:35
问题 How can I declare function in MATLAB with optional arguments? For example: function [a] = train(x, y, opt) , where opt must be an optional argument. 回答1: There are a few different options on how to do this. The most basic is to use varargin, and then use nargin , size etc. to determine whether the optional arguments have been passed to the function. % Function that takes two arguments, X & Y, followed by a variable % number of additional arguments function varlist(X,Y,varargin) fprintf('Total

“this” in function parameter

痞子三分冷 提交于 2019-12-17 15:14:11
问题 Looking at some code examples for HtmlHelpers, and I see declarations that look like: public static string HelperName(this HtmlHelper htmlHelper, ...more regular params ) I can't remember seeing this type of construct any where else - can someone explain the purpose of the "this"? I thought that by declaring something public static meant that the class did not need to be instantiated - so what is "this" in this case? 回答1: This is the syntax for declaring extension methods, a new feature of C#

How to pass parameters from bash to php script?

巧了我就是萌 提交于 2019-12-17 13:44:24
问题 I have done a a bash script which run php script. It works fine without parameters but when I add parameters (id and url), there are some errors: PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf .d/mcrypt.ini on line 1 in Unknown on line 0 Could not open input file: /var/www/dev/dbinsert/script/automatisation.php? id=1 I run php script from the bash like this: php /var/www/dev/dbinsert/script/automatisation.php?id=19&url=http://bkjbezjnkelnkz.com 回答1: Call it as

undefined method `stringify_keys!' ruby on rails

不羁岁月 提交于 2019-12-17 11:31:01
问题 I have this code: def addcar @car = Car.new(params[:car]) render :action => 'list' end <% @allcars.each do |cell| %> <p> <%= link_to cell.to_s, :controller => 'car', :action => 'addcar', :car => cell.to_s %> </p> <% end %> It's giving me this error: undefined method `stringify_keys!' for "Honda":String I don't understand what is wrong with :car . 回答1: in the addcar method, you try to create a new object ( create method) while transfering just a string to it ( params[:car] which apparently is

undefined method `stringify_keys!' ruby on rails

爷,独闯天下 提交于 2019-12-17 11:29:10
问题 I have this code: def addcar @car = Car.new(params[:car]) render :action => 'list' end <% @allcars.each do |cell| %> <p> <%= link_to cell.to_s, :controller => 'car', :action => 'addcar', :car => cell.to_s %> </p> <% end %> It's giving me this error: undefined method `stringify_keys!' for "Honda":String I don't understand what is wrong with :car . 回答1: in the addcar method, you try to create a new object ( create method) while transfering just a string to it ( params[:car] which apparently is

Mark parameters as NOT nullable in C#/.NET?

血红的双手。 提交于 2019-12-17 10:46:08
问题 Is there a simple attribute or data contract that I can assign to a function parameter that prevents null from being passed in C#/.NET? Ideally this would also check at compile time to make sure the literal null isn't being used anywhere for it and at run-time throw ArgumentNullException . Currently I write something like ... if (null == arg) throw new ArgumentNullException("arg"); ... for every argument that I expect to not be null . On the same note, is there an opposite to Nullable<>

Shell run/execute php script with parameters

我只是一个虾纸丫 提交于 2019-12-17 10:44:23
问题 I need to execute a php file with parameters through shell. here is how I would run the php file: php -q htdocs/file.php I need to have the parameter 'show' be passed through and php -q htdocs/file.php?show=show_name doesn't work If someone could spell out to me what command to execute to get the php file to execute with set parameters, it would be much appreciated. If not, try to lead me the right direction. 回答1: test.php: <?php print_r($argv); ?> Shell: $ php -q test.php foo bar Array ( [0]

Difference between value parameter and reference parameter?

不想你离开。 提交于 2019-12-17 09:54:25
问题 Difference between value parameter and reference parameter ? This question is asked sometime by interviewers during my interviews. Can someone tell me the exact difference that is easy to explain with example? And is reference parameter and pointer parameter are same thing ? Thanks 回答1: Changes to a value parameter are not visible to the caller (also called "pass by value"). Changes to a reference parameter are visible to the caller ("pass by reference"). C++ example: void by_value(int n) { n

How do I pass a wildcard parameter to a bash file

筅森魡賤 提交于 2019-12-17 09:38:27
问题 I'm trying to write a bash script that allows the user to pass a directory path using wildcards. For example, bash show_files.sh * when executed within this directory drw-r--r-- 2 root root 4.0K Sep 18 11:33 dir_a -rw-r--r-- 1 root root 223 Sep 18 11:33 file_b.txt -rw-rw-r-- 1 root root 106 Oct 18 15:48 file_c.sql would output: dir_a file_b.txt file_c.sql The way it is right now, it outputs: dir_a contents of show_files.sh : #!/bin/bash dirs="$1" for dir in $dirs do echo $dir done 回答1: The

The builder pattern and a large number of mandatory parameters

爷,独闯天下 提交于 2019-12-17 08:55:42
问题 To date I use the following implementation of the builder pattern (as opposed to the implementation described here): public class Widget { public static class Builder { public Builder(String name, double price) { ... } public Widget build() { ... } public Builder manufacturer(String value) { ... } public Builder serialNumber(String value) { ... } public Builder model(String value) { ... } } private Widget(Builder builder) { ... } } This works well for most situations I've encountered where I