how to permit an array with strong parameters

This https://github.com/rails/strong_parameters seems like the relevant section of the docs: The permitted scalar types are String, Symbol, NilClass, Numeric, TrueClass, FalseClass, Date, Time, DateTime, StringIO, IO, ActionDispatch::Http::UploadedFile and Rack::Test::UploadedFile. To declare that the value in params must be an array of permitted scalar values map the key to an empty array: params.permit(:id => []) In … Read more

Difference between List and Array types in Kotlin

Arrays and lists (represented by List<T> and its subtype MutableList<T>) have many differences, here are the most significant ones: Array<T> is a class with known implementation: it’s a sequential fixed-size memory region storing the items (and on JVM it is represented by Java array). List<T> and MutableList<T> are interfaces which have different implementations: ArrayList<T>, LinkedList<T> … Read more

Print array elements on separate lines in Bash?

Try doing this : $ printf ‘%s\n’ “${my_array[@]}” The difference between $@ and $*: Unquoted, the results are unspecified. In Bash, both expand to separate args and then wordsplit and globbed. Quoted, “$@” expands each element as a separate argument, while “$*” expands to the args merged into one argument: “$1c$2c…” (where c is the … Read more

Access first level keys with array_map() without calling `array_keys()`

Not with array_map, as it doesn’t handle keys. array_walk does: $test_array = array(“first_key” => “first_value”, “second_key” => “second_value”); array_walk($test_array, function(&$a, $b) { $a = “$b loves $a”; }); var_dump($test_array); // array(2) { // [“first_key”]=> // string(27) “first_key loves first_value” // [“second_key”]=> // string(29) “second_key loves second_value” // } It does change the array given as … Read more

How do you extract a column from a multi-dimensional array?

>>> import numpy as np >>> A = np.array([[1,2,3,4],[5,6,7,8]]) >>> A array([[1, 2, 3, 4], [5, 6, 7, 8]]) >>> A[:,2] # returns the third columm array([3, 7]) See also: “numpy.arange” and “reshape” to allocate memory Example: (Allocating a array with shaping of matrix (3×4)) nrows = 3 ncols = 4 my_array = numpy.arange(nrows*ncols, dtype=”double”) … Read more

React proptype array with shape

You can use React.PropTypes.shape() as an argument to React.PropTypes.arrayOf(): // an array of a particular shape. ReactComponent.propTypes = { arrayWithShape: React.PropTypes.arrayOf(React.PropTypes.shape({ color: React.PropTypes.string.isRequired, fontSize: React.PropTypes.number.isRequired, })).isRequired, } See the Prop Validation section of the documentation. UPDATE As of react v15.5, using React.PropTypes is deprecated and the standalone package prop-types should be used instead : // … Read more

How to remove an element from an array in Swift

The let keyword is for declaring constants that can’t be changed. If you want to modify a variable you should use var instead, e.g: var animals = [“cats”, “dogs”, “chimps”, “moose”] animals.remove(at: 2) //[“cats”, “dogs”, “moose”] A non-mutating alternative that will keep the original collection unchanged is to use filter to create a new collection … Read more