parameter-passing

Should Rails helpers assume an instance variable exists or should they receive them as parameters?

こ雲淡風輕ζ 提交于 2019-11-28 18:34:54
I'm wondering if there's a specific programming principle (Demeter?) that supports the idea that Rails helpers should never use controller instance variables, rather, they should receive such variables as function parameters. For example, assume my ChickensController#squawk action creates an instance variable called @egg . Furthermore, assume the squawk view contains a call to a helper called cockadoodledoo , implemented like so: def cockadoodledoo @egg.to_s end Would it be better or unnecessarily verbose to pass @egg as a parameter, such that the view calls cockadoodledoo(@egg) and for the

Build and run with arguments in Sublime Text 2

房东的猫 提交于 2019-11-28 18:17:01
I'm running on MacOS X and I'm using Sublime Text 2 to code. I've found the command + B option to build and command + shift + B to build and run. Is it possible to run a program (or script) and pass arguments. Exemple: myProg arg1 arg2 Note: I'm using multiple languages (C++, Java, Python), so I hope there is a way to set the arguments for each project and not for all build. Edit I want to set the parameters for a program call, a little bit like in eclipse where you can set the arguments when you run your program. For each project you can create a .sublime-project file with your specific build

Send list/array as parameter with jQuery getJson

偶尔善良 提交于 2019-11-28 17:53:57
I have the following where I'm trying to send list/array to MVC controller method: var id = []; var inStock = []; $table.find('tbody>tr').each(function() { id.push($(this).find('.id').text()); inStock.push($(this).find('.stocked').attr('checked')); }); var params = {}; params.ids = id; params.stocked = inStock; $.getJSON('MyApp/UpdateStockList', params, function() { alert('finished'); }); in my contoller: public JsonResult UpdateStockList(int[] ids, bool[] stocked) { } both paramaters are null. Note that if I change the params to single items params.ids = 1; params.stocked = true; public

Pass property itself to function as parameter in C#

谁说胖子不能爱 提交于 2019-11-28 17:12:36
I am looking for a method to pass property itself to a function. Not value of property. Function doesn't know in advance which property will be used for sorting. Simplest way in this example is: creating 4 overwrites with different parameter types. Other way is using of typeof() inside function. Both these ways are unacceptable when Class1 has hundreds properties. So far I found following method: class Class1 { string vehName; int maxSpeed; int fuelCapacity; bool isFlying; } class Processor { List<Class1> vehicles = null; Processor(List<Class1> input) { vehicles = input; } List<Class1> sortBy

Passing an Array/List into Python

牧云@^-^@ 提交于 2019-11-28 15:58:54
I've been looking at passing arrays, or lists, as Python tends to call them, into a function. I read something about using *args, such as: def someFunc(*args) for x in args print x But not sure if this is right/wrong. Nothing seems to work as I want. I'm used to be able to pass arrays into PHP function with ease and this is confusing me. It also seems I can't do this: def someFunc(*args, someString) As it throws up an error. I think I've just got myself completely confused and looking for someone to clear it up for me. When you define your function using this syntax: def someFunc(*args) for x

How to pass parameter on 'vagrant up' and have it in the scope of Vagrantfile?

巧了我就是萌 提交于 2019-11-28 15:33:53
I'm looking for a way to pass parameter to Chef cookbook like: $ vagrant up some_parameter And then use some_parameter inside one of the Chef cookbooks. You cannot pass any parameter to vagrant. The only way is to use environment variables MY_VAR='my value' vagrant up And use ENV['MY_VAR'] in recipe. Benjamin Gauthier You also can include the GetoptLong Ruby library that allows you to parse command line options. Vagrantfile require 'getoptlong' opts = GetoptLong.new( [ '--custom-option', GetoptLong::OPTIONAL_ARGUMENT ] ) customParameter='' opts.each do |opt, arg| case opt when '--custom-option

Passing variables, creating instances, self, The mechanics and usage of classes: need explanation [closed]

社会主义新天地 提交于 2019-11-28 15:16:33
I've been sitting over this the whole day and Im a little tired already so please excuse me being brief. Im new to python. I just rewrote a working program, into a bunch of functions in a class and everything messed up. I dont know if it's me but I'm very surprised I couldn't find a beginner's tutorial on how to handle classes on the web so I have a few questions. First of all, in the __init__ section of the class I have declared a bunch of variables with self.variable=something . Is it correct that I should be able to access/modify these variables in every function of the class by using self

Bash: pass a function as parameter

倾然丶 夕夏残阳落幕 提交于 2019-11-28 15:00:23
问题 I need to pass a function as a parameter in Bash. For example, the following code: function x() { echo "Hello world" } function around() { echo "before" eval $1 echo "after" } around x Should output: before Hello world after I know eval is not correct in that context but that's just an example :) Any idea? 回答1: If you don't need anything fancy like delaying the evaluation of the function name or its arguments, you don't need eval : function x() { echo "Hello world"; } function around() { echo

In-Place Quicksort in matlab

风格不统一 提交于 2019-11-28 14:00:00
I wrote a small quicksort implementation in matlab to sort some custom data. Because I am sorting a cell-array and I need the indexes of the sort-order and do not want to restructure the cell-array itself I need my own implementation (maybe there is one available that works, but I did not find it). My current implementation works by partitioning into a left and right array and then passing these arrays to the recursive call. Because I do not know the size of left and and right I just grow them inside a loop which I know is horribly slow in matlab. I know you can do an in place quicksort, but I

How to pass a parameter in URL on a form submit in Struts2

萝らか妹 提交于 2019-11-28 13:57:48
I am doing a project in Struts2 where I need of setting a parameter in URL like user parameter in below link. I want this parameter to be passed when I click a form submit button and not any links separately. I know how to do this with <s:url> but that way I need to create a link instead of form submit. Can someone please help me with a code sample how to do this? I know there's a way to do it with HTML or Struts1 but how to do it with Struts2? If there is a way to do this in struts.xml , please explain with an example. <form action="/example/xyz.action?user=george" method="POST"> try this: <s